Skip to content

Commit

Permalink
Merge pull request #142 from benjaminpjones/fix-japanese-scoring-capt…
Browse files Browse the repository at this point in the history
…ure-bug

Fix ScoreEstimator bug for Japanese scoring
  • Loading branch information
anoek authored Dec 19, 2023
2 parents 6582235 + 4fd8b6d commit 2b28729
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ScoreEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ export function adjust_estimate(
}
}
}
}

// Account for already-captured prisoners in Japanese rules.
if (territory_counting) {
adjusted_score += engine.getBlackPrisoners();
adjusted_score -= engine.getWhitePrisoners();
}
// Account for already-captured prisoners in Japanese rules.
if (territory_counting) {
adjusted_score += engine.getBlackPrisoners();
adjusted_score -= engine.getWhitePrisoners();
}

return { score: adjusted_score, ownership };
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/ScoreEstimator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,38 @@ describe("ScoreEstimator", () => {
[0, 0, 0, 0],
]);
});

test("score() with captures", async () => {
// A board that is split down the middle between black and white
const engine = new GoEngine({
width: 8,
height: 8,
initial_state: { black: "dadbdcdddedfdgdh", white: "eaebecedeeefegeh" },
komi: 0,
});

// Capture a stone in the corner
engine.place(7, 0);
engine.place(7, 1);
engine.place(-1, -1);
engine.place(6, 0);

// A B C D E F G H
// 8 . . . X O . O{.}
// 7 . . . X O . . O
// 6 . . . X O . . .
// 5 . . . X O . . .
// 4 . . . X O . . .
// 3 . . . X O . . .
// 2 . . . X O . . .
// 1 . . . X O . . .

const se = new ScoreEstimator(undefined, engine, 10, 0.5, false);
await se.when_ready;

se.score();

expect(se.amount).toBe(1);
expect(se.winner).toBe("Black");
});
});

0 comments on commit 2b28729

Please sign in to comment.