-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathperft.go
More file actions
33 lines (30 loc) · 716 Bytes
/
Copy pathperft.go
File metadata and controls
33 lines (30 loc) · 716 Bytes
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
package dragontoothmg
import "fmt"
// Run perft to count the number of moves.
// Useful for testing and benchmarking.
func Perft(b *Board, n int) int64 {
if n <= 0 {
return 1
}
moves := b.GenerateLegalMoves()
if n == 1 {
return int64(len(moves))
}
var count int64 = 0
for _, move := range moves {
unapply := b.Apply(move)
count += Perft(b, n-1)
unapply()
}
return int64(count)
}
// Performs the Perft move count division operation. Useful for debugging.
func Divide(b *Board, n int) {
moves := b.GenerateLegalMoves()
for _, move := range moves {
unapply := b.Apply(move)
result := Perft(b, n-1)
unapply()
fmt.Printf( /*"Move #%3d: "*/ "%-6s =%9d\n" /*i+1, */, &move, result)
}
}