Browse Source

Retain dice rolls

master
Trevor Slocum 1 month ago
parent
commit
9b048ec05d
  1. 28
      board.go
  2. 10
      client.go

28
board.go

@ -217,17 +217,35 @@ func (b *Board) SetState(state string) {
}*/
s := strings.Split(state, ":")
newPlayers := s[StatePlayerName] != b.s[StatePlayerName] || s[StateOpponentName] != b.s[StateOpponentName]
copy(b.s, s)
var err error
v := make([]int, 50)
var err error
for i := 0; i < 50; i++ {
v[i], err = strconv.Atoi(b.s[i+2])
if err != nil {
log.Fatal(err)
}
}
newTurn := v[StateTurn] != b.v[StateTurn]
// Retain dice rolls
if !newPlayers && !newTurn {
copyDice := []int{
StatePlayerDice1,
StatePlayerDice2,
StateOpponentDice1,
StateOpponentDice2,
}
for _, vi := range copyDice {
if v[vi] == 0 {
v[vi] = b.v[vi]
}
}
}
copy(b.v, v)
/*if b.v[StateTurn] != lastTurn {
@ -434,8 +452,10 @@ func (b *Board) allPlayerPiecesInHomeBoard() bool {
if index < 0 || index > 25 {
return false
}
return (b.v[StatePlayerColor] == 1 && b.v[StateBoardSpace0+index] > 0) ||
(b.v[StatePlayerColor] == -1 && b.v[StateBoardSpace0+index] < 0)
value := b.v[StateBoardSpace0+index]
mod := b.v[StatePlayerColor]
value -= b.client.Board.Premovefrom[index] * mod
return value != 0
}
for i := 1; i < 24; i++ {
if i >= homeBoardStart && i <= homeBoardEnd {

10
client.go

@ -682,6 +682,16 @@ func (c *Client) eventLoop() {
}
c.Board.SimplifyMoves()
c.Board.v[StateTurn] = player * -1
if c.Board.v[StateTurn] == c.Board.v[StatePlayerColor] {
c.Board.v[StatePlayerDice1] = 0
c.Board.v[StatePlayerDice2] = 0
} else {
c.Board.v[StateOpponentDice1] = 0
c.Board.v[StateOpponentDice2] = 0
}
c.Board.Draw()
bs := string(b)

Loading…
Cancel
Save