setsmatchconfig.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package setsmatch
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/matches/handler/matchbase"
  5. )
  6. type set_config struct {
  7. SetIndex int // 局数
  8. EliminateScore int // 淘汰分
  9. BaseScore int // 低分
  10. }
  11. type matchconfig struct {
  12. GameId int
  13. GameName string
  14. UserOptions []matchbase.UserOption
  15. GameRules []matchbase.MatchRule // 从privateroom取
  16. InitialScore int // 初始分数
  17. SetConfigs []set_config
  18. }
  19. func (mc *matchconfig) isEliminated(setCount int, score int) bool {
  20. for i := 0; i < len(mc.SetConfigs); i++ {
  21. if setCount == mc.SetConfigs[i].SetIndex {
  22. return score < mc.SetConfigs[i].EliminateScore
  23. }
  24. }
  25. return false
  26. }
  27. func (mc *matchconfig) getBaseScore(setCount int) int {
  28. count := len(mc.SetConfigs)
  29. if count == 0 {
  30. return 0
  31. }
  32. for i := 0; i < len(mc.SetConfigs); i++ {
  33. if setCount == mc.SetConfigs[i].SetIndex {
  34. return mc.SetConfigs[i].BaseScore
  35. }
  36. }
  37. // 没找到,取最后一个
  38. return mc.SetConfigs[count-1].BaseScore
  39. }
  40. func (mc *matchconfig) addGameRule(gameRule string, ruleDesc string, targetOptions []int, userOptions []int, playTimeOptions []int) {
  41. //log.Release("matchconfig addGameRule gameRule = %s,ruleDesc = %s", gameRule, ruleDesc)
  42. for i := 0; i < len(mc.GameRules); i++ {
  43. if mc.GameRules[i].Name == gameRule {
  44. mc.GameRules[i].Desc = ruleDesc
  45. mc.GameRules[i].UserOptions = userOptions
  46. mc.GameRules[i].PlayTimeOptions = playTimeOptions
  47. return
  48. }
  49. }
  50. mc.GameRules = append(mc.GameRules, matchbase.MatchRule{Name: gameRule, Desc: ruleDesc, TargetOptions: targetOptions, UserOptions: userOptions, PlayTimeOptions: playTimeOptions})
  51. }
  52. func (mc *matchconfig) dump() {
  53. log.Release(" GameId:%d GameName:%s,UserOptions[%v]", mc.GameId, mc.GameName, mc.UserOptions)
  54. log.Release(" %v", mc.SetConfigs)
  55. }
  56. func (mc *matchconfig) isValidParams(gameRule string, totalUserCount, tableUserCount, playTime int) bool {
  57. var mr *matchbase.MatchRule
  58. for i := 0; i < len(mc.GameRules); i++ {
  59. if mc.GameRules[i].Name == gameRule {
  60. mr = &mc.GameRules[i]
  61. break
  62. }
  63. }
  64. if mr == nil {
  65. log.Release("setsmatch.matchconfig.isValidParams gamerRule[%s] not found", gameRule)
  66. return false
  67. }
  68. if !mc.isValueIn(tableUserCount, mr.UserOptions) {
  69. log.Release("matchconfig.isValidParams tableUserCount[%d] not of [%v]", tableUserCount, mr.UserOptions)
  70. return false
  71. }
  72. return true
  73. }
  74. func (mc *matchconfig) isValueIn(value int, values []int) bool {
  75. if len(values) == 0 {
  76. return true
  77. }
  78. for i := 0; i < len(values); i++ {
  79. if values[i] == value {
  80. return true
  81. }
  82. }
  83. return false
  84. }