Skip to content

Commit 8c6e091

Browse files
committed
Pigs2: Bug fix (moving on top of a disabled pig)
1 parent efb0f77 commit 8c6e091

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "npm run json2ts && npm run build-ts && npm run lint",
99
"build-ts": "tsc && npm pack",
10-
"test0": "mocha -r ts-node/register test/games/emu.test.ts",
10+
"test0": "mocha -r ts-node/register test/games/pigs2.test.ts",
1111
"test": "mocha -r ts-node/register test/**/*.test.ts",
1212
"lint": "npx eslint .",
1313
"dist-dev": "rimraf dist && webpack",

src/games/pigs2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class Pigs2Game extends GameBaseSimultaneous {
344344

345345
// get ready
346346
const grid = new RectGrid(8, 8);
347-
const pigs = [...this.board.entries()].map(e => { return {player: e[1][0], cell: e[0], facing: e[1][1]} as IPigPos}).sort((a, b) => a.player - b.player);
347+
let pigs = [...this.board.entries()].map(e => { return {player: e[1][0], cell: e[0], facing: e[1][1]} as IPigPos}).sort((a, b) => a.player - b.player);
348348
const dmgApplied: number[] = []
349349
const resultGroups: APMoveResult[][] = [];
350350
for (let i = 0; i < this.numplayers; i++) {
@@ -472,6 +472,11 @@ export class Pigs2Game extends GameBaseSimultaneous {
472472
resultGroups[i].push({type: "move", from, to});
473473
pig.cell = to;
474474
}
475+
// filter out any disabled pigs that share a space with an active pig
476+
const able = pigs.filter(p => p.facing !== "U");
477+
const ableCells = able.map(p => p.cell);
478+
const disabled = pigs.filter(p => p.facing === "U");
479+
pigs = [...able, ...disabled.filter(p => !ableCells.includes(p.cell))];
475480

476481
// then resolve damage
477482
for (let player = 1; player <= this.numplayers; player++) {

0 commit comments

Comments
 (0)