mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
IPVGO: Prevent tiny islands surrounded by offline nodes during initial board generation (#2310)
This commit is contained in:
committed by
GitHub
parent
21ddb99fd5
commit
cad38f015c
@@ -3,6 +3,9 @@ import type { Board, BoardState, PointState } from "../Types";
|
||||
import { Player } from "@player";
|
||||
import { boardSizes } from "../Constants";
|
||||
import { WHRNG } from "../../Casino/RNG";
|
||||
import { getAllChains } from "../boardAnalysis/boardAnalysis";
|
||||
import { updateChains } from "./boardState";
|
||||
import { GoColor } from "@enums";
|
||||
|
||||
type rand = (n1: number, n2: number) => number;
|
||||
|
||||
@@ -36,6 +39,8 @@ export function addObstacles(boardState: BoardState) {
|
||||
boardState.board = ensureOfflineNodes(boardState.board);
|
||||
|
||||
boardState.board = resetCoordinates(boardState.board);
|
||||
|
||||
boardState.board = removeIslands(boardState.board);
|
||||
}
|
||||
|
||||
export function resetCoordinates(board: Board) {
|
||||
@@ -52,6 +57,24 @@ export function resetCoordinates(board: Board) {
|
||||
return board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all tiny islands of empty points (2 or fewer) from the board
|
||||
* @param board
|
||||
*/
|
||||
export function removeIslands(board: Board) {
|
||||
updateChains(board, true);
|
||||
const chains = getAllChains(board);
|
||||
|
||||
for (const chain of chains) {
|
||||
if (chain.length <= 2 && chain[0]?.color === GoColor.empty) {
|
||||
for (const point of chain) {
|
||||
board[point.x][point.y] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return board;
|
||||
}
|
||||
|
||||
function getScale(board: Board) {
|
||||
return boardSizes.indexOf(board[0].length);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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 { removeIslands, resetCoordinates, rotate90Degrees } from "../../../src/Go/boardState/offlineNodes";
|
||||
import { bitverseBoardShape } from "../../../src/Go/Constants";
|
||||
import { getEmptyHighlightedPoints } from "../../../src/Go/Go";
|
||||
|
||||
@@ -52,6 +52,12 @@ describe("Board analysis utility tests", () => {
|
||||
expect(boardWithNoRouters).toEqual(specialBoardTemplate);
|
||||
});
|
||||
|
||||
it("removes tiny empty point chains from initial board", () => {
|
||||
const board = boardFromSimpleBoard([".#...", "##...", ".....", "...##", "..#.."]);
|
||||
const cleanedBoard = removeIslands(board);
|
||||
expect(simpleBoardFromBoard(cleanedBoard)).toEqual(["##...", "##...", ".....", "...##", "..###"]);
|
||||
});
|
||||
|
||||
it("Correctly applies moves made", () => {
|
||||
const result = getNewBoardState(5, GoOpponent.Daedalus, false);
|
||||
makeMove(result, 1, 1, GoColor.black);
|
||||
|
||||
Reference in New Issue
Block a user