forked from WikiDeck/wikideck
story: tokens (never cited) and drawn matches, for duel-core's LogEvent shape
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,11 +47,12 @@ export class Narrator {
|
|||||||
|
|
||||||
player(seat: Seat): string { return this.record.players[seat].name; }
|
player(seat: Seat): string { return this.record.players[seat].name; }
|
||||||
|
|
||||||
/** Assigns a reference number without mentioning the card (e.g. for the References list). */
|
/** Assigns a reference number without mentioning the card (e.g. for the References list). Tokens get none (0). */
|
||||||
cite(id: string): number {
|
cite(id: string): number {
|
||||||
let n = this.refByCard.get(id);
|
let n = this.refByCard.get(id);
|
||||||
if (n === undefined) {
|
if (n === undefined) {
|
||||||
const c = this.card(id);
|
const c = this.card(id);
|
||||||
|
if (c.token || c.revisionId === undefined) return 0;
|
||||||
n = this.references.length + 1;
|
n = this.references.length + 1;
|
||||||
this.refByCard.set(id, n);
|
this.refByCard.set(id, n);
|
||||||
this.references.push({
|
this.references.push({
|
||||||
@@ -66,6 +67,7 @@ export class Narrator {
|
|||||||
/** A card's name for a sentence: italic, with its description on first mention. */
|
/** A card's name for a sentence: italic, with its description on first mention. */
|
||||||
mention(id: string): string {
|
mention(id: string): string {
|
||||||
const c = this.card(id);
|
const c = this.card(id);
|
||||||
|
if (c.token || c.revisionId === undefined) return c.title;
|
||||||
const first = !this.refByCard.has(id);
|
const first = !this.refByCard.has(id);
|
||||||
const n = this.cite(id);
|
const n = this.cite(id);
|
||||||
if (!first) return `*${c.title}*`;
|
if (!first) return `*${c.title}*`;
|
||||||
@@ -157,6 +159,7 @@ export function renderEvent(nar: Narrator, ev: StoryEvent, index: number, viewer
|
|||||||
case 'rivalry':
|
case 'rivalry':
|
||||||
return nar.sentence('rivalry', index, { a: M(ev.a), b: M(ev.b), reason: () => ev.reason });
|
return nar.sentence('rivalry', index, { a: M(ev.a), b: M(ev.b), reason: () => ev.reason });
|
||||||
case 'gameOver': {
|
case 'gameOver': {
|
||||||
|
if (ev.winner === null) return nar.sentence('gameOverDraw', index, { turn: N(ev.turn) });
|
||||||
const key = ({ life: 'gameOverLife', library: 'gameOverLibrary', concede: 'gameOverConcede', timeout: 'gameOverTimeout', turnCap: 'gameOverTurnCap' } as const)[ev.reason];
|
const key = ({ life: 'gameOverLife', library: 'gameOverLibrary', concede: 'gameOverConcede', timeout: 'gameOverTimeout', turnCap: 'gameOverTurnCap' } as const)[ev.reason];
|
||||||
return nar.sentence(key, index, { winner: P(ev.winner), loser: P(other(ev.winner)), turn: N(ev.turn) });
|
return nar.sentence(key, index, { winner: P(ev.winner), loser: P(other(ev.winner)), turn: N(ev.turn) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ export function longDate(iso: string): string {
|
|||||||
interface Played { id: string; seat: Seat; order: number }
|
interface Played { id: string; seat: Seat; order: number }
|
||||||
|
|
||||||
interface Facts {
|
interface Facts {
|
||||||
|
/** For a draw: seat 0, with `draw` set. */
|
||||||
winner: Seat;
|
winner: Seat;
|
||||||
|
draw: boolean;
|
||||||
loser: Seat;
|
loser: Seat;
|
||||||
reason: GameOverReason;
|
reason: GameOverReason;
|
||||||
turns: number;
|
turns: number;
|
||||||
@@ -72,7 +74,8 @@ function facts(record: MatchRecord): Facts {
|
|||||||
if (e.kind === 'adopt') played.push({ id: e.doctrine, seat: e.seat, order: i });
|
if (e.kind === 'adopt') played.push({ id: e.doctrine, seat: e.seat, order: i });
|
||||||
if (e.kind === 'destroyed') destroyed.push(e.card);
|
if (e.kind === 'destroyed') destroyed.push(e.card);
|
||||||
});
|
});
|
||||||
return { winner: over.winner, loser: over.winner === 0 ? 1 : 0, reason: over.reason, turns: over.turn, life, played, destroyed };
|
const winner: Seat = over.winner ?? 0;
|
||||||
|
return { winner, draw: over.winner === null, loser: winner === 0 ? 1 : 0, reason: over.reason, turns: over.turn, life, played, destroyed };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Highest cost wins; ties go to the card played first. */
|
/** Highest cost wins; ties go to the card played first. */
|
||||||
@@ -104,6 +107,7 @@ export function battleTitle(record: MatchRecord, f: Facts = facts(record)): stri
|
|||||||
|
|
||||||
function resultText(record: MatchRecord, f: Facts): string {
|
function resultText(record: MatchRecord, f: Facts): string {
|
||||||
const w = record.players[f.winner].name;
|
const w = record.players[f.winner].name;
|
||||||
|
if (f.draw) return 'Inconclusive';
|
||||||
switch (f.reason) {
|
switch (f.reason) {
|
||||||
case 'concede': case 'timeout': return `${w} victory by withdrawal`;
|
case 'concede': case 'timeout': return `${w} victory by withdrawal`;
|
||||||
case 'library': return `${w} victory by attrition`;
|
case 'library': return `${w} victory by attrition`;
|
||||||
@@ -138,6 +142,7 @@ function sub(t: string, v: Record<string, string | number>): string {
|
|||||||
/** The result as a phrase for the lead: "a Pyrrhic victory for bob". */
|
/** The result as a phrase for the lead: "a Pyrrhic victory for bob". */
|
||||||
function resultPhrase(record: MatchRecord, f: Facts): string {
|
function resultPhrase(record: MatchRecord, f: Facts): string {
|
||||||
const w = record.players[f.winner].name;
|
const w = record.players[f.winner].name;
|
||||||
|
if (f.draw) return 'a draw';
|
||||||
switch (f.reason) {
|
switch (f.reason) {
|
||||||
case 'concede': case 'timeout': return `a victory for ${w} by withdrawal`;
|
case 'concede': case 'timeout': return `a victory for ${w} by withdrawal`;
|
||||||
case 'library': return `a victory for ${w} by attrition`;
|
case 'library': return `a victory for ${w} by attrition`;
|
||||||
@@ -216,8 +221,9 @@ export function recap(record: MatchRecord): RecapDoc {
|
|||||||
if (end) course.push(end.text);
|
if (end) course.push(end.text);
|
||||||
|
|
||||||
// Aftermath.
|
// Aftermath.
|
||||||
const aftermath = [
|
const aftermath = [f.draw
|
||||||
`${record.players[f.winner].name} ended the engagement with ${f.life[f.winner]} Notability; ${record.players[f.loser].name} ended with ${f.life[f.loser]}.`,
|
? `Both ${a} and ${b} ended the engagement with ${f.life[0]} Notability.`
|
||||||
|
: `${record.players[f.winner].name} ended the engagement with ${f.life[f.winner]} Notability; ${record.players[f.loser].name} ended with ${f.life[f.loser]}.`,
|
||||||
];
|
];
|
||||||
if (record.ratingChange) {
|
if (record.ratingChange) {
|
||||||
const fmt = (n: number) => (n >= 0 ? `+${n}` : `${n}`);
|
const fmt = (n: number) => (n >= 0 ? `+${n}` : `${n}`);
|
||||||
|
|||||||
@@ -91,6 +91,11 @@ export const LOG_TEMPLATES = {
|
|||||||
'{loser} was reduced to 0 Notability. {winner} won.',
|
'{loser} was reduced to 0 Notability. {winner} won.',
|
||||||
'{winner} won on turn {turn}.',
|
'{winner} won on turn {turn}.',
|
||||||
],
|
],
|
||||||
|
gameOverDraw: [
|
||||||
|
'Both sides were reduced to 0 Notability. The engagement ended in a draw.',
|
||||||
|
'The engagement ended in a draw on turn {turn}.',
|
||||||
|
'Neither side retained any Notability. No winner was recorded.',
|
||||||
|
],
|
||||||
gameOverLibrary: [
|
gameOverLibrary: [
|
||||||
'{loser} could not draw a card and lost.',
|
'{loser} could not draw a card and lost.',
|
||||||
'{loser} ran out of cards. {winner} won.',
|
'{loser} ran out of cards. {winner} won.',
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ export interface StoryCard {
|
|||||||
cost: number;
|
cost: number;
|
||||||
/** Portal (faction): Arts, Earth, History, Science, Society or Neutral. */
|
/** Portal (faction): Arts, Earth, History, Science, Society or Neutral. */
|
||||||
portal?: string;
|
portal?: string;
|
||||||
/** The article revision the card was minted from (on-chain). */
|
/** The article revision the card was minted from (on-chain). Absent for tokens: they are never cited. */
|
||||||
revisionId: number;
|
revisionId?: number;
|
||||||
|
/** Tokens (Elected Member, Staff Member): generic, not articles, never cited or glossed. */
|
||||||
|
token?: boolean;
|
||||||
/** On-chain token id of the mint, if known. */
|
/** On-chain token id of the mint, if known. */
|
||||||
tokenId?: string;
|
tokenId?: string;
|
||||||
/** Seat that owns the card in this match. */
|
/** Seat that owns the card in this match. */
|
||||||
@@ -47,7 +49,8 @@ export type StoryEvent =
|
|||||||
| { kind: 'discard'; seat: Seat; card: string }
|
| { kind: 'discard'; seat: Seat; card: string }
|
||||||
| { kind: 'connected'; seat: Seat; a: string; b: string; reason: string }
|
| { kind: 'connected'; seat: Seat; a: string; b: string; reason: string }
|
||||||
| { kind: 'rivalry'; a: string; b: string; reason: string }
|
| { kind: 'rivalry'; a: string; b: string; reason: string }
|
||||||
| { kind: 'gameOver'; winner: Seat; reason: GameOverReason; turn: number };
|
/** winner null = draw (both players reached 0 at once). */
|
||||||
|
| { kind: 'gameOver'; winner: Seat | null; reason: GameOverReason; turn: number };
|
||||||
|
|
||||||
export interface StoryPlayer {
|
export interface StoryPlayer {
|
||||||
/** Display name of the seat (account display name or "Bot (Normal)"). */
|
/** Display name of the seat (account display name or "Bot (Normal)"). */
|
||||||
|
|||||||
@@ -216,3 +216,26 @@ test('golden: full log and recap prose match tests/duel-design-story.golden.json
|
|||||||
const r = recap(record);
|
const r = recap(record);
|
||||||
assert.deepEqual({ log: logParagraphs(renderLog(record).lines), lead: r.lead, sections: r.sections }, golden);
|
assert.deepEqual({ log: logParagraphs(renderLog(record).lines), lead: r.lead, sections: r.sections }, golden);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tokens are named plainly and never cited; draws are recorded as inconclusive', () => {
|
||||||
|
const withToken: MatchRecord = {
|
||||||
|
...record,
|
||||||
|
cards: { ...cards, 't:1': { id: 't:1', title: 'Elected Member', type: 'Figure', cost: 0, portal: 'Society', owner: 1, token: true } },
|
||||||
|
events: [
|
||||||
|
T(1), { kind: 'cast', seat: 1, card: 'b1' },
|
||||||
|
{ kind: 'tokenCreated', seat: 1, source: 'b1', token: 'Elected Member', count: 1 },
|
||||||
|
T(2), { kind: 'attack', seat: 1, card: 't:1', power: 1, toughness: 1 },
|
||||||
|
{ kind: 'playerDamage', seat: 0, source: 't:1', amount: 20, life: 0 },
|
||||||
|
{ kind: 'playerDamage', seat: 1, amount: 20, life: 0 },
|
||||||
|
{ kind: 'gameOver', winner: null, reason: 'life', turn: 2 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const { lines, references } = renderLog(withToken);
|
||||||
|
assert.ok(lines.some(l => /Elected Member \(1\/1\)/.test(l.text) && !/\*Elected Member\*/.test(l.text)));
|
||||||
|
assert.deepEqual(references.map(r => r.title), ['1954 Gold Coast general election']);
|
||||||
|
assert.match(lines[lines.length - 1].text, /draw|No winner/);
|
||||||
|
const r = recap(withToken);
|
||||||
|
assert.equal(r.infobox.result, 'Inconclusive');
|
||||||
|
assert.match(r.lead, /ended in a draw\./);
|
||||||
|
assert.ok(r.references.every(x => x.revisionId !== undefined));
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user