slotcount.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package rezekislot
  2. import (
  3. "math/rand"
  4. "bet24.com/log"
  5. )
  6. type SlotCount struct {
  7. SlotID int
  8. Count int
  9. }
  10. type SlotColumn struct {
  11. SlotCounts []SlotCount
  12. pool []int
  13. }
  14. func (sc *SlotColumn) makePool() {
  15. sc.pool = []int{}
  16. for _, v := range sc.SlotCounts {
  17. for i := 0; i < v.Count; i++ {
  18. sc.pool = append(sc.pool, v.SlotID)
  19. }
  20. }
  21. }
  22. func (sc *SlotColumn) getSlot() int {
  23. return sc.pool[rand.Intn(len(sc.pool))]
  24. }
  25. type SlotLevel struct {
  26. Columns []SlotColumn
  27. }
  28. type SlotCountManager struct {
  29. levels []SlotLevel
  30. WinAmount int
  31. }
  32. func newSlotCountManager(counts [][][]int) *SlotCountManager {
  33. ret := new(SlotCountManager)
  34. ret.loadDataByConfig(counts)
  35. return ret
  36. }
  37. func newSlotCountManagerByConfig(winAmount int, counts [][][]int) *SlotCountManager {
  38. log.Color(LogColor, "newSlotCountManagerByConfig")
  39. ret := new(SlotCountManager)
  40. ret.WinAmount = winAmount
  41. ret.loadDataByConfig(counts)
  42. return ret
  43. }
  44. func (scm *SlotCountManager) loadDataByConfig(counts [][][]int) {
  45. for _, level := range counts {
  46. // level
  47. var sl SlotLevel
  48. for _, column := range level {
  49. var sc SlotColumn
  50. for i := 0; i < len(column); i++ {
  51. if column[i] == 0 {
  52. continue
  53. }
  54. sc.SlotCounts = append(sc.SlotCounts, SlotCount{SlotID: i, Count: column[i]})
  55. }
  56. sc.makePool()
  57. sl.Columns = append(sl.Columns, sc)
  58. }
  59. scm.levels = append(scm.levels, sl)
  60. }
  61. }
  62. /*
  63. 获取16个格子数据,最后一个为特殊区域
  64. */
  65. func (scm *SlotCountManager) get16Slots(betLevel int, isFree bool, freeSlotId int) []int {
  66. ret := make([]int, RESULT_COUNT)
  67. isHaveFree := make([]bool, COLUMN_COUNT)
  68. if betLevel >= len(scm.levels) {
  69. betLevel = len(scm.levels) - 1
  70. }
  71. level := scm.levels[betLevel]
  72. for r := 0; r < ROW_COUNT; r++ {
  73. for c := 0; c < COLUMN_COUNT; c++ {
  74. row := (r*COLUMN_COUNT + c) % 5
  75. id := scm.getSlotIdByLevel(&level.Columns[c], isFree, isHaveFree[row], freeSlotId)
  76. if !isHaveFree[row] && id == freeSlotId {
  77. isHaveFree[row] = true
  78. }
  79. ret[r*COLUMN_COUNT+c] = id
  80. }
  81. }
  82. //特殊区域
  83. ret[RESULT_COUNT-1] = scm.getSlotIdByLevel(&level.Columns[5], isFree, isHaveFree[2], freeSlotId)
  84. return ret
  85. }
  86. /*
  87. 获取扇子ID
  88. */
  89. func (scm *SlotCountManager) getFanID(magicSlotId, topSlotId, betLevel int, isFree bool) int {
  90. //判断顶格是否为扇子 因为只有扇子为通用素材所以判断是否为Magic即可
  91. if magicSlotId != topSlotId && !isFree {
  92. return -1
  93. }
  94. if betLevel >= len(scm.levels) {
  95. betLevel = len(scm.levels) - 1
  96. }
  97. level := scm.levels[betLevel]
  98. ret := level.Columns[6].getSlot()
  99. return ret
  100. }
  101. /*
  102. 根据等级配置获取单个素材ID
  103. */
  104. func (scm *SlotCountManager) getSlotIdByLevel(sc *SlotColumn, isFree, isHaveFreeRow bool, freeSlotId int) int {
  105. slotId := -1
  106. for {
  107. slotId = sc.getSlot()
  108. //每列最多出现一个免费素材
  109. if !isFree && isHaveFreeRow && slotId == freeSlotId {
  110. continue
  111. } else {
  112. break
  113. }
  114. }
  115. return slotId
  116. }