mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-05 22:13:20 +01:00
97ca8c5f5e
Co-authored-by: Michael Ficocelli <ficocemt@gmail.com>
79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
import { getNewBoardState, makeMove, passTurn, updateCaptures } from "../../../src/Go/boardState/boardState";
|
|
import { GoColor, GoOpponent } from "@enums";
|
|
import { boardFromSimpleBoard, simpleBoardFromBoard } from "../../../src/Go/boardAnalysis/boardAnalysis";
|
|
import { resetCoordinates, rotate90Degrees } from "../../../src/Go/boardState/offlineNodes";
|
|
import { bitverseBoardShape } from "../../../src/Go/Constants";
|
|
|
|
describe("Board analysis utility tests", () => {
|
|
it("Correctly applies the board size and handicap for 5x5 board", () => {
|
|
const result = getNewBoardState(5, GoOpponent.Illuminati, false);
|
|
const whitePieceCount = simpleBoardFromBoard(result.board)
|
|
.join("")
|
|
.split("")
|
|
.filter((p) => p === "O").length;
|
|
expect(whitePieceCount).toEqual(1);
|
|
expect(result).toEqual({
|
|
board: result.board, // This board state is different every run, due to random offline nodes and handicap placement
|
|
previousPlayer: GoColor.white,
|
|
previousBoards: [],
|
|
ai: GoOpponent.Illuminati,
|
|
passCount: 0,
|
|
cheatCount: 0,
|
|
});
|
|
expect(result.board?.length).toEqual(5);
|
|
});
|
|
|
|
it("Correctly applies the board size and handicap for the special opponent", () => {
|
|
const result = getNewBoardState(5, GoOpponent.w0r1d_d43m0n, true);
|
|
const simpleBoard = simpleBoardFromBoard(result.board);
|
|
const whitePieceCount = simpleBoard
|
|
.join("")
|
|
.split("")
|
|
.filter((p) => p === "O").length;
|
|
// Handicap of 7
|
|
expect(whitePieceCount).toEqual(7);
|
|
// Special board: 19x19 (even if other board size is passed in)
|
|
expect(result.board[0]?.length).toEqual(19);
|
|
|
|
// Special board shape
|
|
const boardWithNoRouters = simpleBoard.map((row) =>
|
|
row
|
|
.split("")
|
|
.map((p) => (p === "O" ? "." : p))
|
|
.join(""),
|
|
);
|
|
const specialBoardTemplate = simpleBoardFromBoard(
|
|
resetCoordinates(rotate90Degrees(boardFromSimpleBoard(bitverseBoardShape))),
|
|
);
|
|
expect(boardWithNoRouters).toEqual(specialBoardTemplate);
|
|
});
|
|
|
|
it("Correctly applies moves made", () => {
|
|
const result = getNewBoardState(5, GoOpponent.Daedalus, false);
|
|
makeMove(result, 1, 1, GoColor.black);
|
|
|
|
expect(simpleBoardFromBoard(result.board)).toEqual([".....", ".X...", ".....", ".....", "....."]);
|
|
});
|
|
|
|
it("Correctly applies passes made", () => {
|
|
const result = getNewBoardState(5, GoOpponent.Daedalus, false);
|
|
expect(result.previousPlayer).toEqual(GoColor.white);
|
|
passTurn(result, GoColor.black);
|
|
expect(result.passCount).toEqual(1);
|
|
expect(result.previousPlayer).toEqual(GoColor.black);
|
|
passTurn(result, GoColor.white);
|
|
expect(result.passCount).toEqual(2);
|
|
expect(result.previousPlayer).toEqual(null);
|
|
});
|
|
|
|
it("Correctly updates captures and chains", () => {
|
|
const boardState = boardFromSimpleBoard(["OX...", "XX...", ".....", ".....", "....."]);
|
|
expect(boardState[0][0]?.color).toEqual(GoColor.white);
|
|
|
|
updateCaptures(boardState, GoColor.black, true);
|
|
|
|
expect(boardState[0][0]?.color).toEqual(GoColor.empty);
|
|
expect(boardState[0][1]?.chain).toEqual("0,1");
|
|
});
|
|
});
|