Summary
Add a pure function hasValuableMoves(state: BeleagueredCastleState): boolean to BeleagueredCastleRules.ts that determines whether any of the currently legal moves are 'valuable' -- i.e. executing the move would make at least one new move available involving a card not already involved in the current legal moves.
Implementation Approach
- Get the current set of legal moves via
getLegalMoves(state).
- Extract the set of card identifiers involved in those moves (the top cards of source/destination columns and foundation targets).
- For each legal move:
a. Apply the move to a snapshot/clone of the state.
b. Get the new set of legal moves in the resulting state.
c. Extract the set of card identifiers involved in the new moves.
d. If any card in the new set was NOT in the original set, this move is valuable.
e. Undo the move to restore the original state.
- Return true if at least one valuable move was found.
Note: Foundation moves are always valuable since they permanently advance progress.
Acceptance Criteria
- Function exported from BeleagueredCastleRules.ts
- A move is valuable if after executing it, at least one new move involves a card not involved in any move before
- Foundation moves are always valuable (they always expose a new card or win)
- Returns false when the only available moves just shuffle cards without exposing new possibilities
- Works correctly with empty columns, single-card columns
- Pure function: does not mutate state
Summary
Add a pure function
hasValuableMoves(state: BeleagueredCastleState): booleantoBeleagueredCastleRules.tsthat determines whether any of the currently legal moves are 'valuable' -- i.e. executing the move would make at least one new move available involving a card not already involved in the current legal moves.Implementation Approach
getLegalMoves(state).a. Apply the move to a snapshot/clone of the state.
b. Get the new set of legal moves in the resulting state.
c. Extract the set of card identifiers involved in the new moves.
d. If any card in the new set was NOT in the original set, this move is valuable.
e. Undo the move to restore the original state.
Note: Foundation moves are always valuable since they permanently advance progress.
Acceptance Criteria