IPVGO: Do not update captures on passed analysis boards (#2415)

This commit is contained in:
Michael Ficocelli
2025-12-21 16:44:24 -05:00
committed by GitHub
parent 49e231fd41
commit 4218b01dfb
8 changed files with 127 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ import {
import { getNewBoardState, getNewBoardStateFromSimpleBoard } from "../../../src/Go/boardState/boardState";
import { installAugmentations } from "../../../src/Augmentation/AugmentationHelpers";
import { getMockedNetscriptContext, initGameEnvironment, setupBasicTestingEnvironment } from "../Utilities";
import { NetscriptGo } from "../../../src/NetscriptFunctions/Go";
initGameEnvironment();
@@ -155,20 +156,52 @@ describe("Netscript Go API unit tests", () => {
]);
});
it("should correctly find available moves for a given board when playing as white", () => {
const boardState = ["XOX..", "X.X.X", ".X..X", "...XX", "..XOO"];
const mockNetscriptContext = getMockedNetscriptContext();
const result = NetscriptGo().analysis.getValidMoves(mockNetscriptContext)(boardState, null, true);
expect(result).toEqual([
[false, false, false, true, true],
[false, false, false, true, false],
[true, false, true, true, false],
[true, true, true, false, false],
[true, true, false, false, false],
]);
});
it("should correctly find available moves for a given board when playing as white and given a prior board", () => {
const boardState = ["#..##", ".....", "...O.", ".....", "....."];
const mockNetscriptContext = getMockedNetscriptContext();
const result = NetscriptGo().analysis.getValidMoves(mockNetscriptContext)(boardState, boardState, true);
expect(result).toEqual([
[false, true, true, false, false],
[true, true, true, true, true],
[true, true, true, false, true],
[true, true, true, true, true],
[true, true, true, true, true],
]);
});
it("should return all valid and invalid moves on the board, if a board is provided", () => {
const currentBoard = [".....", ".....", ".....", ".....", "....."];
Go.currentGame = boardStateFromSimpleBoard(currentBoard, GoOpponent.Daedalus, GoColor.white);
resetAI();
const board = getNewBoardStateFromSimpleBoard(
["XXO.#", "XO.O.", ".OOOO", "XXXXX", "X.X.X"],
["XXO.#", "XO.O.", ".OOO.", "XXXXX", "X.X.X"],
["..O.#", ".O.O.", ".OOOO", "XXXXX", "X.X.X"],
undefined,
GoOpponent.Netburners,
GoColor.white,
);
const result = getValidMoves(board);
expect(result).toEqual([
[false, false, false, false, false],
[false, false, false, false, false],
[true, true, false, false, false],
[true, false, false, false, false],
[true, false, false, false, false],
[false, false, false, false, false],
[false, true, false, true, false],
@@ -207,6 +240,21 @@ describe("Netscript Go API unit tests", () => {
[3, -1, 3, -1, 3],
]);
});
it("should show zero liberties for groups that would be captured and -1 for empty spaces or offline nodes", () => {
const boardState = [".XXX#", "XOOOX", "XOXOX", "XOOOX", "XXXX."];
const mockNetscriptContext = getMockedNetscriptContext();
const result = NetscriptGo().analysis.getLiberties(mockNetscriptContext)(boardState);
expect(result).toEqual([
[-1, 1, 1, 1, -1],
[2, 0, 0, 0, 1],
[2, 0, 0, 0, 1],
[2, 0, 0, 0, 1],
[2, 2, 2, 2, -1],
]);
});
});
describe("getControlledEmptyNodes() unit tests", () => {
it("should show the owner of each empty node, if a single player has fully encircled it", () => {
@@ -230,6 +278,35 @@ describe("Netscript Go API unit tests", () => {
expect(result).toEqual(["...O#", "..O.O", "?....", ".....", ".X.X."]);
});
});
describe("setTestingBoardState() tests", () => {
it("should set the board to the requested state", () => {
const board = ["OXX..", ".....", ".....", ".....", "....."];
Go.currentGame = boardStateFromSimpleBoard(board, GoOpponent.Daedalus, GoColor.white);
resetAI();
NetscriptGo().analysis.setTestingBoardState(mockCtx)(["XOX..", "X.X.X", ".X..X", "...XX", "..XOO"], null, true);
const newBoard = simpleBoardFromBoard(Go.currentGame.board);
expect(newBoard).toEqual(["XOX..", "X.X.X", ".X..X", "...XX", "..X.."]);
expect(Go.currentGame.previousPlayer).toEqual(GoColor.black);
expect(Go.currentGame.komiOverride).toEqual(5.5);
expect(Go.currentGame.ai).toEqual(GoOpponent.none);
});
it("should set the board to the requested state, and set the last played color correctly", () => {
const board = ["OXX..", ".....", ".....", ".....", "....."];
Go.currentGame = boardStateFromSimpleBoard(board, GoOpponent.Daedalus, GoColor.white);
resetAI();
NetscriptGo().analysis.setTestingBoardState(mockCtx)(["XOX..", "X.X.X", ".X..X", "...XX", "..XOO"], 13);
const newBoard = simpleBoardFromBoard(Go.currentGame.board);
expect(newBoard).toEqual(["XOX..", "X.X.X", ".X..X", "...XX", "..X.."]);
expect(Go.currentGame.previousPlayer).toEqual(GoColor.white);
expect(Go.currentGame.komiOverride).toEqual(13);
expect(Go.currentGame.ai).toEqual(GoOpponent.none);
});
});
describe("cheatPlayTwoMoves() tests", () => {
it("should handle invalid moves", () => {
const board = ["XOO..", ".....", ".....", ".....", "....."];