fix(SCOPONE-0008): complete iteration 1 remove ai lag
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import { Card, Suit, SUITS } from './types';
|
||||
|
||||
export interface CardTrackerSnapshot {
|
||||
playedCardIds: string[];
|
||||
}
|
||||
|
||||
function normalizeSnapshot(snapshot: CardTrackerSnapshot): CardTrackerSnapshot {
|
||||
return {
|
||||
playedCardIds: Array.from(new Set(snapshot.playedCardIds)),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks which cards have been played/captured during a round.
|
||||
* Used by AI to infer opponent hands WITHOUT cheating.
|
||||
@@ -7,6 +17,27 @@ import { Card, Suit, SUITS } from './types';
|
||||
export class CardTracker {
|
||||
private played: Set<string> = new Set(); // card IDs that have been seen
|
||||
|
||||
constructor(snapshot?: CardTrackerSnapshot) {
|
||||
if (snapshot) {
|
||||
this.restoreSnapshot(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
static fromSnapshot(snapshot: CardTrackerSnapshot): CardTracker {
|
||||
return new CardTracker(snapshot);
|
||||
}
|
||||
|
||||
toSnapshot(): CardTrackerSnapshot {
|
||||
return {
|
||||
playedCardIds: [...this.played],
|
||||
};
|
||||
}
|
||||
|
||||
restoreSnapshot(snapshot: CardTrackerSnapshot): void {
|
||||
const normalized = normalizeSnapshot(snapshot);
|
||||
this.played = new Set(normalized.playedCardIds);
|
||||
}
|
||||
|
||||
/** Record a card being played to the table */
|
||||
trackPlay(card: Card): void {
|
||||
this.played.add(card.id);
|
||||
|
||||
Reference in New Issue
Block a user