diff --git a/src/ScoreEstimator.ts b/src/ScoreEstimator.ts index 32ef3655..58a7de64 100644 --- a/src/ScoreEstimator.ts +++ b/src/ScoreEstimator.ts @@ -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 }; diff --git a/src/__tests__/ScoreEstimator.test.ts b/src/__tests__/ScoreEstimator.test.ts index efba3375..b38a9b3f 100644 --- a/src/__tests__/ScoreEstimator.test.ts +++ b/src/__tests__/ScoreEstimator.test.ts @@ -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"); + }); });