IPVGO: Remove unneeded functions from boardState.ts (#1270)

This commit is contained in:
David Walker
2024-05-16 12:26:18 -07:00
committed by GitHub
parent b7962ad8ab
commit 38d99ff15e
7 changed files with 38 additions and 66 deletions
+11 -27
View File
@@ -140,7 +140,7 @@ export function applyHandicap(board: Board, handicap: number): void {
// select random distinct moves from the move options list up to the specified handicap amount
for (let i = 0; i < handicap && i < handicapMoveOptions.length; i++) {
const index = floor(Math.random() * handicapMoveOptions.length);
const index = Math.floor(Math.random() * handicapMoveOptions.length);
handicapMoves.push(handicapMoveOptions[index]);
handicapMoveOptions.splice(index, 1);
}
@@ -247,16 +247,13 @@ export function findAdjacentPointsInChain(board: Board, x: number, y: number) {
checkedPoints.push(currentPoint);
const neighbors = findNeighbors(board, currentPoint.x, currentPoint.y);
[neighbors.north, neighbors.east, neighbors.south, neighbors.west]
.filter(isNotNull)
.filter(isDefined)
.forEach((neighbor) => {
if (neighbor && neighbor.color === currentPoint.color && !contains(checkedPoints, neighbor)) {
adjacentPoints.push(neighbor);
pointsToCheckNeighbors.push(neighbor);
}
checkedPoints.push(neighbor);
});
[neighbors.north, neighbors.east, neighbors.south, neighbors.west].filter(isNotNullish).forEach((neighbor) => {
if (neighbor && neighbor.color === currentPoint.color && !contains(checkedPoints, neighbor)) {
adjacentPoints.push(neighbor);
pointsToCheckNeighbors.push(neighbor);
}
checkedPoints.push(neighbor);
});
}
return adjacentPoints;
@@ -312,22 +309,9 @@ export function findNeighbors(board: Board, x: number, y: number): Neighbor {
}
export function getArrayFromNeighbor(neighborObject: Neighbor): PointState[] {
return [neighborObject.north, neighborObject.east, neighborObject.south, neighborObject.west]
.filter(isNotNull)
.filter(isDefined);
return [neighborObject.north, neighborObject.east, neighborObject.south, neighborObject.west].filter(isNotNullish);
}
export function isNotNull<T>(argument: T | null): argument is T {
return argument !== null;
}
export function isDefined<T>(argument: T | undefined): argument is T {
return argument !== undefined;
}
export function floor(n: number) {
return ~~n;
}
export function ceil(n: number) {
const floored = floor(n);
return floored === n ? n : floored + 1;
export function isNotNullish<T>(argument: T | undefined | null): argument is T {
return argument != null;
}
+3 -4
View File
@@ -3,13 +3,12 @@ import type { Board, BoardState, PointState } from "../Types";
import { Player } from "@player";
import { boardSizes } from "../Constants";
import { WHRNG } from "../../Casino/RNG";
import { floor } from "./boardState";
type rand = (n1: number, n2: number) => number;
export function addObstacles(boardState: BoardState) {
const rng = new WHRNG(Player.totalPlaytime ?? new Date().getTime());
const random = (n1: number, n2: number) => n1 + floor((n2 - n1 + 1) * rng.random());
const random = (n1: number, n2: number) => n1 + Math.floor((n2 - n1 + 1) * rng.random());
const shouldRemoveCorner = !random(0, 4);
const shouldRemoveRows = !shouldRemoveCorner && !random(0, 4);
@@ -105,8 +104,8 @@ function addDeadCorner(board: Board, random: rand, size: number) {
function addCenterBreak(board: Board, random: rand) {
const size = board[0].length;
const maxOffset = getScale(board);
const xIndex = random(0, maxOffset * 2) - maxOffset + floor(size / 2);
const length = random(1, floor(size / 2 - 1));
const xIndex = random(0, maxOffset * 2) - maxOffset + Math.floor(size / 2);
const length = random(1, Math.floor(size / 2 - 1));
board[xIndex] = board[xIndex].map((point, index) => (index < length ? null : point));