WinShape.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package slotpanda
  2. import (
  3. "bet24.com/log"
  4. )
  5. func NewWinShape(shape int, desc string) *WinShape {
  6. ws := new(WinShape)
  7. ws.Shape = shape
  8. ws.Desc = desc
  9. if !ws.isValid() {
  10. return nil
  11. }
  12. return ws
  13. }
  14. type WinShape struct {
  15. Shape int
  16. Desc string
  17. }
  18. func (ws *WinShape) isValid() bool {
  19. shape := ws.Shape
  20. for i := 0; i < COLUMN_COUNT; i++ {
  21. if shape%10 >= ROW_COUNT {
  22. log.Release("WinShape.IsValid r%d = %d", i, shape%10)
  23. return false
  24. }
  25. shape = shape / 10
  26. }
  27. return true
  28. }
  29. func (ws *WinShape) getFive(slots []Slot) []Slot {
  30. ret := make([]Slot, COLUMN_COUNT)
  31. shape := ws.Shape
  32. for i := 1; i <= COLUMN_COUNT; i++ {
  33. var row = shape % 10
  34. ret[COLUMN_COUNT-i] = slots[(row+1)*COLUMN_COUNT-i]
  35. shape = shape / 10
  36. }
  37. return ret
  38. }
  39. func (ws *WinShape) getCount(slots []Slot) (slotID, slotCount, magicCount int) {
  40. if len(slots) != RESULT_COUNT {
  41. log.Release("WinShape.isWin count = %d", len(slots))
  42. return 0, 0, 0
  43. }
  44. five_slot := ws.getFive(slots)
  45. slotID, slotCount, magicCount = ws.getShapeCount(five_slot)
  46. return
  47. }
  48. func (ws *WinShape) getShapeCount(slots []Slot) (slotID, slotCount, magicCount int) {
  49. slotID = 0xFFFFFFFF
  50. slotCount = 0
  51. magicCount = 0
  52. magicSlotID := 0xFFFFFFFF
  53. for _, v := range slots {
  54. if v.isMagic() {
  55. slotCount++
  56. magicSlotID = v.SlotID
  57. magicCount++
  58. continue
  59. }
  60. if slotID != v.SlotID && slotID != 0xFFFFFFFF {
  61. break
  62. }
  63. slotCount++
  64. slotID = v.SlotID
  65. }
  66. if slotID == 0xFFFFFFFF {
  67. slotID = magicSlotID
  68. }
  69. return
  70. }