forked from WikiDeck/wikideck
Engine: trendDown -200 default; nullable loaner pageId counts copies per cardId (DESIGN #23/#24)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ type Action =
|
|||||||
```ts
|
```ts
|
||||||
interface GameCard {
|
interface GameCard {
|
||||||
cardId: string; // unique within a deck: the NFT card hash, or `loaner:<pageId>:<n>`
|
cardId: string; // unique within a deck: the NFT card hash, or `loaner:<pageId>:<n>`
|
||||||
pageId: number; // at most ruleset.maxCopiesPerPage cards share a pageId
|
pageId: number | null; // at most maxCopiesPerPage cards share a pageId; null (unpinned loaners) → counted per cardId
|
||||||
title: string;
|
title: string;
|
||||||
faction: 'Space' | 'Nature' | 'People' | 'Science' | 'History' | 'Culture';
|
faction: 'Space' | 'Nature' | 'People' | 'Science' | 'History' | 'Culture';
|
||||||
rarity: 'Common' | 'Rare' | 'Epic' | 'Legendary'; // cosmetic in v1
|
rarity: 'Common' | 'Rare' | 'Epic' | 'Legendary'; // cosmetic in v1
|
||||||
|
|||||||
@@ -29,14 +29,15 @@ export function validateDeck(rules: Ruleset, deck: readonly GameCard[]): string[
|
|||||||
if (!Array.isArray(deck)) return ['Deck must be an array'];
|
if (!Array.isArray(deck)) return ['Deck must be an array'];
|
||||||
if (deck.length !== rules.deckSize) problems.push(`Deck must have exactly ${rules.deckSize} cards (has ${deck.length})`);
|
if (deck.length !== rules.deckSize) problems.push(`Deck must have exactly ${rules.deckSize} cards (has ${deck.length})`);
|
||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
const copies = new Map<number, number>();
|
const copies = new Map<string, number>();
|
||||||
let loaners = 0;
|
let loaners = 0;
|
||||||
for (const card of deck) {
|
for (const card of deck) {
|
||||||
if (typeof card?.cardId !== 'string' || !card.cardId || card.cardId.length > 128) { problems.push('cardId must be a non-empty string'); continue; }
|
if (typeof card?.cardId !== 'string' || !card.cardId || card.cardId.length > 128) { problems.push('cardId must be a non-empty string'); continue; }
|
||||||
const label = card.cardId;
|
const label = card.cardId;
|
||||||
if (ids.has(card.cardId)) problems.push(`Duplicate cardId ${label}`);
|
if (ids.has(card.cardId)) problems.push(`Duplicate cardId ${label}`);
|
||||||
ids.add(card.cardId);
|
ids.add(card.cardId);
|
||||||
if (!Number.isInteger(card.pageId)) problems.push(`${label}: bad pageId`);
|
if (card.pageId !== null && !Number.isInteger(card.pageId)) problems.push(`${label}: bad pageId`);
|
||||||
|
if (card.pageId === null && card.source !== 'loaner') problems.push(`${label}: owned cards need a pageId`);
|
||||||
if (typeof card.title !== 'string' || card.title.length > 256) problems.push(`${label}: bad title`);
|
if (typeof card.title !== 'string' || card.title.length > 256) problems.push(`${label}: bad title`);
|
||||||
if (!FACTION_SET.has(card.faction)) problems.push(`${label}: bad faction`);
|
if (!FACTION_SET.has(card.faction)) problems.push(`${label}: bad faction`);
|
||||||
if (!RARITIES.has(card.rarity)) problems.push(`${label}: bad rarity`);
|
if (!RARITIES.has(card.rarity)) problems.push(`${label}: bad rarity`);
|
||||||
@@ -49,9 +50,11 @@ export function validateDeck(rules: Ruleset, deck: readonly GameCard[]): string[
|
|||||||
if (card.check !== undefined && !CHECKS.has(card.check)) problems.push(`${label}: bad check`);
|
if (card.check !== undefined && !CHECKS.has(card.check)) problems.push(`${label}: bad check`);
|
||||||
if (card.source === 'loaner') loaners++;
|
if (card.source === 'loaner') loaners++;
|
||||||
if (card.source === 'owned' && !rules.ownedCards) problems.push(`${label}: owned cards are not allowed in this mode`);
|
if (card.source === 'owned' && !rules.ownedCards) problems.push(`${label}: owned cards are not allowed in this mode`);
|
||||||
const n = (copies.get(card.pageId) ?? 0) + 1;
|
// §2 / §2.1: owned and loaner copies count together by pageId; unpinned loaners (pageId null) by cardId.
|
||||||
copies.set(card.pageId, n);
|
const key = card.pageId !== null ? `page:${card.pageId}` : `card:${card.cardId}`;
|
||||||
if (n === rules.maxCopiesPerPage + 1) problems.push(`More than ${rules.maxCopiesPerPage} copies of page ${card.pageId}`);
|
const n = (copies.get(key) ?? 0) + 1;
|
||||||
|
copies.set(key, n);
|
||||||
|
if (n === rules.maxCopiesPerPage + 1) problems.push(`More than ${rules.maxCopiesPerPage} copies of ${card.pageId !== null ? `page ${card.pageId}` : card.cardId}`);
|
||||||
}
|
}
|
||||||
if (loaners > rules.maxLoaners) problems.push(`At most ${rules.maxLoaners} loaner cards`);
|
if (loaners > rules.maxLoaners) problems.push(`At most ${rules.maxLoaners} loaner cards`);
|
||||||
return problems;
|
return problems;
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export const DEFAULT_RULESET: Ruleset = {
|
|||||||
powerByCost: [0, 1, 2, 4, 6, 8, 10],
|
powerByCost: [0, 1, 2, 4, 6, 8, 10],
|
||||||
onTopicBonus: [0, 1, 1, 2, 2, 3, 3], vanillaBonus: 1,
|
onTopicBonus: [0, 1, 1, 2, 2, 3, 3], vanillaBonus: 1,
|
||||||
keywordsEnabled: ['viral', 'rising', 'local', 'encyclopedic', 'nostalgic', 'translated'], ownedCards: true,
|
keywordsEnabled: ['viral', 'rising', 'local', 'encyclopedic', 'nostalgic', 'translated'], ownedCards: true,
|
||||||
trendUp: 25, trendDown: -25, trendMinDaily: 20, uncheckedCostCap: 4,
|
trendUp: 25, trendDown: -200, trendMinDaily: 20, uncheckedCostCap: 4,
|
||||||
factionSynergyCap: 3,
|
factionSynergyCap: 3,
|
||||||
verifyStats: true,
|
verifyStats: true,
|
||||||
percentiles: 'card-sample-2026-11-16',
|
percentiles: 'card-sample-2026-11-16',
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ export type Rarity = 'Common' | 'Rare' | 'Epic' | 'Legendary';
|
|||||||
export interface GameCard {
|
export interface GameCard {
|
||||||
/** Unique within one deck (the NFT card hash, or `loaner:<pageId>:<n>`). */
|
/** Unique within one deck (the NFT card hash, or `loaner:<pageId>:<n>`). */
|
||||||
cardId: string;
|
cardId: string;
|
||||||
pageId: number;
|
/** null for unpinned loaners (DESIGN §2.1): copies then count per cardId. */
|
||||||
|
pageId: number | null;
|
||||||
title: string;
|
title: string;
|
||||||
faction: Faction;
|
faction: Faction;
|
||||||
/** Cosmetic in v1 (§1.7). */
|
/** Cosmetic in v1 (§1.7). */
|
||||||
|
|||||||
Reference in New Issue
Block a user