nn.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package qznn
  2. import "github.com/sirupsen/logrus"
  3. func WinLevel(leftNum, rightNum []uint32) (bool, bool, int) {
  4. //优先处理,下面会覆盖掉花色
  5. maxLeft, suitLeft := FindMaxCardInList(leftNum)
  6. maxRight, suitRight := FindMaxCardInList(rightNum)
  7. leftNum = TransCardNum(leftNum)
  8. rightNum = TransCardNum(rightNum)
  9. pointLeft := GetNiuniuPoint(leftNum)
  10. pointRight := GetNiuniuPoint(rightNum)
  11. isWuhuaLeft := IsWuhuaWuXiaoSiZha(leftNum)
  12. isWuhuaRight := IsWuhuaWuXiaoSiZha(rightNum)
  13. logrus.Infof("left is wx:%v, right is wx:%v", isWuhuaLeft, isWuhuaRight)
  14. logrus.Infof("%v:%d", leftNum, pointLeft)
  15. logrus.Infof("%v:%d", rightNum, pointRight)
  16. if isWuhuaLeft && !isWuhuaRight {
  17. return true, false, 3
  18. }
  19. if !isWuhuaLeft && isWuhuaRight {
  20. return false, false, 0
  21. }
  22. if isWuhuaLeft && isWuhuaRight {
  23. //五花<四炸<五小
  24. if IsWuhuaNiu(leftNum) && !IsWuhuaNiu(rightNum) {
  25. return true, false, 4
  26. }
  27. if IsSiZha(leftNum) && IsWuhuaNiu(rightNum) {
  28. return false, false, 0
  29. }
  30. if IsSiZha(leftNum) && IsWuXiaoNiu(rightNum) {
  31. return true, false, 4
  32. }
  33. if IsWuXiaoNiu(leftNum) && !IsWuXiaoNiu(rightNum) {
  34. return false, false, 0
  35. }
  36. //相同的情况,比花色
  37. if maxLeft > maxRight {
  38. return true, false, 4
  39. }
  40. if maxLeft == maxRight {
  41. if suitLeft > suitRight {
  42. return true, false, 4
  43. }
  44. if suitLeft == suitRight {
  45. return false, true, 0
  46. }
  47. if suitLeft < suitRight {
  48. return false, false, 0
  49. }
  50. }
  51. if maxLeft < maxRight {
  52. return false, false, 0
  53. }
  54. }
  55. isLeftWin := false
  56. if pointLeft > pointRight {
  57. isLeftWin = true
  58. }
  59. if pointLeft == pointRight {
  60. if maxLeft > maxRight {
  61. isLeftWin = true
  62. }
  63. if maxLeft == maxRight {
  64. if suitLeft > suitRight {
  65. isLeftWin = true
  66. }
  67. //和的情况
  68. if suitLeft == suitRight {
  69. return false, true, 0
  70. }
  71. }
  72. }
  73. if isLeftWin {
  74. if pointLeft == 7 || pointLeft == 8 || pointLeft == 9 {
  75. return true, false, 2
  76. }
  77. if pointLeft == 10 {
  78. return true, false, 3
  79. }
  80. return true, false, 1
  81. }
  82. return false, false, 0
  83. }
  84. func IsWuhuaNiu(numList []uint32) bool {
  85. for _, item := range numList {
  86. if item <= 10 {
  87. return false
  88. }
  89. }
  90. return true
  91. }
  92. func IsWuXiaoNiu(numList []uint32) bool {
  93. total := 0
  94. for _, item := range numList {
  95. if item >= 5 {
  96. return false
  97. }
  98. total += int(item)
  99. }
  100. return total < 10
  101. }
  102. func IsSiZha(numList []uint32) bool {
  103. numMap := map[uint32]int{}
  104. for _, item := range numList {
  105. // if item >= 5 {
  106. // return false
  107. // }
  108. numMap[item] = numMap[item] + 1
  109. }
  110. if len(numMap) == 1 {
  111. return true
  112. }
  113. for _, item := range numMap {
  114. if item >= 4 {
  115. return true
  116. }
  117. }
  118. // if numMap[0] == 4 || numMap[1] == 4 {
  119. // return true
  120. // }
  121. return false
  122. }
  123. func IsWuhuaWuXiaoSiZha(numList []uint32) bool {
  124. if IsWuhuaNiu(numList) {
  125. return true
  126. }
  127. if IsWuXiaoNiu(numList) {
  128. return true
  129. }
  130. if IsSiZha(numList) {
  131. return true
  132. }
  133. return false
  134. }
  135. func IsWuhuaWuXiaoSiZhaDesc(numList []uint32) (bool, string) {
  136. if IsWuhuaNiu(numList) {
  137. return true, "五花牛"
  138. }
  139. if IsWuXiaoNiu(numList) {
  140. return true, "五小牛"
  141. }
  142. if IsSiZha(numList) {
  143. return true, "四炸"
  144. }
  145. return false, ""
  146. }
  147. func TransCardNum(openNumberList []uint32) []uint32 {
  148. resultList := make([]uint32, len(openNumberList))
  149. for index, item := range openNumberList {
  150. val := item % 13
  151. if val == 0 {
  152. val = 13
  153. }
  154. resultList[index] = val
  155. }
  156. return resultList
  157. }
  158. func FindMaxCardInList(cardList []uint32) (num uint32, suit uint32) {
  159. num = 0
  160. suit = 0
  161. for _, item := range cardList {
  162. formatItem := item % 13
  163. if formatItem == 0 {
  164. formatItem = 13
  165. }
  166. if num == formatItem {
  167. newSuit := (item - 1) / 13
  168. if newSuit > suit {
  169. suit = newSuit
  170. }
  171. }
  172. if num < formatItem {
  173. num = formatItem
  174. suit = (item - 1) / 13
  175. }
  176. }
  177. return num, suit
  178. }
  179. func GetNiuniuPoint(numList []uint32) int {
  180. numList = TransCardNum(numList)
  181. for i := 0; i < len(numList); i++ {
  182. if numList[i] > 10 {
  183. numList[i] = 10
  184. }
  185. }
  186. for i := 0; i < 3; i++ {
  187. for j := i + 1; j < 4; j++ {
  188. for k := j + 1; k < 5; k++ {
  189. num1 := numList[i]
  190. num2 := numList[j]
  191. num3 := numList[k]
  192. if (num1+num2+num3)%10 != 0 {
  193. continue
  194. }
  195. pointTotal := uint32(0)
  196. for f := 0; f < 5; f++ {
  197. if f != i && f != j && f != k {
  198. pointTotal += numList[f]
  199. }
  200. }
  201. if pointTotal%10 == 0 {
  202. return 10
  203. }
  204. return int(pointTotal % 10)
  205. }
  206. }
  207. }
  208. return 0
  209. }