Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/games/asli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,33 +709,27 @@ export class AsliGame extends GameBase {
}
pstr += pieces.join("");
}
// pstr = pstr.replace(/-{4}/g, "_");

const hasPrison = this.prison.reduce((prev, curr) => prev + curr, 0) > 0;
const hasPrison = this.prison[0] > 0 || this.prison[1] > 0;
const prisonPiece: Glyph[] = [];
prisonPiece.push({
name: hasPrison ? "piece" : "piece-borderless",
colour: this.getPrisonColour(swapPrison),
scale: 0.85
});
if (hasPrison) {
prisonPiece.push({
name: "piece",
colour: this.prison[0] > 0 ? this.getPlayerColour(swapPrison ? 2 : 1) : this.getPlayerColour(swapPrison ? 1 : 2),
scale: 0.85,
});
prisonPiece.push({
text: this.prison[0] > 0 ? this.prison[0].toString() : this.prison[1].toString(),
colour: {
func: "bestContrast",
fg: ["_context_background", "_context_fill", "_context_label"],
bg: this.prison[0] > 0 ? this.getPlayerColour(swapPrison ? 2 : 1) : this.getPlayerColour(swapPrison ? 1 : 2),
bg: this.getPrisonColour(swapPrison)
},
scale: 0.75,
rotate: null,
});
} else {
prisonPiece.push({
name: "piece-borderless",
colour: "_context_background",
scale: 0.85,
rotate: null
});
}

// Build rep
const rep: APRenderRep = {
board: {
Expand Down Expand Up @@ -868,6 +862,20 @@ export class AsliGame extends GameBase {
}
}

public getPrisonColour(swapPrison: boolean): number|string {
if (this.prison[0] === 0 && this.prison[1] === 0) {
return "_context_background";
}
let swap = swapPrison;
if (this.stack.length > 2 && this.stack[2].lastmove !== "pass") {
swap = !swap;
}
if (this.prison[1] > 0) {
swap = !swap;
}
return swap ? 2 : 1;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public serialize(opts?: {strip?: boolean, player?: number}): string {
const json = JSON.stringify(this.state(), replacer);
Expand Down