-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuba.go
55 lines (41 loc) · 1.16 KB
/
buba.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
package buba
import (
"fmt"
"time"
"github.com/notnil/chess"
)
func BestMove(fen_string string) *chess.Move {
fen, err := chess.FEN(fen_string)
if err != nil {
panic("Invalid FEN string!")
}
counter := 0
pos := chess.NewGame(fen).Position()
maxDepth := 99
maxRuntime := 10000.0 // ms
timerStart := float64(time.Now().UnixMilli())
var bestMove *chess.Move
var currMove *chess.Move
var bestScore float64
var currScore float64
var depth int
for depth = 1; depth < maxDepth; depth++ {
currMove, currScore, err = miniMax(pos, depth, &counter, timerStart, maxRuntime)
if err != nil {
break
}
bestMove = currMove
bestScore = currScore
}
timer_end := float64(time.Now().UnixMilli())
timer_diff := timer_end - timerStart
timer_diff_sec := timer_diff / float64(time.Second.Milliseconds())
fmt.Println("summary")
fmt.Println("runtime[s]", timer_diff_sec)
fmt.Println("nodes ", counter)
fmt.Println("k-nodes/s ", int(float64(counter)/timer_diff))
fmt.Println("evaluation", bestScore/100) // change evaluation scale from pawn=100 to pawn=1
fmt.Println("depth ", depth)
fmt.Println("best_move ", bestMove.String())
return bestMove
}