Skip to content

Commit

Permalink
Allow playing dev cards before rolling. Remove duplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zarns committed Nov 5, 2024
1 parent 3b2f398 commit b8e9b9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
44 changes: 16 additions & 28 deletions catanatron_core/catanatron/models/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,26 @@ def generate_playable_actions(state) -> List[Action]:
elif action_prompt == ActionPrompt.MOVE_ROBBER:
return robber_possibilities(state, color)
elif action_prompt == ActionPrompt.PLAY_TURN:
actions = []
# Allow playing dev cards before and after rolling
if player_can_play_dev(state, color, "YEAR_OF_PLENTY"):
actions.extend(year_of_plenty_possibilities(color, state.resource_freqdeck))
if player_can_play_dev(state, color, "MONOPOLY"):
actions.extend(monopoly_possibilities(color))
if player_can_play_dev(state, color, "KNIGHT"):
actions.append(Action(color, ActionType.PLAY_KNIGHT_CARD, None))
if (
player_can_play_dev(state, color, "ROAD_BUILDING")
and len(road_building_possibilities(state, color, False)) > 0
):
actions.append(Action(color, ActionType.PLAY_ROAD_BUILDING, None))

if state.is_road_building:
actions = road_building_possibilities(state, color, False)
elif not player_has_rolled(state, color):
actions = [Action(color, ActionType.ROLL, None)]
# Allow playing any dev card before rolling
if player_can_play_dev(state, color, "KNIGHT"):
actions.append(Action(color, ActionType.PLAY_KNIGHT_CARD, None))
if player_can_play_dev(state, color, "YEAR_OF_PLENTY"):
actions.extend(
year_of_plenty_possibilities(color, state.resource_freqdeck)
)
if player_can_play_dev(state, color, "MONOPOLY"):
actions.extend(monopoly_possibilities(color))
if player_can_play_dev(state, color, "ROAD_BUILDING"):
actions.append(Action(color, ActionType.PLAY_ROAD_BUILDING, None))
actions.append(Action(color, ActionType.ROLL, None))
else:
actions = [Action(color, ActionType.END_TURN, None)]
actions.append(Action(color, ActionType.END_TURN, None))
actions.extend(road_building_possibilities(state, color))
actions.extend(settlement_possibilities(state, color))
actions.extend(city_possibilities(state, color))
Expand All @@ -79,21 +82,6 @@ def generate_playable_actions(state) -> List[Action]:
if can_buy_dev_card:
actions.append(Action(color, ActionType.BUY_DEVELOPMENT_CARD, None))

# Play Dev Cards
if player_can_play_dev(state, color, "YEAR_OF_PLENTY"):
actions.extend(
year_of_plenty_possibilities(color, state.resource_freqdeck)
)
if player_can_play_dev(state, color, "MONOPOLY"):
actions.extend(monopoly_possibilities(color))
if player_can_play_dev(state, color, "KNIGHT"):
actions.append(Action(color, ActionType.PLAY_KNIGHT_CARD, None))
if (
player_can_play_dev(state, color, "ROAD_BUILDING")
and len(road_building_possibilities(state, color, False)) > 0
):
actions.append(Action(color, ActionType.PLAY_ROAD_BUILDING, None))

# Trade
actions.extend(maritime_trade_possibilities(state, color))
return actions
Expand Down
5 changes: 1 addition & 4 deletions tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ def test_play_road_building(fake_roll_dice):
):
game.play_tick()

# roll not a 7
fake_roll_dice.return_value = (1, 2)
game.play_tick() # roll

# Play Road Building before rolling
game.execute(Action(p0.color, ActionType.PLAY_ROAD_BUILDING, None))
assert game.state.is_road_building
assert game.state.free_roads_available == 2
Expand Down

0 comments on commit b8e9b9b

Please sign in to comment.