pointmatchconfig.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package pointmatch
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/matches/handler/matchbase"
  5. )
  6. type matchconfig struct {
  7. GameId int
  8. GameName string
  9. UserOptions []matchbase.UserOption
  10. GameRules []matchbase.MatchRule // 从privateroom取
  11. // 比赛配置
  12. EliminateScores []int // 起始淘汰分数
  13. ShrinkSecs []int // 改变淘汰分数时间
  14. ShrinkScores []int // 改变淘汰分数delta
  15. WinnerCounts []int // 最终剩下多少人赢
  16. }
  17. func (mc *matchconfig) addGameRule(gameRule string, ruleDesc string, targetOptions []int, userOptions []int, playTimeOptions []int) {
  18. //log.Release("matchconfig addGameRule gameRule = %s,ruleDesc = %s", gameRule, ruleDesc)
  19. for i := 0; i < len(mc.GameRules); i++ {
  20. if mc.GameRules[i].Name == gameRule {
  21. mc.GameRules[i].Desc = ruleDesc
  22. mc.GameRules[i].UserOptions = userOptions
  23. mc.GameRules[i].PlayTimeOptions = playTimeOptions
  24. return
  25. }
  26. }
  27. mc.GameRules = append(mc.GameRules, matchbase.MatchRule{Name: gameRule, Desc: ruleDesc, TargetOptions: targetOptions, UserOptions: userOptions, PlayTimeOptions: playTimeOptions})
  28. }
  29. func (mc *matchconfig) dump() {
  30. log.Release(" GameId:%d GameName:%s,UserOptions[%v]", mc.GameId, mc.GameName, mc.UserOptions)
  31. log.Release(" EliminateScores:%v ShrinkSecs:%v,ShrinkScores:%v,WinnerCounts:%v", mc.EliminateScores, mc.ShrinkSecs, mc.ShrinkScores, mc.WinnerCounts)
  32. for _, v := range mc.GameRules {
  33. log.Release(" Rule[%s] UserOptions[%v],PlayTimeOptions[%v]", v.Name, v.UserOptions, v.PlayTimeOptions)
  34. }
  35. }
  36. func (mc *matchconfig) isValidParams(gameRule string, totalUserCount, tableUserCount, playTime int,
  37. eliminateScore, shrinkSec, shrinkScore, winnerCount int) bool {
  38. var mr *matchbase.MatchRule
  39. for i := 0; i < len(mc.GameRules); i++ {
  40. if mc.GameRules[i].Name == gameRule {
  41. mr = &mc.GameRules[i]
  42. break
  43. }
  44. }
  45. if mr == nil {
  46. log.Release("pointmatch.matchconfig.isValidParams gamerRule[%s] not found", gameRule)
  47. return false
  48. }
  49. if totalUserCount <= tableUserCount || totalUserCount <= winnerCount {
  50. log.Release("pointmatch.matchconfig.isValidParams totalUserCount invalid %d,%d,%d", totalUserCount, tableUserCount, winnerCount)
  51. return false
  52. }
  53. if !mc.isValueIn(tableUserCount, mr.UserOptions) {
  54. log.Release("matchconfig.isValidParams tableUserCount[%d] not of [%v]", tableUserCount, mr.UserOptions)
  55. return false
  56. }
  57. if !mc.isValueIn(eliminateScore, mc.EliminateScores) {
  58. log.Release("matchconfig.isValidParams eliminateScore[%d] not of [%v]", eliminateScore, mc.EliminateScores)
  59. return false
  60. }
  61. if !mc.isValueIn(shrinkSec, mc.ShrinkSecs) {
  62. log.Release("matchconfig.isValidParams shrinkSec[%d] not of [%v]", shrinkSec, mc.ShrinkSecs)
  63. return false
  64. }
  65. if !mc.isValueIn(shrinkScore, mc.ShrinkScores) {
  66. log.Release("matchconfig.isValidParams shrinkScore[%d] not of [%v]", shrinkScore, mc.ShrinkScores)
  67. return false
  68. }
  69. if !mc.isValueIn(winnerCount, mc.WinnerCounts) {
  70. log.Release("matchconfig.isValidParams winnerCount[%d] not of [%v]", winnerCount, mc.WinnerCounts)
  71. return false
  72. }
  73. // 人数限制,有上下限,暂不限制
  74. /*for i := 0; i < len(mr.UserOptions); i++ {
  75. if mc.UserOptions[i].TableUser == tableUserCount {
  76. if mc.isValueIn(totalUserCount, mc.UserOptions[i].TotalUser) {
  77. return true
  78. }
  79. }
  80. }
  81. */
  82. return true
  83. }
  84. func (mc *matchconfig) isValueIn(value int, values []int) bool {
  85. if len(values) == 0 {
  86. return true
  87. }
  88. for i := 0; i < len(values); i++ {
  89. if values[i] == value {
  90. return true
  91. }
  92. }
  93. return false
  94. }