Fix parsing error
This commit is contained in:
parent
1f8ee17cc0
commit
2a31ba04d6
1 changed files with 5 additions and 6 deletions
11
gnubg.go
11
gnubg.go
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue