IPVGO: Fix self-capture move evaluation (#1140)

This commit is contained in:
Michael Ficocelli 2024-03-06 16:23:16 -05:00 committed by GitHub
parent 1755b7cd7f
commit 1547581c24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

@ -480,12 +480,12 @@ export function findAllCapturedChains(chainList: PointState[][], playerWhoMoved:
const opposingPlayer = playerWhoMoved === GoColor.white ? GoColor.black : GoColor.white; const opposingPlayer = playerWhoMoved === GoColor.white ? GoColor.black : GoColor.white;
const enemyChainsToCapture = findCapturedChainOfColor(chainList, opposingPlayer); const enemyChainsToCapture = findCapturedChainOfColor(chainList, opposingPlayer);
if (enemyChainsToCapture) { if (enemyChainsToCapture.length) {
return enemyChainsToCapture; return enemyChainsToCapture;
} }
const friendlyChainsToCapture = findCapturedChainOfColor(chainList, playerWhoMoved); const friendlyChainsToCapture = findCapturedChainOfColor(chainList, playerWhoMoved);
if (friendlyChainsToCapture) { if (friendlyChainsToCapture.length) {
return friendlyChainsToCapture; return friendlyChainsToCapture;
} }
} }

@ -1,7 +1,12 @@
import { setPlayer } from "@player"; import { setPlayer } from "@player";
import { GoColor } from "@enums"; import { GoColor, GoValidity } from "@enums";
import { PlayerObject } from "../../../src/PersonObjects/Player/PlayerObject"; import { PlayerObject } from "../../../src/PersonObjects/Player/PlayerObject";
import { getAllEyes, getAllValidMoves, boardStateFromSimpleBoard } from "../../../src/Go/boardAnalysis/boardAnalysis"; import {
getAllEyes,
getAllValidMoves,
boardStateFromSimpleBoard,
evaluateIfMoveIsValid,
} from "../../../src/Go/boardAnalysis/boardAnalysis";
import { findAnyMatchedPatterns } from "../../../src/Go/boardAnalysis/patternMatching"; import { findAnyMatchedPatterns } from "../../../src/Go/boardAnalysis/patternMatching";
setPlayer(new PlayerObject()); setPlayer(new PlayerObject());
@ -40,4 +45,12 @@ describe("Go board analysis tests", () => {
expect(point?.x).toEqual(3); expect(point?.x).toEqual(3);
expect(point?.y).toEqual(2); expect(point?.y).toEqual(2);
}); });
it("identifies invalid moves from self-capture", async () => {
const board = [".X...", "X....", ".....", ".....", "....."];
const boardState = boardStateFromSimpleBoard(board);
const validity = evaluateIfMoveIsValid(boardState, 0, 0, GoColor.white, false);
expect(validity).toEqual(GoValidity.noSuicide);
});
}); });