-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1023 Bytes
/
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
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/sblackstone/go-chess/boardstate"
"github.com/sblackstone/go-chess/treesearch"
"github.com/sblackstone/go-chess/uci"
)
func main() {
logFile, _ := os.OpenFile("/tmp/go-chess-log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
buf := bufio.NewScanner(os.Stdin)
var board *boardstate.BoardState
sendReply := func(line string) {
logFile.WriteString(line + "\n")
fmt.Println(line)
logFile.Sync()
}
for {
buf.Scan()
command := buf.Text()
logFile.WriteString(command + "\n")
logFile.Sync()
if command == "uci" {
sendReply("id name StephenChess 1.0")
sendReply("id author Stephen Blackstone")
sendReply("uciok")
}
if command == "isready" {
sendReply("readyok")
}
if strings.HasPrefix(command, "go ") {
move := treesearch.BestMoveSmp(board, 5)
sendReply(fmt.Sprintf("bestmove %s", uci.MoveToUCI(move)))
}
if strings.HasPrefix(command, "position") {
board = uci.BoardFromUCIPosition(command)
}
}
}