slotcount.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package slotcount
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "os"
  7. "bet24.com/log"
  8. )
  9. type SlotCount struct {
  10. SlotID int
  11. Count int
  12. }
  13. type SlotColumn struct {
  14. SlotCounts []SlotCount
  15. pool []int
  16. }
  17. func (scm *SlotColumn) makePool() {
  18. scm.pool = []int{}
  19. for _, v := range scm.SlotCounts {
  20. for i := 0; i < v.Count; i++ {
  21. scm.pool = append(scm.pool, v.SlotID)
  22. }
  23. }
  24. }
  25. func (scm *SlotColumn) getSlot() int {
  26. return scm.pool[rand.Intn(len(scm.pool))]
  27. }
  28. type SlotLevel struct {
  29. Columns []SlotColumn
  30. }
  31. type SlotCountManager struct {
  32. levels []SlotLevel
  33. Level int
  34. // fafafa特殊
  35. goldFaId int
  36. freeSlotId int
  37. }
  38. func NewSlotCountManager(confFile string) *SlotCountManager {
  39. ret := new(SlotCountManager)
  40. ret.loadData(confFile)
  41. return ret
  42. }
  43. func NewSlotCountManagerByConfig(level int, counts [][][]int) *SlotCountManager {
  44. ret := new(SlotCountManager)
  45. ret.Level = level
  46. ret.loadDataByConfig(counts)
  47. return ret
  48. }
  49. func (scm *SlotCountManager) loadDataByConfig(counts [][][]int) {
  50. for _, level := range counts {
  51. // level
  52. var sl SlotLevel
  53. for _, column := range level {
  54. var scm SlotColumn
  55. for i := 0; i < len(column); i++ {
  56. if column[i] == 0 {
  57. continue
  58. }
  59. scm.SlotCounts = append(scm.SlotCounts, SlotCount{SlotID: i, Count: column[i]})
  60. }
  61. scm.makePool()
  62. sl.Columns = append(sl.Columns, scm)
  63. }
  64. scm.levels = append(scm.levels, sl)
  65. }
  66. }
  67. func (scm *SlotCountManager) loadData(confFile string) {
  68. var counts [][][]int
  69. data, err := os.ReadFile(fmt.Sprintf("slotconf/%s.json", confFile))
  70. if err != nil {
  71. log.Error("SlotCountManager.loadData read %s.json failed", confFile)
  72. return
  73. }
  74. err = json.Unmarshal(data, &counts)
  75. if err != nil {
  76. log.Error("SlotCountManager.loadData Unmarshal %s.json failed err:%v", confFile, err)
  77. return
  78. }
  79. scm.loadDataByConfig(counts)
  80. }
  81. const (
  82. ROW_COUNT = 3
  83. COLUMN_COUNT = 5
  84. )
  85. func (scm *SlotCountManager) Get15Slots(betLevel int) []int {
  86. if len(scm.levels) == 0 {
  87. return []int{}
  88. }
  89. ret := make([]int, ROW_COUNT*COLUMN_COUNT)
  90. // dfdc根据下注额确定配置项,其他slot没有
  91. if betLevel >= len(scm.levels) {
  92. betLevel = len(scm.levels) - 1
  93. }
  94. level := scm.levels[betLevel]
  95. for r := 0; r < ROW_COUNT; r++ {
  96. for c := 0; c < COLUMN_COUNT; c++ {
  97. // dfdc只有5列的配置,其他slot是15列配置
  98. idx := (r*COLUMN_COUNT + c) % len(level.Columns)
  99. ret[r*COLUMN_COUNT+c] = level.Columns[idx].getSlot()
  100. }
  101. }
  102. return ret
  103. }
  104. func (scm *SlotCountManager) GetOneSlot(betLevel int, idx int) int {
  105. if len(scm.levels) == 0 {
  106. return -1
  107. }
  108. if betLevel >= len(scm.levels) {
  109. betLevel = len(scm.levels) - 1
  110. }
  111. level := scm.levels[betLevel]
  112. idx = idx % len(level.Columns)
  113. return level.Columns[idx].getSlot()
  114. }
  115. func (scm *SlotCountManager) setFafafaInfo(goldFaId int, freeSlotId int) {
  116. scm.goldFaId = goldFaId
  117. scm.freeSlotId = freeSlotId
  118. }
  119. func (scm *SlotCountManager) GetFafafaSlots(isFree bool) []int {
  120. ret := make([]int, 15)
  121. goldFaCount := 0
  122. for i := 0; i < 15; i++ {
  123. for {
  124. ret[i] = scm.GetOneSlot(0, i)
  125. if !isFree || (ret[i] != scm.freeSlotId && ret[i] != scm.goldFaId) {
  126. break
  127. }
  128. }
  129. if ret[i] == scm.goldFaId {
  130. goldFaCount++
  131. }
  132. }
  133. // 如果有两个以上
  134. if goldFaCount >= 2 {
  135. for i := 0; i < 5; i++ {
  136. if ret[i] == scm.goldFaId {
  137. // 每列都改成发
  138. ret[i+5] = scm.goldFaId
  139. ret[i+10] = scm.goldFaId
  140. }
  141. }
  142. } else if isFree {
  143. // 随机一列发
  144. faLineCount := 1
  145. if rand.Intn(100) >= 99 {
  146. faLineCount = 4
  147. } else if rand.Intn(100) >= 92 {
  148. faLineCount = 3
  149. } else if rand.Intn(100) >= 72 {
  150. faLineCount = 2
  151. }
  152. changeLines := make([]int, faLineCount)
  153. lines5 := []int{0, 1, 2, 3, 4}
  154. for i := 4; i > 1; i-- {
  155. place := rand.Intn(i)
  156. tmp := lines5[place]
  157. lines5[place] = lines5[i]
  158. lines5[i] = tmp
  159. }
  160. for i := 0; i < faLineCount; i++ {
  161. changeLines[i] = lines5[i]
  162. }
  163. for _, line := range changeLines {
  164. ret[line] = scm.goldFaId
  165. ret[line+5] = scm.goldFaId
  166. ret[line+10] = scm.goldFaId
  167. }
  168. }
  169. return ret
  170. }
  171. func (scm *SlotCountManager) Get16Slots(betLevel int, isFree bool, freeSlotId int) []int {
  172. const RESULT_COUNT = 16
  173. ret := make([]int, RESULT_COUNT)
  174. isHaveFree := make([]bool, COLUMN_COUNT)
  175. if betLevel >= len(scm.levels) {
  176. betLevel = len(scm.levels) - 1
  177. }
  178. level := scm.levels[betLevel]
  179. for r := 0; r < ROW_COUNT; r++ {
  180. for c := 0; c < COLUMN_COUNT; c++ {
  181. row := (r*COLUMN_COUNT + c) % 5
  182. id := scm.getSlotIdByLevel(&level.Columns[c], isFree, isHaveFree[row], freeSlotId)
  183. if !isHaveFree[row] && id == freeSlotId {
  184. isHaveFree[row] = true
  185. }
  186. ret[r*COLUMN_COUNT+c] = id
  187. }
  188. }
  189. //特殊区域
  190. ret[RESULT_COUNT-1] = scm.getSlotIdByLevel(&level.Columns[5], isFree, isHaveFree[2], freeSlotId)
  191. return ret
  192. }
  193. /*
  194. 获取扇子ID
  195. */
  196. func (scm *SlotCountManager) GetFanID(magicSlotId, topSlotId, betLevel int, isFree bool) int {
  197. //判断顶格是否为扇子 因为只有扇子为通用素材所以判断是否为Magic即可
  198. if magicSlotId != topSlotId && !isFree {
  199. return -1
  200. }
  201. if betLevel >= len(scm.levels) {
  202. betLevel = len(scm.levels) - 1
  203. }
  204. level := scm.levels[betLevel]
  205. ret := level.Columns[6].getSlot()
  206. return ret
  207. }
  208. /*
  209. 根据等级配置获取单个素材ID
  210. */
  211. func (scm *SlotCountManager) getSlotIdByLevel(sc *SlotColumn, isFree, isHaveFreeRow bool, freeSlotId int) int {
  212. slotId := -1
  213. for {
  214. slotId = sc.getSlot()
  215. //每列最多出现一个免费素材
  216. if !isFree && isHaveFreeRow && slotId == freeSlotId {
  217. continue
  218. } else {
  219. break
  220. }
  221. }
  222. return slotId
  223. }