IPVGO: Ensure that the player has the prerequisites to face the secret opponent (#1157)

This commit is contained in:
Michael Ficocelli 2024-03-11 12:57:44 -04:00 committed by GitHub
parent e9d1ddfaf3
commit c703b71871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 9 deletions

@ -1,7 +1,7 @@
import type { BoardState, Play } from "../Types"; import type { BoardState, Play } from "../Types";
import { Player } from "@player"; import { Player } from "@player";
import { GoColor, GoPlayType, GoValidity, GoOpponent } from "@enums"; import { AugmentationName, GoColor, GoOpponent, GoPlayType, GoValidity } from "@enums";
import { Go, GoEvents } from "../Go"; import { Go, GoEvents } from "../Go";
import { getMove, sleep } from "../boardAnalysis/goAI"; import { getMove, sleep } from "../boardAnalysis/goAI";
import { getNewBoardState, makeMove, passTurn, updateCaptures, updateChains } from "../boardState/boardState"; import { getNewBoardState, makeMove, passTurn, updateCaptures, updateChains } from "../boardState/boardState";
@ -177,7 +177,12 @@ function logEndGame(logger: (s: string) => void) {
*/ */
export function resetBoardState(error: (s: string) => void, opponent: GoOpponent, boardSize: number) { export function resetBoardState(error: (s: string) => void, opponent: GoOpponent, boardSize: number) {
if (![5, 7, 9, 13].includes(boardSize)) { if (![5, 7, 9, 13].includes(boardSize)) {
error(`Invalid subnet size requested (${boardSize}, size must be 5, 7, 9, or 13`); error(`Invalid subnet size requested (${boardSize}), size must be 5, 7, 9, or 13`);
return;
}
if (opponent === GoOpponent.w0r1d_d43m0n && !Player.hasAugmentation(AugmentationName.TheRedPill, true)) {
error(`Invalid opponent requested (${opponent}), this opponent has not yet been discovered`);
return; return;
} }

@ -1,5 +1,5 @@
import { setPlayer } from "@player"; import { setPlayer } from "@player";
import { GoOpponent, GoColor, GoPlayType } from "@enums"; import { GoColor, GoOpponent, GoPlayType } from "@enums";
import { Go } from "../../../src/Go/Go"; import { Go } from "../../../src/Go/Go";
import { boardStateFromSimpleBoard, simpleBoardFromBoard } from "../../../src/Go/boardAnalysis/boardAnalysis"; import { boardStateFromSimpleBoard, simpleBoardFromBoard } from "../../../src/Go/boardAnalysis/boardAnalysis";
import { import {
@ -87,19 +87,17 @@ describe("Netscript Go API unit tests", () => {
expect(Go.currentGame.board.length).toEqual(9); expect(Go.currentGame.board.length).toEqual(9);
expect(Go.currentGame.ai).toEqual(GoOpponent.SlumSnakes); expect(Go.currentGame.ai).toEqual(GoOpponent.SlumSnakes);
}); });
/* This typechecking is now done prior to calling resetBoardState (it's checked in the ns function via getEnumHelper("GoOpponent".nsGetMember()))
it("should throw an error if an invalid opponent is requested", () => { it("should throw an error if an invalid opponent is requested", () => {
const board = ["OXX..", ".....", ".....", ".....", "..###"]; const board = ["OXX..", ".....", ".....", ".....", "..###"];
Go.boardState = getBoardFromSimplifiedBoardState(board); Go.currentGame = boardStateFromSimpleBoard(board);
const mockError = jest.fn(); const mockError = jest.fn();
resetBoardState(mockError, "fake opponent", 9); resetBoardState(mockError, GoOpponent.w0r1d_d43m0n, 9);
expect(mockError).toHaveBeenCalledWith( expect(mockError).toHaveBeenCalledWith(
"Invalid opponent requested (fake opponent), valid options are Netburners, Slum Snakes, The Black Hand, Tetrads, Daedalus, Illuminati", `Invalid opponent requested (${GoOpponent.w0r1d_d43m0n}), this opponent has not yet been discovered`,
); );
}); });
*/
it("should throw an error if an invalid size is requested", () => { it("should throw an error if an invalid size is requested", () => {
const board = ["OXX..", ".....", ".....", ".....", "..###"]; const board = ["OXX..", ".....", ".....", ".....", "..###"];
Go.currentGame = boardStateFromSimpleBoard(board); Go.currentGame = boardStateFromSimpleBoard(board);
@ -107,7 +105,7 @@ describe("Netscript Go API unit tests", () => {
resetBoardState(mockError, GoOpponent.TheBlackHand, 31337); resetBoardState(mockError, GoOpponent.TheBlackHand, 31337);
expect(mockError).toHaveBeenCalledWith("Invalid subnet size requested (31337, size must be 5, 7, 9, or 13"); expect(mockError).toHaveBeenCalledWith("Invalid subnet size requested (31337), size must be 5, 7, 9, or 13");
}); });
}); });