1
0

Fix Play Two Roads interaction

This commit is contained in:
James Ketr 2025-10-11 13:14:07 -07:00
parent 67f2580e3a
commit 419b36c22f
2 changed files with 43 additions and 8 deletions

View File

@ -246,7 +246,13 @@ const Activities: React.FC = () => {
{placement && ( {placement && (
<div className="Requirement"> <div className="Requirement">
{who} must place a {placeRoad ? "road" : "settlement"}. {who} must place {
(turn && (turn as any).active === "road-building" && (turn as any).freeRoads)
? `${(turn as any).freeRoads} roads`
: placeRoad
? "a road"
: "a settlement"
}.
</div> </div>
)} )}

View File

@ -2839,14 +2839,43 @@ const placeRoad = (game: Game, session: Session, index: number): string | undefi
road.color = session.color; road.color = session.color;
road.type = "road"; road.type = "road";
player.roads--; player.roads--;
/* Handle normal play road placement including Road Building free roads.
* If the turn is a road-building action, decrement freeRoads and
* only clear actions when no free roads remain. Otherwise, during
* initial placement we advance the initial-placement sequence. */
if (game.state === "normal") {
addActivity(game, session, `${session.name} placed a road.`);
calculateRoadLengths(game, session);
/* During initial placement, placing a road advances the initial-placement let resetLimits = true;
* sequence. In forward direction we move to the next player; when the if (game.turn && (game.turn as any).active === "road-building") {
* last player places their road we flip to backward and begin the reverse if ((game.turn as any).freeRoads !== undefined) {
* settlement placements. In backward direction we move to the previous (game.turn as any).freeRoads = (game.turn as any).freeRoads - 1;
* player and when the first player finishes, initial placement is done }
* and normal play begins. */ if ((game.turn as any).freeRoads === 0) {
if (game.state === "initial-placement") { delete (game.turn as any).free;
delete (game.turn as any).active;
delete (game.turn as any).freeRoads;
}
const roads = getValidRoads(game, session.color as string);
if (!roads || roads.length === 0) {
delete (game.turn as any).active;
delete (game.turn as any).freeRoads;
addActivity(game, session, `${session.name} has another road to play, but there are no more valid locations.`);
} else if ((game.turn as any).freeRoads !== 0) {
(game.turn as any).free = true;
setForRoadPlacement(game, roads);
resetLimits = false;
}
}
if (resetLimits) {
delete (game.turn as any).free;
game.turn.actions = [];
game.turn.limits = {};
}
} else if (game.state === "initial-placement") {
const order: PlayerColor[] = game.playerOrder; const order: PlayerColor[] = game.playerOrder;
const idx = order.indexOf(session.color); const idx = order.indexOf(session.color);
// defensive: if player not found, just clear actions and continue // defensive: if player not found, just clear actions and continue