From 48dc415f33986b9e6f6b417ede53c23eda15d94e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 24 Sep 2026 12:21:50 +0000 Subject: [PATCH] Arimaa: show the Harlog leader as a coloured piece instead of a sign The Harlog status row now shows an unsigned value preceded by a `piece` glyph in the leading player's colour (Gold when positive, Silver when negative). The glyph is omitted when the value displays as all zeros, which also avoids showing "-0.00" for balanced material, and when the value is NaN. Infinite values keep the leader's glyph. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AVSKZLA5aG9G2pNxSnTrHG --- src/games/arimaa.ts | 10 ++++++++- test/games/arimaa.test.ts | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/games/arimaa.ts b/src/games/arimaa.ts index a37de9ed..e62688e6 100644 --- a/src/games/arimaa.ts +++ b/src/games/arimaa.ts @@ -1800,7 +1800,15 @@ export class ArimaaGame extends GameBase { } public sidebarStatuses(): IStatus[] { - return [{ key: this.neutralAreaLabel("apgames:status.arimaa.HARLOG"), value: [this.harlog().toFixed(2)] } as IStatus]; + const key = this.neutralAreaLabel("apgames:status.arimaa.HARLOG"); + const harlog = this.harlog(); + const magnitude = Math.abs(harlog).toFixed(2); + // The glyph's colour stands in for the sign, so omit it when the displayed value is all zeros + if (Number.isNaN(harlog) || Number(magnitude) === 0) { + return [{ key, value: [magnitude] }]; + } + const glyph = { glyph: "piece", colour: this.getPlayerColour(harlog > 0 ? 1 : 2) }; + return [{ key, value: [glyph, magnitude] }]; } diff --git a/test/games/arimaa.test.ts b/test/games/arimaa.test.ts index d8e79eee..0081fa0d 100644 --- a/test/games/arimaa.test.ts +++ b/test/games/arimaa.test.ts @@ -222,6 +222,50 @@ describe("Arimaa", () => { expect(result.valid).to.be.true; expect(result.complete).to.equal(1); }); + + it ("Harlog status shows the leader's colour instead of a sign", () => { + // balanced material: no glyph + let g = new ArimaaGame(undefined, ["free"]); + g.move("Ed2,Rd3"); + g.move("ed7,rd6"); + let [status] = g.sidebarStatuses(); + expect(status.value).to.deep.equal(["0.00"]); + + // nonzero but displayed as all zeros: no glyph, no sign + g.harlog = () => -0.004; + [status] = g.sidebarStatuses(); + expect(status.value).to.deep.equal(["0.00"]); + + // gold ahead + g = new ArimaaGame(undefined, ["free"]); + g.move("Ed2,Mg2,Rd3"); + g.move("ed7,rd6"); + [status] = g.sidebarStatuses(); + expect(g.harlog()).to.be.greaterThan(0); + expect(status.value).to.deep.equal([ + { glyph: "piece", colour: g.getPlayerColour(1) }, + g.harlog().toFixed(2), + ]); + + // silver ahead: the number is unsigned + g = new ArimaaGame(undefined, ["free"]); + g.move("Ed2,Rd3"); + g.move("ed7,mg7,rd6"); + [status] = g.sidebarStatuses(); + expect(g.harlog()).to.be.lessThan(0); + expect(status.value).to.deep.equal([ + { glyph: "piece", colour: g.getPlayerColour(2) }, + Math.abs(g.harlog()).toFixed(2), + ]); + + // infinite values keep the leader's glyph; NaN has no leader + g.harlog = () => Infinity; + expect(g.sidebarStatuses()[0].value).to.deep.equal([{ glyph: "piece", colour: g.getPlayerColour(1) }, "Infinity"]); + g.harlog = () => -Infinity; + expect(g.sidebarStatuses()[0].value).to.deep.equal([{ glyph: "piece", colour: g.getPlayerColour(2) }, "Infinity"]); + g.harlog = () => NaN; + expect(g.sidebarStatuses()[0].value).to.deep.equal(["NaN"]); + }); });