Fix playing acey-deucey games
This commit is contained in:
parent
d51931e431
commit
60982417c5
1 changed files with 3 additions and 31 deletions
|
@ -431,22 +431,15 @@ func (c *Client) HandleEvents() {
|
|||
c.Out <- []byte(fmt.Sprintf("ok %d", doubles))
|
||||
c.lastActivity = time.Now()
|
||||
continue
|
||||
}
|
||||
|
||||
if len(Game.Moves) != 0 {
|
||||
continue
|
||||
} else if len(Game.Available) == 0 {
|
||||
} else if Game.MayOK() {
|
||||
if c.thinkTime != 0 {
|
||||
time.Sleep(c.thinkTime)
|
||||
}
|
||||
c.Out <- []byte("ok")
|
||||
c.lastActivity = time.Now()
|
||||
continue
|
||||
}
|
||||
|
||||
var t time.Time
|
||||
if c.thinkTime != 0 {
|
||||
t = time.Now()
|
||||
} else if len(Game.Moves) != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
boardState := TabulaBoard(Game.Board)
|
||||
|
@ -499,26 +492,6 @@ func (c *Client) HandleEvents() {
|
|||
}
|
||||
}
|
||||
|
||||
if c.thinkTime != 0 {
|
||||
s := time.Since(t)
|
||||
if s < c.thinkTime {
|
||||
time.Sleep(c.thinkTime - s)
|
||||
}
|
||||
}
|
||||
if Game.MayChooseRoll() {
|
||||
newGame := Game.Copy(false)
|
||||
for _, move := range c.analysis[0].Moves {
|
||||
if move[0] == 0 && move[1] == 0 {
|
||||
break
|
||||
}
|
||||
newGame.AddLocalMove([]int8{move[0], move[1]})
|
||||
}
|
||||
newBoardState := TabulaBoard(newGame.Board)
|
||||
doubles := newBoardState.ChooseDoubles(&c.analysis)
|
||||
c.Out <- []byte(fmt.Sprintf("ok %d", doubles))
|
||||
} else {
|
||||
c.Out <- []byte("ok")
|
||||
}
|
||||
c.lastActivity = time.Now()
|
||||
case *bgammon.EventRolled:
|
||||
Game.Roll1 = ev.Roll1
|
||||
|
@ -556,7 +529,6 @@ func (c *Client) HandleEvents() {
|
|||
log.Printf("*** Failed to move checker%s: %s", extra, ev.Reason)
|
||||
log.Printf("*** Legal moves: %s", bgammon.FormatMoves(Game.Available))
|
||||
case *bgammon.EventFailedOk:
|
||||
c.Out <- []byte("board") // Refresh game state.
|
||||
log.Printf("*** Failed to submit moves: %s", ev.Reason)
|
||||
case *bgammon.EventWin:
|
||||
log.Printf("%s wins!", ev.Player)
|
||||
|
|
Loading…
Reference in a new issue