|
|
|
@ -161,7 +161,7 @@ func (b *Board) autoSendMoves() {
@@ -161,7 +161,7 @@ func (b *Board) autoSendMoves() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var to string |
|
|
|
|
if b.premove[i][1] == b.PlayerHomeSpace() { |
|
|
|
|
if b.premove[i][1] == b.PlayerBearOffSpace() { |
|
|
|
|
to = "off" |
|
|
|
|
} else { |
|
|
|
|
to = strconv.Itoa(b.premove[i][1]) |
|
|
|
@ -188,11 +188,6 @@ func (b *Board) GetState() string {
@@ -188,11 +188,6 @@ func (b *Board) GetState() string {
|
|
|
|
|
func (b *Board) SetState(state string) { |
|
|
|
|
b.Lock() |
|
|
|
|
|
|
|
|
|
/*lastTurn := 0 |
|
|
|
|
if len(b.v) > 0 { |
|
|
|
|
lastTurn = b.v[StateTurn] |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
s := strings.Split(state, ":") |
|
|
|
|
newPlayers := s[StatePlayerName] != b.s[StatePlayerName] || s[StateOpponentName] != b.s[StateOpponentName] |
|
|
|
|
copy(b.s, s) |
|
|
|
@ -225,22 +220,6 @@ func (b *Board) SetState(state string) {
@@ -225,22 +220,6 @@ func (b *Board) SetState(state string) {
|
|
|
|
|
|
|
|
|
|
copy(b.v, v) |
|
|
|
|
|
|
|
|
|
/*if b.v[StateTurn] != lastTurn { |
|
|
|
|
if lastTurn == b.v[StatePlayerColor] { |
|
|
|
|
b.playerDice = [2]int{0, 0} |
|
|
|
|
} else { |
|
|
|
|
b.opponentDice = [2]int{0, 0} |
|
|
|
|
} |
|
|
|
|
}*/ // TODO disabled
|
|
|
|
|
|
|
|
|
|
// TODO only overwrite dice when player names change
|
|
|
|
|
/*if b.v[StatePlayerDice1] > 0 { |
|
|
|
|
b.playerDice = [2]int{b.v[StatePlayerDice1], b.v[StatePlayerDice2]} |
|
|
|
|
} |
|
|
|
|
if b.v[StateOpponentDice1] > 0 { |
|
|
|
|
b.opponentDice = [2]int{b.v[StateOpponentDice1], b.v[StateOpponentDice2]} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
b.Unlock() |
|
|
|
|
b.Draw() |
|
|
|
|
} |
|
|
|
@ -313,7 +292,6 @@ func (b *Board) renderSpace(index int, spaceValue int) []byte {
@@ -313,7 +292,6 @@ func (b *Board) renderSpace(index int, spaceValue int) []byte {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
if abs > 5 { |
|
|
|
|
abs = 5 |
|
|
|
|
} |
|
|
|
@ -349,7 +327,6 @@ func (b *Board) renderSpace(index int, spaceValue int) []byte {
@@ -349,7 +327,6 @@ func (b *Board) renderSpace(index int, spaceValue int) []byte {
|
|
|
|
|
// Highlight legal moves
|
|
|
|
|
highlightSpace := b.ValidMove(b.selectedSpace, index) |
|
|
|
|
highlightSpace = false // TODO Make configurable, disable by default
|
|
|
|
|
//+(b.v[StatePlayerDice1]*b.v[StatePlayerColor]) ||b.selectedSpace == index+(b.v[StatePlayerDice2]*b.v[StatePlayerColor])) && b.selectedNum > 0
|
|
|
|
|
if b.selectedNum > 0 && highlightSpace && index != 25 && index != 0 { |
|
|
|
|
foregroundColor = "black" |
|
|
|
|
backgroundColor = "yellow" |
|
|
|
@ -413,7 +390,7 @@ func (b *Board) ResetPreMoves() {
@@ -413,7 +390,7 @@ func (b *Board) ResetPreMoves() {
|
|
|
|
|
b.Premoveto = make(map[int]int) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b *Board) homeBoardSpaces() (int, int) { |
|
|
|
|
func (b *Board) PlayerHomeSpaces() (int, int) { |
|
|
|
|
homeBoardStart := 1 |
|
|
|
|
homeBoardEnd := 6 |
|
|
|
|
if (b.v[StateDirection] == -1) == (b.v[StatePlayerColor] == -1) { |
|
|
|
@ -424,7 +401,7 @@ func (b *Board) homeBoardSpaces() (int, int) {
@@ -424,7 +401,7 @@ func (b *Board) homeBoardSpaces() (int, int) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b *Board) allPlayerPiecesInHomeBoard() bool { |
|
|
|
|
homeBoardStart, homeBoardEnd := b.homeBoardSpaces() |
|
|
|
|
homeBoardStart, homeBoardEnd := b.PlayerHomeSpaces() |
|
|
|
|
hasPlayerPiece := func(index int) bool { |
|
|
|
|
if index < 0 || index > 25 { |
|
|
|
|
return false |
|
|
|
@ -489,7 +466,7 @@ func (b *Board) GetValidMoves(from int) [][]int {
@@ -489,7 +466,7 @@ func (b *Board) GetValidMoves(from int) [][]int {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if b.allPlayerPiecesInHomeBoard() { |
|
|
|
|
homeSpace := b.PlayerHomeSpace() |
|
|
|
|
homeSpace := b.PlayerBearOffSpace() |
|
|
|
|
spacesHome := from - homeSpace |
|
|
|
|
if spacesHome < 0 { |
|
|
|
|
spacesHome *= -1 |
|
|
|
@ -519,10 +496,10 @@ CHECKSPACES:
@@ -519,10 +496,10 @@ CHECKSPACES:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b *Board) PlayerBarSpace() int { |
|
|
|
|
return 25 - b.PlayerHomeSpace() |
|
|
|
|
return 25 - b.PlayerBearOffSpace() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b *Board) PlayerHomeSpace() int { |
|
|
|
|
func (b *Board) PlayerBearOffSpace() int { |
|
|
|
|
if b.v[StateDirection] == -1 { |
|
|
|
|
return 0 |
|
|
|
|
} |
|
|
|
@ -534,7 +511,7 @@ func (b *Board) ValidMove(f int, t int) bool {
@@ -534,7 +511,7 @@ func (b *Board) ValidMove(f int, t int) bool {
|
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if t == b.PlayerHomeSpace() { |
|
|
|
|
if t == b.PlayerBearOffSpace() { |
|
|
|
|
// TODO bear off logic, only allow high roll
|
|
|
|
|
return b.allPlayerPiecesInHomeBoard() |
|
|
|
|
} |
|
|
|
@ -568,7 +545,7 @@ func (b *Board) parseMoveString(player int, s string) int {
@@ -568,7 +545,7 @@ func (b *Board) parseMoveString(player int, s string) int {
|
|
|
|
|
space = 25 - barSpace |
|
|
|
|
} |
|
|
|
|
} else if s == "off" { |
|
|
|
|
space = b.PlayerHomeSpace() |
|
|
|
|
space = b.PlayerBearOffSpace() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return space |
|
|
|
@ -579,7 +556,7 @@ func (b *Board) Move(player int, f string, t string) {
@@ -579,7 +556,7 @@ func (b *Board) Move(player int, f string, t string) {
|
|
|
|
|
to := b.parseMoveString(player, t) |
|
|
|
|
|
|
|
|
|
if from == SpaceUnknown || to == SpaceUnknown { |
|
|
|
|
// TODO debug print ("error: failed to parse move: player %d, from %s, to %s", player, f, t)
|
|
|
|
|
lf("WARNING: Unknown move %s-%s", f, t) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -589,6 +566,21 @@ func (b *Board) Move(player int, f string, t string) {
@@ -589,6 +566,21 @@ func (b *Board) Move(player int, f string, t string) {
|
|
|
|
|
b.from[from]++ |
|
|
|
|
b.to[to]++ |
|
|
|
|
|
|
|
|
|
spaceValue := b.v[StateBoardSpace0+to] |
|
|
|
|
|
|
|
|
|
// Hit.
|
|
|
|
|
if (spaceValue == -1 && player == 1) || (spaceValue == 1 && player == -1) { |
|
|
|
|
bar := 25 - b.PlayerBarSpace() |
|
|
|
|
if player == b.v[StatePlayerColor] { |
|
|
|
|
bar = b.PlayerBarSpace() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
b.v[StateBoardSpace0+bar] -= player |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
b.v[StateBoardSpace0+from] -= player |
|
|
|
|
b.v[StateBoardSpace0+to] += player |
|
|
|
|
|
|
|
|
|
b.v[StateTurn] = player * -1 |
|
|
|
|
|
|
|
|
|
b.validMoves = make(map[int][][]int) |
|
|
|
@ -630,7 +622,7 @@ func (b *Board) ResetSelection() {
@@ -630,7 +622,7 @@ func (b *Board) ResetSelection() {
|
|
|
|
|
func (b *Board) addPreMove(from int, to int, num int) bool { |
|
|
|
|
// Allow bearing off when the player moves their own pieces on to the bar
|
|
|
|
|
if to == 0 || to == 25 { |
|
|
|
|
to = b.PlayerHomeSpace() |
|
|
|
|
to = b.PlayerBearOffSpace() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Expand combined move
|
|
|
|
|