-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
133 lines (120 loc) · 2.48 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package niuniu
import (
"math/rand"
"time"
"fmt"
)
func getCountByValue(value int) int {
if value > 10 {
return 10
}
return value
}
func Shuffle(vals []CardInfo) []CardInfo {
r := rand.New(rand.NewSource(time.Now().Unix()))
for i := 0; i < len(vals); i++ {
n := len(vals)
randIndex := r.Intn(n - i)
vals[n-1-i], vals[randIndex] = vals[randIndex], vals[n-1-i]
}
return vals
}
func Trans(color, value int) string {
return fmt.Sprintf("%s %s", TransColor[color], TransValue[value])
}
func CompareCards(a, b CardInfo) bool {
if a.CardValue > b.CardValue {
return true
}
if a.CardValue < b.CardValue {
return false
}
return a.CardColor > b.CardColor
}
func IsSmallNiu(cards []CardInfo) bool {
sum := 0
for _, item := range cards {
sum += item.CardCount
}
if sum <= 10 {
return true
}
return false
}
func IsBomb(cards []CardInfo) bool {
if cards[0].CardCount == cards[3].CardCount {
return true
} else if cards[1].CardCount == cards[4].CardCount {
return true
}
return false
}
func IsGoldNiu(cards []CardInfo) bool {
return cards[1].CardValue > 10
}
func IsSilverNiu(cards []CardInfo) bool {
return cards[1].CardValue > 10 && cards[0].CardValue == 10
}
func GetNiu(cards []CardInfo) int {
lave := 0
for i := 0; i < len(cards); i++ {
lave = lave + cards[i].CardValue
}
lave = lave % 10
for i := 0; i < len(cards)-1; i++ {
for j := i + 1; j < len(cards); j++ {
if ((cards[i].CardCount+cards[j].CardCount)%10 == lave) {
if lave == 0 {
return 10
}
return lave
}
}
}
return 0
}
func GetNiuType(cards []CardInfo) int {
cards = SortCards(cards)
if IsSmallNiu(cards) {
return SmallNiu
}
if IsBomb(cards) {
return Bomb
}
if IsGoldNiu(cards) {
return GoldNiu
}
if IsSilverNiu(cards) {
return SilverNiu
}
return GetNiu(cards)
}
func SortCards(cards []CardInfo) []CardInfo {
length := len(cards)
for i := 0; i < length; i++ {
for j := i + 1; j < length; j++ {
temp := cards[i]
if cards[i].CardCount > cards[j].CardCount {
cards[i] = cards[j]
cards[j] = temp
}
}
}
return cards
}
func BankerIsWin(bankerCards, otherCards []CardInfo) bool {
bankerType := GetNiuType(bankerCards)
otherType := GetNiuType(bankerCards)
if bankerType != otherType {
return bankerType > otherType
}
switch bankerType {
case SmallNiu:
return true
case Bomb:
return bankerCards[2].CardValue > otherCards[2].CardValue
case GoldNiu, SilverNiu, NiuNiu, NotNiu:
return CompareCards(bankerCards[4], otherCards[4])
}
return true
}