-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (55 loc) · 1.45 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
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
var board Board
turn, side := 1, White
seed := time.Now().UnixNano()
fmt.Printf("Random number seed is %d\n", seed)
rand.Seed(seed)
board.Init()
for {
var line string
fmt.Printf("\nPrior to Turn #%d (%s's move):\n\n", turn, side.Color())
board.Show()
fmt.Println()
incheck := board.isCheck(side)
if incheck {
fmt.Println("Oh god help me, I'm in CHECK!")
}
var chosenmove Move
var stalemate bool
if side == White {
moves := board.CandidateMoves(side)
moves.Show("Candidate Moves for " + side.Color() + ": ")
moves = moves.PruneForCheck(&board, side)
moves.Show("Pruned Candidate Moves for " + side.Color() + ": ")
if len(moves) == 0 {
fmt.Println(side.Color() + " has no moves remaining, STALEMATE!")
break
}
chosenmove = moves.ChooseRandom(side)
} else { // Black's move
//chosenmove = moves.ChooseNoDepth(side)
chosenmove, stalemate = board.ChooseBestWithDepth(side, 2, incheck)
if stalemate {
fmt.Println(side.Color() + " has no moves remaining, STALEMATE!")
break
}
}
fmt.Println("Chosen move: " + chosenmove.Name())
board.Apply(chosenmove)
fmt.Printf("\nAfter Turn #%d (%s's move):\n\n", turn, side.Color())
board.ShowMarked(chosenmove.getTo())
if board.isCheckMate(*(side.Other())) {
fmt.Println(side.Other().Color() + " is in CHECKMATE!")
break
}
side ^= ColorMask
turn++
fmt.Scanln(&line)
}
}