Files
bridzik/frontend/src/lib/gameRules.ts
T

15 lines
479 B
TypeScript

import type { CardColor, Hand } from '../types';
export function computePlayable(hand: Hand, ledColor: CardColor | null): Set<string> {
const keys = Object.keys(hand);
if (!ledColor) return new Set(keys);
const ledKeys = keys.filter((k) => hand[k].color === ledColor);
if (ledKeys.length > 0) return new Set(ledKeys);
const heartKeys = keys.filter((k) => hand[k].color === 'HEARTS');
if (heartKeys.length > 0) return new Set(heartKeys);
return new Set(keys);
}