matchconfig.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package simplematch
  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. Round_timeoff int64 // 每轮中间的延迟秒数
  12. TeamGame bool // 是否一直同队伍撮合
  13. BaseScore int
  14. //EleminateByScore bool // 是否根据分数淘汰
  15. }
  16. func (mc *matchconfig) getRoundTimeOff() int64 {
  17. return mc.Round_timeoff
  18. }
  19. func (mc *matchconfig) addGameRule(gameRule string, ruleDesc string, targetOptions []int, userOptions []int, playTimeOptions []int) {
  20. //log.Release("matchconfig addGameRule gameRule = %s,ruleDesc = %s", gameRule, ruleDesc)
  21. for i := 0; i < len(mc.GameRules); i++ {
  22. if mc.GameRules[i].Name == gameRule {
  23. mc.GameRules[i].Desc = ruleDesc
  24. mc.GameRules[i].TargetOptions = targetOptions
  25. mc.GameRules[i].UserOptions = userOptions
  26. mc.GameRules[i].PlayTimeOptions = playTimeOptions
  27. return
  28. }
  29. }
  30. mc.GameRules = append(mc.GameRules, matchbase.MatchRule{Name: gameRule, Desc: ruleDesc, TargetOptions: targetOptions, UserOptions: userOptions, PlayTimeOptions: playTimeOptions})
  31. }
  32. func (mc *matchconfig) dump() {
  33. log.Release(" GameId:%d GameName:%s,UserOptions[%v] Round_timeoff[%d]", mc.GameId, mc.GameName, mc.UserOptions, mc.Round_timeoff)
  34. for _, v := range mc.GameRules {
  35. log.Release(" Rule[%s] TargetOptions[%v] UserOptions[%v],PlayTimeOptions[%v]", v.Name, v.TargetOptions, v.UserOptions, v.PlayTimeOptions)
  36. }
  37. }
  38. func (mc *matchconfig) isValidParams(gameRule string, totalUserCount, tableUserCount, target, playTime int) bool {
  39. var mr *matchbase.MatchRule
  40. for i := 0; i < len(mc.GameRules); i++ {
  41. if mc.GameRules[i].Name == gameRule {
  42. mr = &mc.GameRules[i]
  43. break
  44. }
  45. }
  46. if mr == nil {
  47. log.Release("simplematch.matchconfig.isValidParams gamerRule[%s] not found", gameRule)
  48. return false
  49. }
  50. if !mc.isValueIn(tableUserCount, mr.UserOptions) {
  51. log.Release("simplematch.matchconfig.isValidParams tableUserCount[%d] not of [%v]", tableUserCount, mr.UserOptions)
  52. return false
  53. }
  54. if target > 0 && !mc.isValueIn(target, mr.TargetOptions) {
  55. log.Release("simplematch.matchconfig.isValidParams target[%d] not of [%v]", target, mr.TargetOptions)
  56. return false
  57. }
  58. // 人数限制
  59. for i := 0; i < len(mr.UserOptions); i++ {
  60. if mc.UserOptions[i].TableUser == tableUserCount {
  61. if mc.isValueIn(totalUserCount, mc.UserOptions[i].TotalUser) {
  62. return true
  63. }
  64. }
  65. }
  66. log.Release("simplematch.matchconfig.isValidParams TotalUser.TableUser not in config [%d.%d]", totalUserCount, tableUserCount)
  67. log.Release("rule:%v", *mr)
  68. return false
  69. }
  70. func (mc *matchconfig) isValueIn(value int, values []int) bool {
  71. if len(values) == 0 {
  72. return true
  73. }
  74. for i := 0; i < len(values); i++ {
  75. if values[i] == value {
  76. return true
  77. }
  78. }
  79. return false
  80. }