Skip to content

Commit 8df1738

Browse files
committed
Entropy: Let's try this again! Explicitly check for in bounds in move validation.
1 parent 85170d1 commit 8df1738

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/games/entropy.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ export class EntropyGame extends GameBaseSimultaneous {
294294
}
295295
// valid cell
296296
try {
297-
this.algebraic2coords(from);
297+
const [fx, fy] = this.algebraic2coords(from);
298+
if (fx >= this.boardsize || fy >= this.boardsize) {
299+
throw new Error("Coordinates out of bounds");
300+
}
298301
} catch {
299302
result.valid = false;
300303
result.message = i18next.t("apgames:validation._general.INVALIDCELL", {cell: from});
@@ -317,6 +320,9 @@ export class EntropyGame extends GameBaseSimultaneous {
317320
let xFrom: number; let yFrom: number;
318321
try {
319322
[xFrom, yFrom] = this.algebraic2coords(from);
323+
if (xFrom >= this.boardsize || yFrom >= this.boardsize) {
324+
throw new Error("Coordinates out of bounds");
325+
}
320326
} catch {
321327
result.valid = false;
322328
result.message = i18next.t("apgames:validation._general.INVALIDCELL", {cell: from});
@@ -341,6 +347,9 @@ export class EntropyGame extends GameBaseSimultaneous {
341347
let xTo: number; let yTo: number;
342348
try {
343349
[xTo, yTo] = this.algebraic2coords(to);
350+
if (xTo >= this.boardsize || yTo >= this.boardsize) {
351+
throw new Error("Coordinates out of bounds");
352+
}
344353
} catch {
345354
result.valid = false;
346355
result.message = i18next.t("apgames:validation._general.INVALIDCELL", {cell: to});

0 commit comments

Comments
 (0)