From d98b96dc2f345836df89a3f0ffaf17fcbff650f4 Mon Sep 17 00:00:00 2001 From: Mason Zarns Date: Sun, 3 Nov 2024 11:41:48 -0600 Subject: [PATCH 1/5] Disallow player to play dev card same turn --- catanatron_core/catanatron/state.py | 4 ++++ catanatron_core/catanatron/state_functions.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/catanatron_core/catanatron/state.py b/catanatron_core/catanatron/state.py index 665eab8c..2a3c98d5 100644 --- a/catanatron_core/catanatron/state.py +++ b/catanatron_core/catanatron/state.py @@ -76,6 +76,10 @@ # de-normalized features (for performance since we think they are good features) "ACTUAL_VICTORY_POINTS": 0, "LONGEST_ROAD_LENGTH": 0, + "KNIGHT_PURCHASED_THIS_TURN": 0, + "MONOPOLY_PURCHASED_THIS_TURN": 0, + "YEAR_OF_PLENTY_PURCHASED_THIS_TURN": 0, + "ROAD_BUILDING_PURCHASED_THIS_TURN": 0, } for resource in RESOURCES: PLAYER_INITIAL_STATE[f"{resource}_IN_HAND"] = 0 diff --git a/catanatron_core/catanatron/state_functions.py b/catanatron_core/catanatron/state_functions.py index acf71799..4b71391d 100644 --- a/catanatron_core/catanatron/state_functions.py +++ b/catanatron_core/catanatron/state_functions.py @@ -225,9 +225,17 @@ def player_resource_freqdeck_contains(state, color, freqdeck): def player_can_play_dev(state, color, dev_card): key = player_key(state, color) + + cards_in_hand = state.player_state[f"{key}_{dev_card}_IN_HAND"] + cards_purchased_this_turn = state.player_state[ + f"{key}_{dev_card}_PURCHASED_THIS_TURN" + ] + playable_cards = cards_in_hand - cards_purchased_this_turn + return ( not state.player_state[f"{key}_HAS_PLAYED_DEVELOPMENT_CARD_IN_TURN"] - and state.player_state[f"{key}_{dev_card}_IN_HAND"] >= 1 + # Must have at least 1 card that wasn't purchased this turn + and playable_cards > 0 ) @@ -259,6 +267,9 @@ def buy_dev_card(state, color, dev_card): state.player_state[f"{key}_{dev_card}_IN_HAND"] += 1 if dev_card == VICTORY_POINT: state.player_state[f"{key}_ACTUAL_VICTORY_POINTS"] += 1 + else: + # Mark as purchased this turn + state.player_state[f"{key}_{dev_card}_PURCHASED_THIS_TURN"] += 1 state.player_state[f"{key}_SHEEP_IN_HAND"] -= 1 state.player_state[f"{key}_WHEAT_IN_HAND"] -= 1 @@ -334,3 +345,8 @@ def player_clean_turn(state, color): key = player_key(state, color) state.player_state[f"{key}_HAS_PLAYED_DEVELOPMENT_CARD_IN_TURN"] = False state.player_state[f"{key}_HAS_ROLLED"] = False + # Reset all purchased-this-turn counters + state.player_state[f"{key}_KNIGHT_PURCHASED_THIS_TURN"] = 0 + state.player_state[f"{key}_MONOPOLY_PURCHASED_THIS_TURN"] = 0 + state.player_state[f"{key}_YEAR_OF_PLENTY_PURCHASED_THIS_TURN"] = 0 + state.player_state[f"{key}_ROAD_BUILDING_PURCHASED_THIS_TURN"] = 0 From 63cbaa2030d89d5468a00e4e521509753ccafe66 Mon Sep 17 00:00:00 2001 From: Mason Zarns Date: Sun, 3 Nov 2024 11:42:09 -0600 Subject: [PATCH 2/5] Allow player to play dev cards before rolling --- catanatron_core/catanatron/models/actions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/catanatron_core/catanatron/models/actions.py b/catanatron_core/catanatron/models/actions.py index 9bb414dc..7574fc41 100644 --- a/catanatron_core/catanatron/models/actions.py +++ b/catanatron_core/catanatron/models/actions.py @@ -55,8 +55,17 @@ def generate_playable_actions(state) -> List[Action]: 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)) else: actions = [Action(color, ActionType.END_TURN, None)] actions.extend(road_building_possibilities(state, color)) From cb4b99cef343bee14f6a8bd26b9ee6791ba3c1fd Mon Sep 17 00:00:00 2001 From: Mason Zarns Date: Sun, 3 Nov 2024 12:16:39 -0600 Subject: [PATCH 3/5] Display Select action instead of Roll if playing dev cards before rolling --- ui/src/pages/ActionsToolbar.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/src/pages/ActionsToolbar.js b/ui/src/pages/ActionsToolbar.js index 74285758..01f0e092 100644 --- a/ui/src/pages/ActionsToolbar.js +++ b/ui/src/pages/ActionsToolbar.js @@ -227,22 +227,22 @@ function PlayButtons() { color="primary" startIcon={} onClick={ - isRoll - ? rollAction - : isDiscard + isDiscard ? proceedAction : isMoveRobber ? setIsMovingRobber : isPlayingYearOfPlenty || isPlayingMonopoly ? handleOpenResourceSelector + : isRoll + ? rollAction : endTurnAction } > { - isRoll ? "ROLL" : isDiscard ? "DISCARD" : isMoveRobber ? "ROB" : isPlayingYearOfPlenty || isPlayingMonopoly ? "SELECT" : + isRoll ? "ROLL" : "END" } From 3b2f398ffa0a2c73b2d6e795aa4123e7d1053e09 Mon Sep 17 00:00:00 2001 From: Mason Zarns Date: Tue, 5 Nov 2024 11:02:17 -0600 Subject: [PATCH 4/5] hide buttons while playing dev cards --- ui/src/pages/ActionsToolbar.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/src/pages/ActionsToolbar.js b/ui/src/pages/ActionsToolbar.js index 01f0e092..2933c844 100644 --- a/ui/src/pages/ActionsToolbar.js +++ b/ui/src/pages/ActionsToolbar.js @@ -47,7 +47,7 @@ function PlayButtons() { [enqueueSnackbar, closeSnackbar] ); - const { gameState, isPlayingMonopoly, isPlayingYearOfPlenty } = state; + const { gameState, isPlayingMonopoly, isPlayingYearOfPlenty, isRoadBuilding } = state; const key = playerKey(gameState, gameState.current_color); const isRoll = gameState.current_prompt === "PLAY_TURN" && @@ -198,7 +198,7 @@ function PlayButtons() { return ( <> } items={useItems} @@ -206,7 +206,7 @@ function PlayButtons() { Use } items={buildItems} @@ -214,7 +214,7 @@ function PlayButtons() { Buy } items={tradeItems} @@ -222,7 +222,7 @@ function PlayButtons() { Trade