-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
56 lines (45 loc) · 1.04 KB
/
game.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
package main
import "fmt"
func Render(game Game) {
fmt.Printf("%s | %s | %s\n", FieldToString(game[0]), FieldToString(game[1]), FieldToString(game[2]))
fmt.Printf("- + - + -\n")
fmt.Printf("%s | %s | %s\n", FieldToString(game[3]), FieldToString(game[4]), FieldToString(game[5]))
fmt.Printf("- + - + -\n")
fmt.Printf("%s | %s | %s\n", FieldToString(game[6]), FieldToString(game[7]), FieldToString(game[8]))
}
func IsGameOver(game Game) bool {
winner := empty
for i := 0; i < 3; i++ {
winner = WonH(game, i*3)
if winner == empty {
winner = WonV(game, i%3)
if winner == empty {
winner = WonD(game)
}
}
if winner != empty {
if winner == X {
fmt.Println("Dein Gegner hat Gewonnen!")
return true
}
if winner == O {
fmt.Println("Glückwunsch, du hast Gewonnen!")
return true
}
return false
}
}
if !Contains(game, 0) {
fmt.Println("Keiner hat gewonnen!")
return true
}
return false
}
func Contains(s Game, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}