Skip to content

Commit b0d705f

Browse files
committed
Interim moves are now annotated correctly in all games.
1 parent df6de45 commit b0d705f

File tree

10 files changed

+53
-43
lines changed

10 files changed

+53
-43
lines changed

TODO

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
✘ The AI appears to be broken at even plies, and does not always do what is expected. Need to evaluate whether this is the fault of the library, the game code, or some combination of both. @cancelled(21-12-10 07:50)
33
✔ Make game descriptions translatable. We could remove the embedded heading and just leave the styling to the front end. Just have the blurb, all on one line or with encoded newlines, and only basic Markdown? @done(21-12-10 07:51)
44
✔ Apparently rotating the board disables the click handlers. Figure that out. @done(21-12-10 07:50)
5+
✔ Fix Amazons partial rendering (annotations missing). While I'm at it, triple check there are no other games using this old way of annotating. @done(21-12-10 08:44)
6+
57
- It's also possible to have the API server generate the reports and just request specific pieces of information from game code. Because I'm the one working on the game and RecRanks code and not the API server, I put the code here. Reconsider in the future.
68

79
- Blam!: Implement variant "Overloaded"
810
- Entropy: Player-specific rendering
911
- Entropy: Remaining pieces added to render
12+
- Chase: Find a simple way to resolve ambiguous moves in Chase via clicks. Thankfully they are rare.
1013

1114
- List of SDG games still to migrate: acity, archimedes, complica, fanorona, focus, frames, garden, mirador, phutball, qy, realm, reaper, scribe, soccer, strings, wyke. This is based on looking at games in the top quartile of "most played of all time," games played recently, and game ratings by players. Grand total is 34 games (18 already coded, 16 in the queue). Nothing is guaranteed. A nomination process will be instituted at some point.
1215

13-
- Fix Amazons partial rendering (annotations missing). While I'm at it, triple check there are no other games using this old way of annotating.
14-
- Click handling: Find a simple way to resolve ambiguous moves in Chase. Thankfully they are rare.

src/games/accasta.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class AccastaGame extends GameBase {
143143
this.currplayer = state.currplayer;
144144
this.board = deepclone(state.board) as Map<string, CellContents[]>;
145145
this.lastmove = state.lastmove;
146+
this.results = [...state._results];
146147
return this;
147148
}
148149

@@ -775,10 +776,12 @@ export class AccastaGame extends GameBase {
775776
}
776777

777778
// Add annotations
778-
if (this.stack[this.stack.length - 1]._results.length > 0) {
779+
// if (this.stack[this.stack.length - 1]._results.length > 0) {
780+
if (this.results.length > 0) {
779781
// @ts-ignore
780782
rep.annotations = [];
781-
for (const move of this.stack[this.stack.length - 1]._results) {
783+
// for (const move of this.stack[this.stack.length - 1]._results) {
784+
for (const move of this.results) {
782785
if (move.type === "move") {
783786
const [fromX, fromY] = this.graph.algebraic2coords(move.from);
784787
const [toX, toY] = this.graph.algebraic2coords(move.to);

src/games/amazons.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -588,31 +588,28 @@ export class AmazonsGame extends GameBase {
588588
};
589589

590590
// Add annotations
591-
if (this.lastmove !== undefined) {
592-
const cells: string[] = this.lastmove.split(new RegExp('[\-\/]'));
593-
if (cells.length !== 3) {
594-
throw new Error(`Malformed last move: ${this.lastmove}`);
595-
}
596-
const [xFrom, yFrom] = AmazonsGame.algebraic2coords(cells[0]);
597-
const [xTo, yTo] = AmazonsGame.algebraic2coords(cells[1]);
598-
const [xArrow, yArrow] = AmazonsGame.algebraic2coords(cells[2]);
599-
rep.annotations = [
600-
{
601-
type: "move",
602-
targets: [
603-
{col: xTo, row: yTo},
604-
{col: xArrow, row: yArrow}
605-
],
606-
style: "dashed"
607-
},
608-
{
609-
type: "move",
610-
targets: [
611-
{col: xFrom, row: yFrom},
612-
{col: xTo, row: yTo}
613-
]
591+
if (this.results.length > 0) {
592+
// @ts-ignore
593+
rep.annotations = [];
594+
let fromX: number|undefined; let fromY: number|undefined;
595+
let toX: number|undefined; let toY: number|undefined;
596+
let xArrow: number|undefined; let yArrow: number|undefined;
597+
598+
for (const move of this.results) {
599+
if (move.type === "move") {
600+
[fromX, fromY] = AmazonsGame.algebraic2coords(move.from);
601+
[toX, toY] = AmazonsGame.algebraic2coords(move.to);
602+
} else if (move.type === "block") {
603+
[xArrow, yArrow] = AmazonsGame.algebraic2coords(move.where!);
614604
}
615-
];
605+
}
606+
607+
if ( (fromX !== undefined) && (fromY !== undefined) && (toX !== undefined) && (toY !== undefined) ) {
608+
rep.annotations.push({type: "move", targets: [{row: fromY, col: fromX}, {row: toY, col: toX}]});
609+
if ( (xArrow !== undefined) && (yArrow !== undefined) ) {
610+
rep.annotations.push({type: "move", style: "dashed", targets: [{row: toY, col: toX}, {row: yArrow, col: xArrow}]});
611+
}
612+
}
616613
}
617614

618615
return rep;

src/games/ceph.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class CephalopodGame extends GameBase {
104104
this.currplayer = state.currplayer;
105105
this.board = new Map(state.board);
106106
this.lastmove = state.lastmove;
107+
this.results = [...state._results];
107108
this.buildGraph();
108109
return this;
109110
}
@@ -549,10 +550,10 @@ export class CephalopodGame extends GameBase {
549550
};
550551

551552
// Add annotations
552-
if (this.stack[this.stack.length - 1]._results.length > 0) {
553+
if (this.results.length > 0) {
553554
// @ts-ignore
554555
rep.annotations = [];
555-
for (const move of this.stack[this.stack.length - 1]._results) {
556+
for (const move of this.results) {
556557
if (move.type === "capture") {
557558
const [x, y] = this.graph.algebraic2coords(move.where!);
558559
rep.annotations.push({type: "exit", targets: [{row: y, col: x}]});

src/games/chase.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ export class ChaseGame extends GameBase {
566566
prevspeed++;
567567
if (prevspeed > 6) {
568568
prevspeed = totalspeed - 6;
569+
} else if (prevspeed >= totalspeed) {
570+
prevspeed = 1;
569571
}
570572
thisspeed = totalspeed - prevspeed;
571573
newmove = `${balance}${prevcell}=${prevspeed},${cell}=${thisspeed}`;
@@ -585,13 +587,17 @@ export class ChaseGame extends GameBase {
585587
lSpeed++;
586588
if (lSpeed > 6) {
587589
lSpeed = totalspeed - 6;
590+
} else if (lSpeed >= totalspeed) {
591+
lSpeed = 1;
588592
}
589593
rSpeed = totalspeed - lSpeed;
590594
newmove = `${balance}${lCell}=${lSpeed},${rCell}=${rSpeed}`;
591595
} else if (cell === rCell) {
592596
rSpeed++;
593597
if (rSpeed > 6) {
594598
rSpeed = totalspeed - 6;
599+
} else if (rSpeed >= totalspeed) {
600+
rSpeed = 1;
595601
}
596602
lSpeed = totalspeed - rSpeed;
597603
newmove = `${balance}${lCell}=${lSpeed},${rCell}=${rSpeed}`;
@@ -1227,10 +1233,10 @@ export class ChaseGame extends GameBase {
12271233
};
12281234

12291235
// Add annotations
1230-
if (this.stack[this.stack.length - 1]._results.length > 0) {
1236+
if (this.results.length > 0) {
12311237
// @ts-ignore
12321238
rep.annotations = [];
1233-
for (const move of this.stack[this.stack.length - 1]._results) {
1239+
for (const move of this.results) {
12341240
if (move.type === "move") {
12351241
const [fromX, fromY] = ChaseGame.algebraic2coords(move.from);
12361242
const [toX, toY] = ChaseGame.algebraic2coords(move.to);

src/games/fabrik.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export class FabrikGame extends GameBase {
113113
this.currplayer = state.currplayer;
114114
this.board = new Map(state.board);
115115
this.lastmove = state.lastmove;
116+
this.results = [...state._results];
116117
return this;
117118
}
118119

@@ -683,10 +684,10 @@ export class FabrikGame extends GameBase {
683684
}
684685

685686
// Add annotations
686-
if (this.stack[this.stack.length - 1]._results.length > 0) {
687+
if (this.results.length > 0) {
687688
// @ts-ignore
688689
rep.annotations = [];
689-
for (const move of this.stack[this.stack.length - 1]._results) {
690+
for (const move of this.results) {
690691
if (move.type === "move") {
691692
const [fromX, fromY] = FabrikGame.algebraic2coords(move.from);
692693
const [toX, toY] = FabrikGame.algebraic2coords(move.to);

src/games/fendo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class FendoGame extends GameBase {
107107
this.lastmove = state.lastmove;
108108
this.pieces = [...state.pieces];
109109
this.fences = clonelst(state.fences) as [string, string][];
110+
this.results = [...state._results];
110111
this.buildGraph();
111112
return this;
112113
}
@@ -756,10 +757,10 @@ export class FendoGame extends GameBase {
756757
};
757758

758759
// Add annotations
759-
if (this.stack[this.stack.length - 1]._results.length > 0) {
760+
if (this.results.length > 0) {
760761
// @ts-ignore
761762
rep.annotations = [];
762-
for (const move of this.stack[this.stack.length - 1]._results) {
763+
for (const move of this.results) {
763764
if (move.type === "move") {
764765
const [fromX, fromY] = this.graph.algebraic2coords(move.from);
765766
const [toX, toY] = this.graph.algebraic2coords(move.to);

src/games/loa.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class LinesOfActionGame extends GameBase {
114114
this.currplayer = state.currplayer;
115115
this.board = new Map(state.board);
116116
this.lastmove = state.lastmove;
117+
this.results = [...state._results];
117118
return this;
118119
}
119120

@@ -530,7 +531,7 @@ export class LinesOfActionGame extends GameBase {
530531
};
531532

532533
// Add annotations
533-
if ( (this.stack[this.stack.length - 1]._results.length > 0) || (this._points.length > 0) ){
534+
if ( (this.results.length > 0) || (this._points.length > 0) ){
534535
// @ts-ignore
535536
rep.annotations = [];
536537

@@ -543,7 +544,7 @@ export class LinesOfActionGame extends GameBase {
543544
rep.annotations.push({type: "dots", targets: points});
544545
}
545546

546-
for (const move of this.stack[this.stack.length - 1]._results) {
547+
for (const move of this.results) {
547548
if (move.type === "move") {
548549
const [fromX, fromY] = LinesOfActionGame.algebraic2coords(move.from);
549550
const [toX, toY] = LinesOfActionGame.algebraic2coords(move.to);

src/games/manalath.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class ManalathGame extends GameBase {
9595
this.currplayer = state.currplayer;
9696
this.board = new Map(state.board);
9797
this.lastmove = state.lastmove;
98+
this.results = [...state._results];
9899
this.buildGraph();
99100
return this;
100101
}
@@ -457,10 +458,10 @@ export class ManalathGame extends GameBase {
457458
};
458459

459460
// Add annotations
460-
if (this.stack[this.stack.length - 1]._results.length > 0) {
461+
if (this.results.length > 0) {
461462
// @ts-ignore
462463
rep.annotations = [];
463-
for (const move of this.stack[this.stack.length - 1]._results) {
464+
for (const move of this.results) {
464465
if (move.type === "place") {
465466
const [x, y] = this.graph.algebraic2coords(move.where!);
466467
rep.annotations.push({type: "enter", targets: [{row: y, col: x}]});

src/games/pikemen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,9 @@ export class PikemenGame extends GameBase {
623623
};
624624

625625
// Add annotations
626-
// if (this.stack[this.stack.length - 1]._results.length > 0) {
627626
if (this.results.length > 0) {
628627
// @ts-ignore
629628
rep.annotations = [];
630-
// for (const move of this.stack[this.stack.length - 1]._results) {
631629
for (const move of this.results) {
632630
if (move.type === "move") {
633631
const [fromX, fromY] = PikemenGame.algebraic2coords(move.from);
@@ -640,7 +638,7 @@ export class PikemenGame extends GameBase {
640638
}
641639
// Only if there were no moves or captures do I want to signal a reorientation
642640
if (rep.annotations.length === 0) {
643-
for (const move of this.stack[this.stack.length - 1]._results) {
641+
for (const move of this.results) {
644642
if (move.type === "orient") {
645643
const [x, y] = PikemenGame.algebraic2coords(move.where!);
646644
rep.annotations.push({type: "enter", targets: [{row: y, col: x}]});

0 commit comments

Comments
 (0)