-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (90 loc) · 1.79 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
package main
import (
"fmt"
"math/rand"
)
func getName() string {
name := ""
fmt.Println("Slot")
fmt.Printf("Enter your name:")
_, err := fmt.Scanln(&name)
if err != nil {
return ""
}
fmt.Printf("Welcome %s, let's play!\n", name)
return name
}
func getBet(balance uint) uint {
var bet uint
for {
fmt.Printf("Enter your bet, or 0 to quit (balance = $%d:)", balance)
fmt.Scan(&bet)
if bet > balance {
fmt.Println("Bet cannot be larger than balance")
} else {
break
}
}
return bet
}
func generateSymbolArray(symbols map[string]uint) []string {
symbolArr := []string{}
for symbol, count := range symbols {
for i := uint(0); i < count; i++ {
symbolArr = append(symbolArr, symbol)
}
}
return symbolArr
}
func getRandomNumber(min int, max int) int {
randomNumber := rand.Intn(max-min+1) + min
return randomNumber
}
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 {
randomIndex := getRandomNumber(0, len(reel)-1)
_, exists := selected[randomIndex]
if !exists {
selected[randomIndex] = true
result[row] = append(result[row], reel[randomIndex])
break
}
}
}
}
return result
}
func main() {
symbols := map[string]uint{
"A": 4,
"B": 7,
"C": 12,
"D": 20,
}
// multipler := map[string]uint{
// "A": 20,
// "B": 10,
// "C": 5,
// "D": 2,
// }
symbolArr := generateSymbolArray(symbols)
spin := getSpin(symbolArr, 3, 3)
fmt.Println(spin)
balance := uint(200)
getName()
for balance > 0 {
bet := getBet(balance)
if bet == 0 {
break
}
balance -= bet
}
fmt.Printf("You are left with: $%d.\n", balance)
}