From 1547581c2488ff68dd5358fbce45ad4e49c83bdc Mon Sep 17 00:00:00 2001 From: Michael Ficocelli Date: Wed, 6 Mar 2024 16:23:16 -0500 Subject: [PATCH] IPVGO: Fix self-capture move evaluation (#1140) --- src/Go/boardAnalysis/boardAnalysis.ts | 4 ++-- test/jest/Go/boardAnalysis.test.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Go/boardAnalysis/boardAnalysis.ts b/src/Go/boardAnalysis/boardAnalysis.ts index 8d8823bee..e34a0e3c9 100644 --- a/src/Go/boardAnalysis/boardAnalysis.ts +++ b/src/Go/boardAnalysis/boardAnalysis.ts @@ -480,12 +480,12 @@ export function findAllCapturedChains(chainList: PointState[][], playerWhoMoved: const opposingPlayer = playerWhoMoved === GoColor.white ? GoColor.black : GoColor.white; const enemyChainsToCapture = findCapturedChainOfColor(chainList, opposingPlayer); - if (enemyChainsToCapture) { + if (enemyChainsToCapture.length) { return enemyChainsToCapture; } const friendlyChainsToCapture = findCapturedChainOfColor(chainList, playerWhoMoved); - if (friendlyChainsToCapture) { + if (friendlyChainsToCapture.length) { return friendlyChainsToCapture; } } diff --git a/test/jest/Go/boardAnalysis.test.ts b/test/jest/Go/boardAnalysis.test.ts index 8de74e036..03cc352ea 100644 --- a/test/jest/Go/boardAnalysis.test.ts +++ b/test/jest/Go/boardAnalysis.test.ts @@ -1,7 +1,12 @@ import { setPlayer } from "@player"; -import { GoColor } from "@enums"; +import { GoColor, GoValidity } from "@enums"; 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"; setPlayer(new PlayerObject()); @@ -40,4 +45,12 @@ describe("Go board analysis tests", () => { expect(point?.x).toEqual(3); 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); + }); });