-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
161 lines (113 loc) · 2.4 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"fmt"
"math/rand"
//"golang.org/x/text/unicode/rangetable"
)
//complex logic
// A - very rare
// B - rare
// C - least rare
// D - normal
func generateSymbolsArray(symbols map[string]uint) []string{
symbolsArr := []string{}
for symbols, count := range symbols {
for i := uint(0); i < (count); i++{
symbolsArr = append(symbolsArr, symbols)
}
}
return symbolsArr
}
//generate a randon number
func getRandonNumber(min int, max int) int {
randonNumber := rand.Intn(max - min + 1) + min
return randonNumber
}
func getSpin(reel []string, rows int, cols int) [][]string {
result := [][]string{}
for i := 0; i < rows; i++{
result = append(result, []string{})
}
for col := 0; col < cols; col++{
selected := map[int]bool{}
for row := 0; row < rows; row++{
for true {
randonIndex := getRandonNumber(0, len(reel)-1)
_, exist := selected[randonIndex]
if !exist{
selected[randonIndex] = true
result[row] = append(result[row], reel[randonIndex])
break
}
}
}
}
return result
}
func printSpin(spin [][]string){
for _, row := range spin{
for j, symbol := range row {
fmt.Printf(symbol)
if j != len(row) - 1{
fmt.Printf(" | ")
}
}
fmt.Println()
}
}
func checkWin(spin [][]string, multipliers map[string]uint) []uint {
lines := []uint{}
for _, row := range spin{
win := true
checkSymbol := row[0]
for _, symbol := range row[1:]{
if checkSymbol != symbol {
win = false
break
}
}
if win {
lines = append(lines, multipliers[checkSymbol])
}else {
lines = append(lines, 0)
}
}
return lines
}
func main(){
symbols := map[string]uint{
"A" : 2,
"B" : 10,
"C" : 16,
"D" : 31,
}
// what money you will win with your bet
multipliers := map[string] uint{
"A" : 30,
"B" : 15,
"C" : 7,
"D" : 2,
}
symbolsArr := generateSymbolsArray(symbols)
balance := uint(200)
GetName()
for balance > 0 {
bet := GetBet(balance)
if bet == 0 {
break
}
balance = balance - bet
spin := getSpin(symbolsArr, 3,3)
printSpin(spin)
//here we check if you win and check balance
winningLines := checkWin(spin, multipliers)
for i, multi := range winningLines{
win := multi * bet
balance = balance + win
if multi > 0 {
fmt.Printf("Won $%d, (%dx) on Line #%d\n", win, multi, i + 1)
}
}
}
fmt.Printf("Your left with, $%d.\n", balance)
}// end main