feat(SCOPONE-0005): iteration 4 — sort hand cards by suit then value

This commit is contained in:
Giancarmine Salucci
2026-03-31 23:01:15 +02:00
parent 2f58da8a63
commit c3a79b028b

View File

@@ -6,6 +6,14 @@ import {
import { chooseMove } from '../game/ai';
import { CardTracker } from '../game/card-tracker';
// ---------------------------------------------------------------------------
// Suit ordering for hand grouping
// ---------------------------------------------------------------------------
const SUIT_ORDER: Record<string, number> = { denara: 0, coppe: 1, bastoni: 2, spade: 3 };
function sortHand(hand: Card[]): void {
hand.sort((a, b) => (SUIT_ORDER[a.suit] - SUIT_ORDER[b.suit]) || (a.value - b.value));
}
// ---------------------------------------------------------------------------
// Layout constants
// ---------------------------------------------------------------------------
@@ -489,6 +497,7 @@ export class GameScene extends Phaser.Scene {
const allCards: Array<{ card: Card; p: number; destX: number; destY: number; face: boolean }> = [];
for (let p = 0; p < 4; p++) {
sortHand(this.state.players[p as PlayerIndex].hand);
const positions = this.getHandPositions(p as PlayerIndex,
this.state.players[p as PlayerIndex].hand.length);
this.state.players[p as PlayerIndex].hand.forEach((card, i) =>
@@ -911,6 +920,7 @@ export class GameScene extends Phaser.Scene {
private relayoutHand(playerIdx: PlayerIndex): void {
const hand = this.state.players[playerIdx].hand;
sortHand(hand);
const positions = this.getHandPositions(playerIdx, hand.length);
hand.forEach((card, i) => {
const img = this.cardImages.get(card.id);