WinShape.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package wildapeslot
  2. import (
  3. "encoding/json"
  4. "os"
  5. "bet24.com/log"
  6. )
  7. func NewWinShape(shape int, desc string) *WinShape {
  8. ws := new(WinShape)
  9. ws.Shape = shape
  10. ws.Desc = desc
  11. if !ws.isValid() {
  12. return nil
  13. }
  14. return ws
  15. }
  16. type ShapeConfig struct {
  17. WinShape1 []WinShape
  18. WinShape2 []WinShape
  19. }
  20. func (sc *ShapeConfig) loadConfig() {
  21. data, err := os.ReadFile("slotconf/wildapeslot_shape.json")
  22. if err != nil {
  23. log.Error("SlotManager.loadData read wildapeslot_shape.json failed")
  24. }
  25. err = json.Unmarshal(data, &sc)
  26. if err != nil {
  27. log.Error("SlotManager.loadData Unmarshal wildapeslot_shape.json failed err:%v", err)
  28. return
  29. }
  30. log.Debug("shapeConfig %v", sc)
  31. }
  32. type WinShape struct {
  33. Shape int
  34. Desc string
  35. }
  36. func (ws *WinShape) isValid() bool {
  37. shape := ws.Shape
  38. for i := 0; i < COLUMN_COUNT; i++ {
  39. if shape%10 >= ROW_COUNT {
  40. log.Release("WinShape.IsValid r%d = %d", i, shape%10)
  41. return false
  42. }
  43. shape = shape / 10
  44. }
  45. return true
  46. }
  47. //从路线个位数开始取5个id
  48. func (ws *WinShape) getFive(slots []int) []int {
  49. ret := make([]int, COLUMN_COUNT)
  50. shape := ws.Shape
  51. for i := 1; i <= COLUMN_COUNT; i++ {
  52. var row = shape % 10
  53. ret[COLUMN_COUNT-i] = slots[(row+1)*COLUMN_COUNT-i]
  54. shape = shape / 10
  55. }
  56. return ret
  57. }
  58. func (ws *WinShape) getCount(slots []int) (slotID, slotCount, magicCount int) {
  59. slotlen := len(slots)
  60. if slotlen != RESULT_COUNT && slotlen != FREE_RESULT_COUNT {
  61. log.Release("WinShape.isWin count = %d", len(slots))
  62. return 0, 0, 0
  63. }
  64. five_slot := ws.getFive(slots)
  65. slotID, slotCount, magicCount = ws.getShapeCount(five_slot)
  66. log.Debug("shape %d", ws.Shape)
  67. log.Debug("getCount %v, id=%d,slotCount=%d", five_slot, slotID, slotCount)
  68. return
  69. }
  70. func (ws *WinShape) getShapeCount(slots []int) (slotID, slotCount, magicCount int) {
  71. slotID = 0xFFFFFFFF
  72. slotCount = 0
  73. magicCount = 0
  74. magicSlotID := 0xFFFFFFFF
  75. for _, v := range slots {
  76. if v == MAGIC_ID {
  77. slotCount++
  78. magicSlotID = v
  79. magicCount++
  80. continue
  81. }
  82. if slotID != v && slotID != 0xFFFFFFFF {
  83. break
  84. }
  85. slotCount++
  86. slotID = v
  87. }
  88. if slotID == 0xFFFFFFFF {
  89. slotID = magicSlotID
  90. }
  91. return
  92. }