feat(SCOPONE-0008): complete iteration 0 improve ai rules
This commit is contained in:
@@ -39,15 +39,14 @@ export function shuffle<T>(arr: T[]): T[] {
|
||||
* Returns array of capture sets (each is a list of cards taken from table).
|
||||
*/
|
||||
export function findCaptures(played: Card, table: Card[]): Card[][] {
|
||||
const results: Card[][] = [];
|
||||
|
||||
// Each direct-match card is a separate single-card capture option
|
||||
const directMatches = table.filter(c => c.value === played.value);
|
||||
for (const dm of directMatches) {
|
||||
results.push([dm]);
|
||||
if (directMatches.length > 0) {
|
||||
return directMatches.map((directMatch): Card[] => [directMatch]);
|
||||
}
|
||||
|
||||
// Also find multi-card subsets that sum to played.value
|
||||
const results: Card[][] = [];
|
||||
// Only sum captures are legal when no direct match is available.
|
||||
const subsets = getSubsets(table);
|
||||
for (const subset of subsets) {
|
||||
if (subset.length >= 2) {
|
||||
@@ -102,6 +101,7 @@ export function createInitialState(startingPlayer: PlayerIndex = 0): GameState {
|
||||
return {
|
||||
players,
|
||||
table,
|
||||
matchStartingPlayer: startingPlayer,
|
||||
currentPlayer: startingPlayer,
|
||||
roundOver: false,
|
||||
gameOver: false,
|
||||
@@ -293,6 +293,33 @@ export function getScoreBreakdown(state: GameState): ScoreBreakdown {
|
||||
return scoreRound(team0, team1);
|
||||
}
|
||||
|
||||
export function getMatchOutcome(teamScores: [TeamScore, TeamScore]): {
|
||||
winner: 0 | 1 | null;
|
||||
continueMatch: boolean;
|
||||
} {
|
||||
const [team0, team1] = teamScores;
|
||||
const thresholdReached = team0.totalPoints >= 11 || team1.totalPoints >= 11;
|
||||
|
||||
if (!thresholdReached) {
|
||||
return {
|
||||
winner: null,
|
||||
continueMatch: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (team0.totalPoints === team1.totalPoints) {
|
||||
return {
|
||||
winner: null,
|
||||
continueMatch: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
winner: team0.totalPoints > team1.totalPoints ? 0 : 1,
|
||||
continueMatch: false,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -325,6 +352,7 @@ export function cloneState(state: GameState): GameState {
|
||||
clonePlayer(state.players[3]),
|
||||
],
|
||||
table: state.table.map(cloneCard),
|
||||
matchStartingPlayer: state.matchStartingPlayer,
|
||||
currentPlayer: state.currentPlayer,
|
||||
roundOver: state.roundOver,
|
||||
gameOver: state.gameOver,
|
||||
|
||||
Reference in New Issue
Block a user