Browse Source

Support specifying doubles as a combined move

tableissue
Trevor Slocum 2 months ago
parent
commit
cff022b72a
  1. 10
      README.md
  2. 26
      board.go

10
README.md

@ -52,6 +52,16 @@ Click on another space to move all selected pieces to it.
Your moves will automatically be submitted once you have input enough of them.
**PROTIP:** You don't always have to input each of your individual moves,
bgammon will guess at what you meant when you move a piece beyond a single
move. For instance, when you roll double 2s, you could grab one piece and move
it eight spaces by clicking on space 2 and then space 10. You could also move
two pieces four spaces by grabbing two pieces and clicking on space 2 and then
space 6. This also applies to normal rolls, when you roll 5 and 2, you could
move a piece seven spaces by clicking on space 2 and then clicking on 9. When
one of the implied first moves results in sending one of your opponents pieces
to the bar, that move is always chosen.
To chat, simply write some text and press enter.
To change chat modes between shout and kibitz, press tab.

26
board.go

@ -130,6 +130,29 @@ func (b *Board) autoSendMoves() {
if b.v[StateMovablePieces] > 0 {
movable = b.v[StateMovablePieces]
}
if len(b.premove) == 1 {
abs := b.premove[0][1] - b.premove[0][0]
direction := 1
if abs < 0 {
abs *= -1
direction = -1
}
if b.playerDice[0] == b.playerDice[1] {
for expandDoubles := 4; expandDoubles >= 2; expandDoubles-- {
if abs != b.playerDice[0]*expandDoubles {
continue
}
from, _ := b.premove[0][0], b.premove[0][1]
b.premove = nil
for i := 1; i <= expandDoubles; i++ {
b.premove = append(b.premove, [2]int{from + ((b.playerDice[0]*i - 1) * direction), from + ((b.playerDice[0] * i) * direction)})
}
break
}
}
}
if len(b.premove) < movable {
return
}
@ -529,7 +552,8 @@ func (b *Board) validMove(f int, t int) bool {
}
// TODO remove any dice used in premove
return spaces == b.playerDice[0] || spaces == b.playerDice[1] || spaces == b.playerDice[0]+b.playerDice[1] || (b.playerDice[0] == b.playerDice[1] && (spaces == b.playerDice[0]*3 || spaces == b.playerDice[0]*4))
return spaces == b.playerDice[0] || spaces == b.playerDice[1] || spaces == b.playerDice[0]+b.playerDice[1] ||
(b.playerDice[0] == b.playerDice[1] && (spaces == b.playerDice[0]*3 || spaces == b.playerDice[0]*4))
}
func (b *Board) Move(player int, f string, t string) {

Loading…
Cancel
Save