1
0
Fork 0
polaris-task-force/tests/int/poker-rank-style.int.spec.ts
Z8MB1E 1b0e4ed074 feat(poker): grade hand ranks on a progressive style ladder
Every made hand maps to a presentation tier from high card (no styling) through brass, silver, and gold pairs to a sapphire straight flush and a royal flush prismatic treatment. The live hand hint carries the tier, so the you-have placard glows with your hand's rank, and royals now read as royal flush.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-11 17:30:03 -04:00

66 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Card, HandRank } from "@/lib/minigames/poker";
import { handRankTier, ROYAL_RANK_TIER } from "@/lib/minigames/poker/handRankStyle";
import { describeHandStrength } from "@/lib/minigames/poker/handHint";
function rank(category: number, tiebreakers: readonly number[]): HandRank {
return { category, tiebreakers };
}
describe("handRankTier", () => {
it("maps every category to its own tier", () => {
expect(handRankTier(rank(0, [14]))).toBe(0);
expect(handRankTier(rank(1, [9]))).toBe(1);
expect(handRankTier(rank(2, [11, 4]))).toBe(2);
expect(handRankTier(rank(3, [7]))).toBe(3);
expect(handRankTier(rank(4, [9]))).toBe(4);
expect(handRankTier(rank(5, [14]))).toBe(5);
expect(handRankTier(rank(6, [13, 8]))).toBe(6);
expect(handRankTier(rank(7, [3]))).toBe(7);
expect(handRankTier(rank(8, [9]))).toBe(8);
});
it("promotes only the ace-high straight flush to the royal tier", () => {
expect(handRankTier(rank(8, [14]))).toBe(ROYAL_RANK_TIER);
expect(handRankTier(rank(8, [13]))).toBe(8);
expect(handRankTier(rank(4, [14]))).not.toBe(ROYAL_RANK_TIER);
});
});
describe("describeHandStrength tiers", () => {
it("keeps high card at tier zero and a pocket pair at tier one", () => {
const high = describeHandStrength(
[
{ rank: 14, suit: "s" },
{ rank: 13, suit: "h" },
],
[],
);
const pair = describeHandStrength(
[
{ rank: 9, suit: "s" },
{ rank: 9, suit: "h" },
],
[],
);
expect(high?.tier).toBe(0);
expect(pair?.tier).toBe(1);
});
it("grades a royal flush at the top tier with the royal label", () => {
const hole: Card[] = [
{ rank: 10, suit: "h" },
{ rank: 11, suit: "h" },
];
const board: Card[] = [
{ rank: 12, suit: "h" },
{ rank: 13, suit: "h" },
{ rank: 14, suit: "h" },
{ rank: 2, suit: "s" },
{ rank: 3, suit: "d" },
];
const hint = describeHandStrength(hole, board);
expect(hint?.tier).toBe(ROYAL_RANK_TIER);
expect(hint?.label).toBe("Royal flush");
});
});