Fix parsing error

This commit is contained in:
Trevor Slocum 2024-11-27 13:01:42 -08:00
parent 1f8ee17cc0
commit 2a31ba04d6

View file

@ -220,17 +220,16 @@ func analyze(g *bgammon.Game) ([4][2]int8, error) {
}
var moves []byte
var setDice bool
var ready bool
go func() {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
buf := scanner.Bytes()
if bytes.Contains(buf, []byte("The dice have been set")) || bytes.Contains(buf, []byte("The cube has been set")) {
setDice = true
} else if setDice && moves == nil && (bytes.Contains(buf, []byte("gnubg moves")) || bytes.Contains(buf, []byte("gnubg doubles")) || bytes.Contains(buf, []byte("gnubg accepts")) || bytes.Contains(buf, []byte("gnubg refuses the cube")) || bytes.Contains(buf, []byte("gnubg offers to resign"))) {
moves = buf
} else if setDice && moves == nil && bytes.Contains(buf, []byte("Rolled")) {
moves = buf
ready = true
} else if ready && moves == nil && (bytes.Contains(buf, []byte("Rolled")) || bytes.Contains(buf, []byte("gnubg moves")) || bytes.Contains(buf, []byte("gnubg doubles")) || bytes.Contains(buf, []byte("gnubg accepts")) || bytes.Contains(buf, []byte("gnubg refuses the cube")) || bytes.Contains(buf, []byte("gnubg offers to resign"))) {
moves = make([]byte, len(buf))
copy(moves, buf)
}
log.Println(string(buf))
}