Skip to content

Commit

Permalink
Fix bug: onboard to 4th grid not marked as rosette
Browse files Browse the repository at this point in the history
Changed Move.__eq__ implementation to compare all attributes

No regression test added since this bug is exposed by the original test suite
after the above change is implemented
  • Loading branch information
Casper-Guo committed Jun 1, 2024
1 parent 153dbfa commit 62c660c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions royal_game/modules/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Board:
bit 28-39: three bit each for WS, WE, BS, BE
indicating number of pieces at start/end
122138132480 = (7 << 28) + (7 << 34)
122138132480 = (7 << 28) + (7 << 34) represents
the empty starting board.
"""

white_rosettes = set(["W4", "8", "W14"])
Expand Down Expand Up @@ -191,7 +192,14 @@ def get_available_moves(self, white_turn: bool, dice_roll: int) -> tuple[Move]:
and self.board[start_grid].num_pieces > 0
):
available_moves.append(
Move(start_grid, grids[dice_roll - 1], is_onboard=True, no_verify=True)
Move(
start_grid,
grids[dice_roll - 1],
# if the roll is 4 then the onboard move also claims a rosette
is_rosette=dice_roll == 4,
is_onboard=True,
no_verify=True,
)
)
if self.board[grids[-dice_roll]].status is own_status:
available_moves.append(
Expand Down
16 changes: 15 additions & 1 deletion royal_game/modules/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,21 @@ def __repr__(self) -> str:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Move):
return NotImplemented
return self.grid1 == other.grid1 and self.grid2 == other.grid2
return (
self.grid1,
self.grid2,
self.is_rosette,
self.is_capture,
self.is_ascension,
self.is_onboard,
) == (
other.grid1,
other.grid2,
other.is_rosette,
other.is_capture,
other.is_ascension,
other.is_onboard,
)

def __hash__(self) -> int:
return hash((self.grid1, self.grid2))
Expand Down

0 comments on commit 62c660c

Please sign in to comment.