Skip to content

Commit 7450cca

Browse files
committed
Morphos: Performance increase, but still not perfect
1 parent d932cd3 commit 7450cca

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/games/morphos.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,13 @@ export class MorphosGame extends GameBase {
795795
}
796796

797797
public render(): APRenderRep {
798+
const g = this.graph;
798799
// Build piece string
799800
const weakRed: RowCol[] = [];
800801
const weakBlue: RowCol[] = [];
801802
let pstr = "";
803+
const dots1: RowCol[] = [];
804+
const dots2: RowCol[] = [];
802805
for (let row = 0; row < this.boardSize; row++) {
803806
if (pstr.length > 0) {
804807
pstr += "\n";
@@ -821,6 +824,21 @@ export class MorphosGame extends GameBase {
821824
}
822825
} else {
823826
pieces.push("-");
827+
const occ = g.neighbours(cell).filter(c => this.board.has(c));
828+
if (occ.length > 2) {
829+
const cloned = this.clone();
830+
for (const p of [1,2] as const) {
831+
cloned.board.set(cell, p);
832+
if (cloned.isWeak(cell)) {
833+
if (p === 1) {
834+
dots1.push({row, col});
835+
} else {
836+
dots2.push({row, col});
837+
}
838+
break;
839+
}
840+
}
841+
}
824842
}
825843
}
826844
pstr += pieces.join("");
@@ -834,28 +852,6 @@ export class MorphosGame extends GameBase {
834852
];
835853

836854
// add territory dots
837-
const g = this.graph;
838-
const dots1: RowCol[] = [];
839-
const dots2: RowCol[] = [];
840-
for (const cell of [...this.empties]) {
841-
const occ = g.neighbours(cell).filter(c => this.board.has(c));
842-
if (occ.length >= 2) {
843-
for (const p of [1,2] as const) {
844-
const opp = p === 1 ? 2 : 1;
845-
const cloned = this.clone();
846-
cloned.board.set(cell, opp);
847-
if (cloned.isWeak(cell)) {
848-
const [col, row] = this.algebraic2coords(cell);
849-
if (p === 1) {
850-
dots1.push({col, row});
851-
} else {
852-
dots2.push({col, row});
853-
}
854-
break;
855-
}
856-
}
857-
}
858-
}
859855
if (dots1.length > 0) {
860856
markers.push({
861857
type: "dots",

0 commit comments

Comments
 (0)