feat(SCOPONE-0005): iteration 4 — sort hand cards by suit then value
This commit is contained in:
@@ -6,6 +6,14 @@ import {
|
|||||||
import { chooseMove } from '../game/ai';
|
import { chooseMove } from '../game/ai';
|
||||||
import { CardTracker } from '../game/card-tracker';
|
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
|
// 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 }> = [];
|
const allCards: Array<{ card: Card; p: number; destX: number; destY: number; face: boolean }> = [];
|
||||||
|
|
||||||
for (let p = 0; p < 4; p++) {
|
for (let p = 0; p < 4; p++) {
|
||||||
|
sortHand(this.state.players[p as PlayerIndex].hand);
|
||||||
const positions = this.getHandPositions(p as PlayerIndex,
|
const positions = this.getHandPositions(p as PlayerIndex,
|
||||||
this.state.players[p as PlayerIndex].hand.length);
|
this.state.players[p as PlayerIndex].hand.length);
|
||||||
this.state.players[p as PlayerIndex].hand.forEach((card, i) =>
|
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 {
|
private relayoutHand(playerIdx: PlayerIndex): void {
|
||||||
const hand = this.state.players[playerIdx].hand;
|
const hand = this.state.players[playerIdx].hand;
|
||||||
|
sortHand(hand);
|
||||||
const positions = this.getHandPositions(playerIdx, hand.length);
|
const positions = this.getHandPositions(playerIdx, hand.length);
|
||||||
hand.forEach((card, i) => {
|
hand.forEach((card, i) => {
|
||||||
const img = this.cardImages.get(card.id);
|
const img = this.cardImages.get(card.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user