Browse Source

Fix resetting premoves too early

master
Trevor Slocum 3 weeks ago
parent
commit
18c4cdbc32
  1. 12
      board.go
  2. 2
      client.go
  3. 2
      go.mod
  4. 4
      go.sum
  5. 9
      util.go

12
board.go

@ -172,8 +172,6 @@ func (b *Board) autoSendMoves() {
}
b.ResetPreMoves()
b.client.Out <- moveCommand
}
@ -220,6 +218,8 @@ func (b *Board) SetState(state string) {
copy(b.v, v)
b.ResetPreMoves()
b.Unlock()
b.Draw()
}
@ -400,7 +400,7 @@ func (b *Board) PlayerHomeSpaces() (int, int) {
return homeBoardStart, homeBoardEnd
}
func (b *Board) allPlayerPiecesInHomeBoard() bool {
func (b *Board) PlayerPieceAreHome() bool {
homeBoardStart, homeBoardEnd := b.PlayerHomeSpaces()
hasPlayerPiece := func(index int) bool {
if index < 0 || index > 25 {
@ -433,7 +433,7 @@ func (b *Board) spaceAvailable(index int) bool {
return false
}
if index == 0 || index == 25 {
return b.allPlayerPiecesInHomeBoard()
return b.PlayerPieceAreHome()
}
return (b.v[StatePlayerColor] == 1 && b.v[StateBoardSpace0+index] >= -1) ||
(b.v[StatePlayerColor] == -1 && b.v[StateBoardSpace0+index] <= 1)
@ -465,7 +465,7 @@ func (b *Board) GetValidMoves(from int) [][]int {
[]int{b.v[StatePlayerDice1], b.v[StatePlayerDice1], b.v[StatePlayerDice1], b.v[StatePlayerDice1]})
}
if b.allPlayerPiecesInHomeBoard() {
if b.PlayerPieceAreHome() {
homeSpace := b.PlayerBearOffSpace()
spacesHome := from - homeSpace
if spacesHome < 0 {
@ -513,7 +513,7 @@ func (b *Board) ValidMove(f int, t int) bool {
if t == b.PlayerBearOffSpace() {
// TODO bear off logic, only allow high roll
return b.allPlayerPiecesInHomeBoard()
return b.PlayerPieceAreHome()
}
validMoves := b.GetValidMoves(f)

2
client.go

@ -211,7 +211,7 @@ func (c *Client) handleWrite() {
lf("Current turn: %d", c.Board.v[StateTurn])
lf("Player home spaces: %d-%d",
homeBoardStart, homeBoardEnd)
lf("Player can bear off: %t", c.Board.allPlayerPiecesInHomeBoard())
lf("Player can bear off: %t", c.Board.PlayerPieceAreHome())
lf("Moves: %+v", c.Board.moves)
lf("Pre-moves: %+v", c.Board.premove)
continue

2
go.mod

@ -9,4 +9,4 @@ require (
nhooyr.io/websocket v1.8.7
)
require github.com/klauspost/compress v1.13.5 // indirect
require github.com/klauspost/compress v1.13.6 // indirect

4
go.sum

@ -28,8 +28,8 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.13.5 h1:9O69jUPDcsT9fEm74W92rZL9FQY7rCdaXVneq+yyzl4=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=

9
util.go

@ -3,7 +3,6 @@ package fibs
import (
"fmt"
"io"
"log"
"strings"
"time"
"unicode"
@ -19,13 +18,13 @@ func l(s string) {
s = strings.ReplaceAll(s, "\a", "")
s = strings.ReplaceAll(s, "\r", "")
m := time.Now().Format("15:04") + "| " + s
m := time.Now().Format("15:04") + " " + s
if StatusWriter != nil {
StatusWriter.Write([]byte(m + "\n"))
return
}
log.Println(m)
fmt.Println(m)
}
func lf(format string, a ...interface{}) {
@ -37,11 +36,11 @@ func lg(s string) {
s = strings.ReplaceAll(s, "\a", "")
s = strings.ReplaceAll(s, "\r", "")
m := time.Now().Format("15:04") + "| " + s
m := time.Now().Format("15:04") + " " + s
if GameWriter != nil {
GameWriter.Write([]byte(m + "\n"))
return
}
log.Println(m)
fmt.Println(m)
}

Loading…
Cancel
Save