2023-12-26 17:45:27 +01:00
|
|
|
import { setPlayer } from "@player";
|
2024-03-06 22:23:16 +01:00
|
|
|
import { GoColor, GoValidity } from "@enums";
|
2023-12-26 17:45:27 +01:00
|
|
|
import { PlayerObject } from "../../../src/PersonObjects/Player/PlayerObject";
|
2024-03-06 22:23:16 +01:00
|
|
|
import {
|
|
|
|
getAllEyes,
|
|
|
|
getAllValidMoves,
|
|
|
|
boardStateFromSimpleBoard,
|
|
|
|
evaluateIfMoveIsValid,
|
|
|
|
} from "../../../src/Go/boardAnalysis/boardAnalysis";
|
2023-12-26 17:45:27 +01:00
|
|
|
import { findAnyMatchedPatterns } from "../../../src/Go/boardAnalysis/patternMatching";
|
|
|
|
|
|
|
|
setPlayer(new PlayerObject());
|
|
|
|
|
|
|
|
describe("Go board analysis tests", () => {
|
|
|
|
it("identifies chains and liberties", async () => {
|
|
|
|
const board = ["XOO..", ".....", ".....", ".....", "....."];
|
2024-02-26 14:05:10 +01:00
|
|
|
const boardState = boardStateFromSimpleBoard(board);
|
2023-12-26 17:45:27 +01:00
|
|
|
|
|
|
|
expect(boardState.board[0]?.[0]?.liberties?.length).toEqual(1);
|
|
|
|
expect(boardState.board[0]?.[1]?.liberties?.length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("identifies all points that are part of 'eyes' on the board", async () => {
|
|
|
|
const board = ["..O..", "OOOOO", "..XXX", "..XX.", "..X.X"];
|
2024-02-26 14:05:10 +01:00
|
|
|
const boardState = boardStateFromSimpleBoard(board);
|
2023-12-26 17:45:27 +01:00
|
|
|
|
2024-02-26 14:05:10 +01:00
|
|
|
const whitePlayerEyes = getAllEyes(boardState.board, GoColor.white).flat().flat();
|
|
|
|
const blackPlayerEyes = getAllEyes(boardState.board, GoColor.black).flat().flat();
|
2023-12-26 17:45:27 +01:00
|
|
|
|
|
|
|
expect(whitePlayerEyes?.length).toEqual(4);
|
|
|
|
expect(blackPlayerEyes?.length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("identifies strong patterns on the board", async () => {
|
|
|
|
const board = [".....", ".....", ".....", ".....", ".OXO."];
|
2024-02-26 14:05:10 +01:00
|
|
|
const boardState = boardStateFromSimpleBoard(board);
|
2023-12-26 17:45:27 +01:00
|
|
|
const point = await findAnyMatchedPatterns(
|
2024-02-26 14:05:10 +01:00
|
|
|
boardState.board,
|
|
|
|
GoColor.white,
|
|
|
|
getAllValidMoves(boardState, GoColor.white),
|
2023-12-26 17:45:27 +01:00
|
|
|
true,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(point?.x).toEqual(3);
|
|
|
|
expect(point?.y).toEqual(2);
|
|
|
|
});
|
2024-03-06 22:23:16 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2024-03-21 01:37:20 +01:00
|
|
|
|
|
|
|
it("identifies invalid moves from repeat", async () => {
|
|
|
|
const board = [".X...", ".....", ".....", ".....", "....."];
|
|
|
|
const boardState = boardStateFromSimpleBoard(board);
|
|
|
|
boardState.previousBoards.push([".X...", ".....", ".....", ".....", "....."]);
|
|
|
|
boardState.previousBoards.push([".X...", ".....", ".....", ".....", "....."]);
|
|
|
|
boardState.previousBoards.push([".X...", ".....", ".....", ".....", "....."]);
|
|
|
|
boardState.previousBoards.push(["OX...", ".....", ".....", ".....", "....."]);
|
|
|
|
const validity = evaluateIfMoveIsValid(boardState, 0, 0, GoColor.white, false);
|
|
|
|
|
|
|
|
expect(validity).toEqual(GoValidity.boardRepeated);
|
|
|
|
});
|
2023-12-26 17:45:27 +01:00
|
|
|
});
|