diff --git a/markdown/bitburner.go.makemove.md b/markdown/bitburner.go.makemove.md index 625a2726a..7b24a7883 100644 --- a/markdown/bitburner.go.makemove.md +++ b/markdown/bitburner.go.makemove.md @@ -6,15 +6,13 @@ Make a move on the IPvGO subnet game board, and await the opponent's response. x:0 y:0 represents the bottom-left corner of the board in the UI. -playAsWhite is optional, and attempts to make a move as the white player. Only can be used when playing against "No AI". - **Signature:** ```typescript makeMove( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -26,9 +24,9 @@ makeMove( | Parameter | Type | Description | | --- | --- | --- | -| x | number | | -| y | number | | -| playAsWhite | (not declared) | _(Optional)_ | +| x | number | x coordinate of move to make | +| y | number | y coordinate of move to make | +| playAsWhite | boolean | _(Optional)_ optional. If true, attempts to play as white and then wait for black's move. Can only be used when playing as white when the opponent is set to "No AI" | **Returns:** diff --git a/markdown/bitburner.go.md b/markdown/bitburner.go.md index 38969d054..68f62d5d6 100644 --- a/markdown/bitburner.go.md +++ b/markdown/bitburner.go.md @@ -28,8 +28,8 @@ export interface Go | [getGameState()](./bitburner.go.getgamestate.md) | Gets the status of the current game. Shows the current player, current score, and the previous move coordinates. Previous move coordinates will be \[-1, -1\] for a pass, or if there are no prior moves. | | [getMoveHistory()](./bitburner.go.getmovehistory.md) |

Returns all the prior moves in the current game, as an array of simple board states.

For example, a single 5x5 prior move board might look like this:

\[
"XX.O.",
"X..OO",
".XO..",
"XXO.\#",
".XO.\#",
\]

| | [getOpponent()](./bitburner.go.getopponent.md) | Returns the name of the opponent faction in the current subnet. | -| [makeMove(x, y, playAsWhite)](./bitburner.go.makemove.md) |

Make a move on the IPvGO subnet game board, and await the opponent's response. x:0 y:0 represents the bottom-left corner of the board in the UI.

playAsWhite is optional, and attempts to make a move as the white player. Only can be used when playing against "No AI".

| +| [makeMove(x, y, playAsWhite)](./bitburner.go.makemove.md) | Make a move on the IPvGO subnet game board, and await the opponent's response. x:0 y:0 represents the bottom-left corner of the board in the UI. | | [opponentNextTurn(logOpponentMove, playAsWhite)](./bitburner.go.opponentnextturn.md) | Returns a promise that resolves with the success or failure state of your last move, and the AI's response, if applicable. x:0 y:0 represents the bottom-left corner of the board in the UI. | -| [passTurn(passAsWhite)](./bitburner.go.passturn.md) |

Pass the player's turn rather than making a move, and await the opponent's response. This ends the game if the opponent passed on the previous turn, or if the opponent passes on their following turn.

This can also be used if you pick up the game in a state where the opponent needs to play next. For example: if BitBurner was closed while waiting for the opponent to make a move, you may need to call passTurn() to get them to play their move on game start.

passAsWhite is optional, and attempts to pass while playing as the white player. Only can be used when playing against "No AI".

| -| [resetBoardState(opponent, boardSize)](./bitburner.go.resetboardstate.md) |

Gets new IPvGO subnet with the specified size owned by the listed faction, ready for the player to make a move. This will reset your win streak if the current game is not complete and you have already made moves.

Note that some factions will have a few routers already on the subnet after a reset.

opponent is "Netburners" or "Slum Snakes" or "The Black Hand" or "Tetrads" or "Daedalus" or "Illuminati" or "????????????" or "No AI",

| +| [passTurn(passAsWhite)](./bitburner.go.passturn.md) |

Pass the player's turn rather than making a move, and await the opponent's response. This ends the game if the opponent passed on the previous turn, or if the opponent passes on their following turn.

This can also be used if you pick up the game in a state where the opponent needs to play next. For example: if BitBurner was closed while waiting for the opponent to make a move, you may need to call passTurn() to get them to play their move on game start.

| +| [resetBoardState(opponent, boardSize)](./bitburner.go.resetboardstate.md) |

Gets new IPvGO subnet with the specified size owned by the listed faction, ready for the player to make a move. This will reset your win streak if the current game is not complete and you have already made moves.

Note that some factions will have a few routers already on the subnet after a reset.

| diff --git a/markdown/bitburner.go.opponentnextturn.md b/markdown/bitburner.go.opponentnextturn.md index 42f8a4900..54153b543 100644 --- a/markdown/bitburner.go.opponentnextturn.md +++ b/markdown/bitburner.go.opponentnextturn.md @@ -11,7 +11,7 @@ Returns a promise that resolves with the success or failure state of your last m ```typescript opponentNextTurn( logOpponentMove?: boolean, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -24,7 +24,7 @@ opponentNextTurn( | Parameter | Type | Description | | --- | --- | --- | | logOpponentMove | boolean | _(Optional)_ optional, defaults to true. if false prevents logging opponent move | -| playAsWhite | (not declared) | _(Optional)_ optional. If true, waits to get the next move the black player makes. Intended to be used when playing as white when the opponent is set to "No AI" | +| playAsWhite | boolean | _(Optional)_ optional. If true, waits to get the next move the black player makes. Intended to be used when playing as white when the opponent is set to "No AI" | **Returns:** diff --git a/markdown/bitburner.go.passturn.md b/markdown/bitburner.go.passturn.md index 3550719e0..48f83bc5e 100644 --- a/markdown/bitburner.go.passturn.md +++ b/markdown/bitburner.go.passturn.md @@ -8,12 +8,10 @@ Pass the player's turn rather than making a move, and await the opponent's respo This can also be used if you pick up the game in a state where the opponent needs to play next. For example: if BitBurner was closed while waiting for the opponent to make a move, you may need to call passTurn() to get them to play their move on game start. -passAsWhite is optional, and attempts to pass while playing as the white player. Only can be used when playing against "No AI". - **Signature:** ```typescript -passTurn(passAsWhite = false): Promise<{ +passTurn(passAsWhite?: boolean): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; y: number | null; @@ -24,7 +22,7 @@ passTurn(passAsWhite = false): Promise<{ | Parameter | Type | Description | | --- | --- | --- | -| passAsWhite | (not declared) | _(Optional)_ | +| passAsWhite | boolean | _(Optional)_ optional. If true, attempts to pass as white and then wait for black's move. Only can be used when playing against "No AI". | **Returns:** diff --git a/markdown/bitburner.go.resetboardstate.md b/markdown/bitburner.go.resetboardstate.md index 84e3cfbfb..aa2422e64 100644 --- a/markdown/bitburner.go.resetboardstate.md +++ b/markdown/bitburner.go.resetboardstate.md @@ -8,8 +8,6 @@ Gets new IPvGO subnet with the specified size owned by the listed faction, ready Note that some factions will have a few routers already on the subnet after a reset. -opponent is "Netburners" or "Slum Snakes" or "The Black Hand" or "Tetrads" or "Daedalus" or "Illuminati" or "????????????" or "No AI", - **Signature:** ```typescript @@ -20,8 +18,8 @@ resetBoardState(opponent: GoOpponent, boardSize: 5 | 7 | 9 | 13): string[] | und | Parameter | Type | Description | | --- | --- | --- | -| opponent | [GoOpponent](./bitburner.goopponent.md) | | -| boardSize | 5 \| 7 \| 9 \| 13 | | +| opponent | [GoOpponent](./bitburner.goopponent.md) | The opponent faction to play against. "Netburners" \| "Slum Snakes" \| "The Black Hand" \| "Tetrads" \| "Daedalus" \| "Illuminati" \| "????????????" \| "No AI" | +| boardSize | 5 \| 7 \| 9 \| 13 | The size of the board to play on. Must be 5, 7, 9, or 13. | **Returns:** diff --git a/markdown/bitburner.goanalysis.getchains.md b/markdown/bitburner.goanalysis.getchains.md index a353c6e49..aa25f4649 100644 --- a/markdown/bitburner.goanalysis.getchains.md +++ b/markdown/bitburner.goanalysis.getchains.md @@ -22,12 +22,14 @@ getChains(boardState?: string[]): (number | null)[][]; | Parameter | Type | Description | | --- | --- | --- | -| boardState | string\[\] | _(Optional)_ | +| boardState | string\[\] | _(Optional)_ Optional. The current board state, as an array of strings. Defaults to the current board state. | **Returns:** (number \| null)\[\]\[\] +A 2D array of numbers identifying the chain ID of each point. + ## Remarks RAM cost: 16 GB (This is intentionally expensive; you can derive this info from just getBoardState() ) diff --git a/markdown/bitburner.goanalysis.getcontrolledemptynodes.md b/markdown/bitburner.goanalysis.getcontrolledemptynodes.md index 99a73f7c5..a8ca593fa 100644 --- a/markdown/bitburner.goanalysis.getcontrolledemptynodes.md +++ b/markdown/bitburner.goanalysis.getcontrolledemptynodes.md @@ -22,12 +22,14 @@ getControlledEmptyNodes(boardState?: string[]): string[]; | Parameter | Type | Description | | --- | --- | --- | -| boardState | string\[\] | _(Optional)_ | +| boardState | string\[\] | _(Optional)_ Optional. The current board state, as an array of strings. Defaults to the current board state. | **Returns:** string\[\] +A 2D array of characters indicating the player who controls each empty point. + ## Remarks RAM cost: 16 GB (This is intentionally expensive; you can derive this info from just getBoardState() ) diff --git a/markdown/bitburner.goanalysis.getliberties.md b/markdown/bitburner.goanalysis.getliberties.md index 4312a0cde..7f5c32424 100644 --- a/markdown/bitburner.goanalysis.getliberties.md +++ b/markdown/bitburner.goanalysis.getliberties.md @@ -20,12 +20,14 @@ getLiberties(boardState?: string[]): number[][]; | Parameter | Type | Description | | --- | --- | --- | -| boardState | string\[\] | _(Optional)_ | +| boardState | string\[\] | _(Optional)_ Optional. The current board state, as an array of strings. Defaults to the current board state. | **Returns:** number\[\]\[\] +A 2D array of numbers counting the liberties of each point. + ## Remarks RAM cost: 16 GB (This is intentionally expensive; you can derive this info from just getBoardState() ) diff --git a/markdown/bitburner.goanalysis.getstats.md b/markdown/bitburner.goanalysis.getstats.md index 05f37cefd..cd98f26f5 100644 --- a/markdown/bitburner.goanalysis.getstats.md +++ b/markdown/bitburner.goanalysis.getstats.md @@ -19,3 +19,5 @@ getStats(): Partial>; Partial<Record<[GoOpponent](./bitburner.goopponent.md), [SimpleOpponentStats](./bitburner.simpleopponentstats.md)>> +A dictionary of opponent stats keyed by opponent name. + diff --git a/markdown/bitburner.goanalysis.getvalidmoves.md b/markdown/bitburner.goanalysis.getvalidmoves.md index a05f6a878..e820ae1b5 100644 --- a/markdown/bitburner.goanalysis.getvalidmoves.md +++ b/markdown/bitburner.goanalysis.getvalidmoves.md @@ -14,27 +14,29 @@ Note that the \[0\]\[0\] point is shown on the bottom-left on the visual board ( Also note that, when given a custom board state, only one prior move can be analyzed. This means that the superko rules (no duplicate board states in the full game history) is not supported; you will have to implement your own analysis for that. -playAsWhite is optional, and gets the current valid moves for the white player. Intended to be used when playing as white when the opponent is set to "No AI" +The current valid moves for white can also be seen by simply calling `ns.go.analysis.getValidMoves(true)` . **Signature:** ```typescript -getValidMoves(boardState?: string[], priorBoardState?: string[], playAsWhite = false): boolean[][]; +getValidMoves(boardState?: string[] | boolean, priorBoardState?: string[], playAsWhite?: boolean): boolean[][]; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| boardState | string\[\] | _(Optional)_ | -| priorBoardState | string\[\] | _(Optional)_ | -| playAsWhite | (not declared) | _(Optional)_ | +| boardState | string\[\] \| boolean | _(Optional)_ Optional. The board state to analyze, in the string\[\] format used by getBoardState(). Defaults to the current board state. Alternatively can be simply "true" to get current valid moves for white. | +| priorBoardState | string\[\] | _(Optional)_ Optional. The move before the board state to analyze, in the format used by getBoardState(). Defaults to the current board's prior move state. | +| playAsWhite | boolean | _(Optional)_ Optional. Whether to analyze the board state as if the white player is the current player. Defaults to false. Intended to be used when playing as white when the opponent is set to "No AI". | **Returns:** boolean\[\]\[\] +A 2D array of booleans indicating the validity of each move. + ## Remarks -RAM cost: 8 GB (This is intentionally expensive; you can derive this info from just getBoardState() ) +RAM cost: 8 GB (This is intentionally expensive; you can derive this info from just getBoardState() and getMoveHistory() ) diff --git a/markdown/bitburner.goanalysis.md b/markdown/bitburner.goanalysis.md index f56ef3776..b7490f39e 100644 --- a/markdown/bitburner.goanalysis.md +++ b/markdown/bitburner.goanalysis.md @@ -20,7 +20,7 @@ export interface GoAnalysis | [getControlledEmptyNodes(boardState)](./bitburner.goanalysis.getcontrolledemptynodes.md) |

Returns 'X' for black, 'O' for white, or '?' for each empty point to indicate which player controls that empty point. If no single player fully encircles the empty space, it is shown as contested with '?'. "\#" are dead nodes that are not part of the subnet.

Takes an optional boardState argument; by default uses the current board state.

Filled points of any color are indicated with '.'

In this example, white encircles some space in the top-left, black encircles some in the top-right, and between their routers is contested space in the center:

 \[ "OO..?", "OO.?.", "O.?.X", ".?.XX", "?..X\#", \] 

| | [getLiberties(boardState)](./bitburner.goanalysis.getliberties.md) |

Returns a number for each point, representing how many open nodes its network/chain is connected to. Empty nodes and dead nodes are shown as -1 liberties.

Takes an optional boardState argument; by default uses the current board state.

For example, a 5x5 board might look like this. The chain in the top-left touches 5 total empty nodes, and the one in the center touches four. The group in the bottom-right only has one liberty; it is in danger of being captured!

 \[ \[-1, 5,-1,-1, 2\], \[ 5, 5,-1,-1,-1\], \[-1,-1, 4,-1,-1\], \[ 3,-1,-1, 3, 1\], \[ 3,-1,-1, 3, 1\], \] 

| | [getStats()](./bitburner.goanalysis.getstats.md) |

Displays the game history, captured nodes, and gained bonuses for each opponent you have played against.

The details are keyed by opponent name, in this structure:

 { : { wins: number, losses: number, winStreak: number, highestWinStreak: number, favor: number, bonusPercent: number, bonusDescription: string, } } 

| -| [getValidMoves(boardState, priorBoardState, playAsWhite)](./bitburner.goanalysis.getvalidmoves.md) |

Shows if each point on the board is a valid move for the player. By default, analyzes the current board state. Takes an optional boardState (and an optional prior-move boardState, if desired) to analyze a custom board.

The true/false validity of each move can be retrieved via the X and Y coordinates of the move. const validMoves = ns.go.analysis.getValidMoves();

const moveIsValid = validMoves[x][y];

Note that the \[0\]\[0\] point is shown on the bottom-left on the visual board (as is traditional), and each string represents a vertical column on the board. In other words, the printed example above can be understood to be rotated 90 degrees clockwise compared to the board UI as shown in the IPvGO subnet tab.

Also note that, when given a custom board state, only one prior move can be analyzed. This means that the superko rules (no duplicate board states in the full game history) is not supported; you will have to implement your own analysis for that.

playAsWhite is optional, and gets the current valid moves for the white player. Intended to be used when playing as white when the opponent is set to "No AI"

| +| [getValidMoves(boardState, priorBoardState, playAsWhite)](./bitburner.goanalysis.getvalidmoves.md) |

Shows if each point on the board is a valid move for the player. By default, analyzes the current board state. Takes an optional boardState (and an optional prior-move boardState, if desired) to analyze a custom board.

The true/false validity of each move can be retrieved via the X and Y coordinates of the move. const validMoves = ns.go.analysis.getValidMoves();

const moveIsValid = validMoves[x][y];

Note that the \[0\]\[0\] point is shown on the bottom-left on the visual board (as is traditional), and each string represents a vertical column on the board. In other words, the printed example above can be understood to be rotated 90 degrees clockwise compared to the board UI as shown in the IPvGO subnet tab.

Also note that, when given a custom board state, only one prior move can be analyzed. This means that the superko rules (no duplicate board states in the full game history) is not supported; you will have to implement your own analysis for that.

The current valid moves for white can also be seen by simply calling ns.go.analysis.getValidMoves(true) .

| | [resetStats(resetAll)](./bitburner.goanalysis.resetstats.md) | Reset all win/loss and winstreak records for the No AI opponent. | | [setTestingBoardState(boardState)](./bitburner.goanalysis.settestingboardstate.md) | Starts a new game against the "No AI" opponent, and sets the initial board size, pieces, and offline nodes to the given board state. "X" represent black pieces, "O" white, and "." empty points. "\#" are dead nodes that are not part of the subnet. | diff --git a/markdown/bitburner.goanalysis.resetstats.md b/markdown/bitburner.goanalysis.resetstats.md index ca2512793..3740b52b1 100644 --- a/markdown/bitburner.goanalysis.resetstats.md +++ b/markdown/bitburner.goanalysis.resetstats.md @@ -9,14 +9,14 @@ Reset all win/loss and winstreak records for the No AI opponent. **Signature:** ```typescript -resetStats(resetAll = false): void; +resetStats(resetAll?: boolean): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| resetAll | (not declared) | _(Optional)_ if true, reset win/loss records for all opponents. Leaves node power and bonuses unchanged. | +| resetAll | boolean | _(Optional)_ Optional. if true, reset win/loss records for all opponents. Leaves node power and bonuses unchanged. Defaults to false. | **Returns:** diff --git a/markdown/bitburner.gocheat.destroynode.md b/markdown/bitburner.gocheat.destroynode.md index cf682b65b..d1268f663 100644 --- a/markdown/bitburner.gocheat.destroynode.md +++ b/markdown/bitburner.gocheat.destroynode.md @@ -16,7 +16,7 @@ Warning: if you fail to play a cheat move, your turn will be skipped. After your destroyNode( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -30,7 +30,7 @@ destroyNode( | --- | --- | --- | | x | number | x coordinate of empty node to destroy | | y | number | y coordinate of empty node to destroy | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** diff --git a/markdown/bitburner.gocheat.getcheatcount.md b/markdown/bitburner.gocheat.getcheatcount.md index 437befe6d..04ee578c0 100644 --- a/markdown/bitburner.gocheat.getcheatcount.md +++ b/markdown/bitburner.gocheat.getcheatcount.md @@ -9,19 +9,21 @@ Returns the number of times you've attempted to cheat in the current game. **Signature:** ```typescript -getCheatCount(playAsWhite = false): number; +getCheatCount(playAsWhite?: boolean): number; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** number +The number of times you've attempted to cheat in the current game. + ## Remarks RAM cost: 1 GB Requires BitNode 14.2 to use diff --git a/markdown/bitburner.gocheat.getcheatsuccesschance.md b/markdown/bitburner.gocheat.getcheatsuccesschance.md index bdc037830..a82324b5a 100644 --- a/markdown/bitburner.gocheat.getcheatsuccesschance.md +++ b/markdown/bitburner.gocheat.getcheatsuccesschance.md @@ -11,7 +11,7 @@ Warning: if you fail to play a cheat move, your turn will be skipped. After your **Signature:** ```typescript -getCheatSuccessChance(cheatCount?: number, playAsWhite = false): number; +getCheatSuccessChance(cheatCount?: number, playAsWhite?: boolean): number; ``` ## Parameters @@ -19,12 +19,14 @@ getCheatSuccessChance(cheatCount?: number, playAsWhite = false): number; | Parameter | Type | Description | | --- | --- | --- | | cheatCount | number | _(Optional)_ Optional override for the number of cheats already attempted. Defaults to the number of cheats attempted in the current game. | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** number +Your chance of successfully playing a cheat move. + ## Remarks RAM cost: 1 GB Requires BitNode 14.2 to use diff --git a/markdown/bitburner.gocheat.playtwomoves.md b/markdown/bitburner.gocheat.playtwomoves.md index 59cb21920..4c1383308 100644 --- a/markdown/bitburner.gocheat.playtwomoves.md +++ b/markdown/bitburner.gocheat.playtwomoves.md @@ -18,7 +18,7 @@ playTwoMoves( y1: number, x2: number, y2: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -34,7 +34,7 @@ playTwoMoves( | y1 | number | y coordinate of first move to make | | x2 | number | x coordinate of second move to make | | y2 | number | y coordinate of second move to make | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** diff --git a/markdown/bitburner.gocheat.removerouter.md b/markdown/bitburner.gocheat.removerouter.md index 6872fd9e4..c4ec0ce28 100644 --- a/markdown/bitburner.gocheat.removerouter.md +++ b/markdown/bitburner.gocheat.removerouter.md @@ -16,7 +16,7 @@ Warning: if you fail to play a cheat move, your turn will be skipped. After your removeRouter( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -30,7 +30,7 @@ removeRouter( | --- | --- | --- | | x | number | x coordinate of router to remove | | y | number | y coordinate of router to remove | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** diff --git a/markdown/bitburner.gocheat.repairofflinenode.md b/markdown/bitburner.gocheat.repairofflinenode.md index f8fdc05dd..48060e409 100644 --- a/markdown/bitburner.gocheat.repairofflinenode.md +++ b/markdown/bitburner.gocheat.repairofflinenode.md @@ -16,7 +16,7 @@ Warning: if you fail to play a cheat move, your turn will be skipped. After your repairOfflineNode( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -30,7 +30,7 @@ repairOfflineNode( | --- | --- | --- | | x | number | x coordinate of offline node to repair | | y | number | y coordinate of offline node to repair | -| playAsWhite | (not declared) | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | +| playAsWhite | boolean | _(Optional)_ Optional override for playing as white. Can only be used when playing on a 'No AI' board. | **Returns:** diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index 1d7b6f098..64014e381 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -73,6 +73,7 @@ export const helpers = { positiveSafeInteger, positiveNumber, scriptArgs, + boolean, runOptions, spawnOptions, argsToString, @@ -181,6 +182,14 @@ function scriptArgs(ctx: NetscriptContext, args: unknown) { return args; } +/** Converts the provided value for v to a boolean, throwing if it is not */ +function boolean(ctx: NetscriptContext, argName: string, v: unknown): boolean { + if (typeof v !== "boolean") { + throw errorMessage(ctx, `${argName} must be a boolean, was ${v}`, "TYPE"); + } + return v; +} + function runOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteRunOptions { const result: CompleteRunOptions = { threads: 1 as PositiveInteger, diff --git a/src/NetscriptFunctions/Go.ts b/src/NetscriptFunctions/Go.ts index f23e96e74..feaa8b857 100644 --- a/src/NetscriptFunctions/Go.ts +++ b/src/NetscriptFunctions/Go.ts @@ -33,9 +33,11 @@ import { getEnumHelper } from "../utils/EnumHelper"; import { errorMessage } from "../Netscript/ErrorMessages"; const logger = (ctx: NetscriptContext) => (message: string) => helpers.log(ctx, () => message); -const error = (ctx: NetscriptContext) => (message: string) => { - throw errorMessage(ctx, message); -}; +const error = + (ctx: NetscriptContext) => + (message: string): never => { + throw errorMessage(ctx, message); + }; /** * Go API implementation @@ -44,20 +46,24 @@ export function NetscriptGo(): InternalAPI { return { makeMove: (ctx: NetscriptContext) => - (_x, _y, playAsWhite): Promise => { + (_x, _y, _playAsWhite): Promise => { const x = helpers.number(ctx, "x", _x); const y = helpers.number(ctx, "y", _y); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), x, y, "makeMove", { playAsWhite }); - return makePlayerMove(logger(ctx), error(ctx), x, y, !!playAsWhite); + return makePlayerMove(logger(ctx), error(ctx), x, y, playAsWhite); }, passTurn: (ctx: NetscriptContext) => - (playAsWhite): Promise => { + (_playAsWhite): Promise => { + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), -1, -1, "passTurn", { playAsWhite, pass: true }); - return handlePassTurn(logger(ctx), !!playAsWhite); + return handlePassTurn(logger(ctx), playAsWhite); }, - opponentNextTurn: (ctx: NetscriptContext) => async (logOpponentMove, playAsWhite) => { - return getOpponentNextMove(logger(ctx), !!logOpponentMove, !!playAsWhite); + opponentNextTurn: (ctx: NetscriptContext) => async (_logOpponentMove, _playAsWhite) => { + const logOpponentMove = helpers.boolean(ctx, "logOpponentMove", _logOpponentMove ?? false); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); + return getOpponentNextMove(logger(ctx), logOpponentMove, playAsWhite); }, getBoardState: () => () => { return simpleBoardFromBoard(Go.currentGame.board); @@ -81,9 +87,13 @@ export function NetscriptGo(): InternalAPI { return resetBoardState(logger(ctx), error(ctx), opponent, boardSize); }, analysis: { - getValidMoves: (ctx) => (_boardState, _priorBoardState, playAsWhite) => { + getValidMoves: (ctx) => (_boardState, _priorBoardState, _playAsWhite) => { + if (_boardState == true) { + return getValidMoves(undefined, true); + } + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); const State = validateBoardState(error(ctx), _boardState, _priorBoardState); - return getValidMoves(State, !!playAsWhite); + return getValidMoves(State, playAsWhite); }, getChains: (ctx) => (_boardState) => { const State = validateBoardState(error(ctx), _boardState); @@ -101,9 +111,10 @@ export function NetscriptGo(): InternalAPI { return getStats(); }, resetStats: - () => - (resetAll = false) => { - resetStats(!!resetAll); + (ctx) => + (_resetAll = false) => { + const resetAll = helpers.boolean(ctx, "resetAll", _resetAll ?? false); + resetStats(resetAll); }, setTestingBoardState: (ctx) => (_boardState, _komi) => { const State = validateBoardState(error(ctx), _boardState); @@ -116,23 +127,26 @@ export function NetscriptGo(): InternalAPI { }, }, cheat: { - getCheatSuccessChance: (ctx: NetscriptContext) => (_cheatCount, playAsWhite) => { + getCheatSuccessChance: (ctx: NetscriptContext) => (_cheatCount, _playAsWhite) => { checkCheatApiAccess(error(ctx)); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); const normalizedCheatCount = _cheatCount ?? (playAsWhite ? Go.currentGame.cheatCountForWhite : Go.currentGame.cheatCount); const cheatCount = helpers.number(ctx, "cheatCount", normalizedCheatCount); - return cheatSuccessChance(cheatCount, !!playAsWhite); + return cheatSuccessChance(cheatCount, playAsWhite); }, - getCheatCount: (ctx: NetscriptContext) => (playAsWhite) => { + getCheatCount: (ctx: NetscriptContext) => (_playAsWhite) => { checkCheatApiAccess(error(ctx)); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); return playAsWhite ? Go.currentGame.cheatCountForWhite : Go.currentGame.cheatCount; }, removeRouter: (ctx: NetscriptContext) => - (_x, _y, playAsWhite): Promise => { + (_x, _y, _playAsWhite): Promise => { checkCheatApiAccess(error(ctx)); const x = helpers.number(ctx, "x", _x); const y = helpers.number(ctx, "y", _y); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), x, y, "removeRouter", { emptyNode: false, requireNonEmptyNode: true, @@ -141,14 +155,15 @@ export function NetscriptGo(): InternalAPI { playAsWhite: playAsWhite, }); - return cheatRemoveRouter(logger(ctx), error(ctx), x, y, undefined, undefined, !!playAsWhite); + return cheatRemoveRouter(logger(ctx), error(ctx), x, y, undefined, undefined, playAsWhite); }, playTwoMoves: (ctx: NetscriptContext) => - (_x1, _y1, _x2, _y2, playAsWhite): Promise => { + (_x1, _y1, _x2, _y2, _playAsWhite): Promise => { checkCheatApiAccess(error(ctx)); const x1 = helpers.number(ctx, "x", _x1); const y1 = helpers.number(ctx, "y", _y1); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), x1, y1, "playTwoMoves", { repeat: false, suicide: false, @@ -162,14 +177,15 @@ export function NetscriptGo(): InternalAPI { playAsWhite, }); - return cheatPlayTwoMoves(logger(ctx), error(ctx), x1, y1, x2, y2, undefined, undefined, !!playAsWhite); + return cheatPlayTwoMoves(logger(ctx), error(ctx), x1, y1, x2, y2, undefined, undefined, playAsWhite); }, repairOfflineNode: (ctx: NetscriptContext) => - (_x, _y, playAsWhite): Promise => { + (_x, _y, _playAsWhite): Promise => { checkCheatApiAccess(error(ctx)); const x = helpers.number(ctx, "x", _x); const y = helpers.number(ctx, "y", _y); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), x, y, "repairOfflineNode", { emptyNode: false, repeat: false, @@ -179,14 +195,15 @@ export function NetscriptGo(): InternalAPI { playAsWhite, }); - return cheatRepairOfflineNode(logger(ctx), x, y, undefined, undefined, !!playAsWhite); + return cheatRepairOfflineNode(logger(ctx), x, y, undefined, undefined, playAsWhite); }, destroyNode: (ctx: NetscriptContext) => - (_x, _y, playAsWhite): Promise => { + (_x, _y, _playAsWhite): Promise => { checkCheatApiAccess(error(ctx)); const x = helpers.number(ctx, "x", _x); const y = helpers.number(ctx, "y", _y); + const playAsWhite = helpers.boolean(ctx, "playAsWhite", _playAsWhite ?? false); validateMove(error(ctx), x, y, "destroyNode", { repeat: false, onlineNode: true, @@ -194,7 +211,7 @@ export function NetscriptGo(): InternalAPI { playAsWhite, }); - return cheatDestroyNode(logger(ctx), x, y, undefined, undefined, !!playAsWhite); + return cheatDestroyNode(logger(ctx), x, y, undefined, undefined, playAsWhite); }, }, }; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index a1ffec3f3..690003d74 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4384,13 +4384,18 @@ export interface GoAnalysis { * Also note that, when given a custom board state, only one prior move can be analyzed. This means that the superko rules * (no duplicate board states in the full game history) is not supported; you will have to implement your own analysis for that. * - * playAsWhite is optional, and gets the current valid moves for the white player. Intended to be used when playing as white when the opponent is set to "No AI" + * The current valid moves for white can also be seen by simply calling `ns.go.analysis.getValidMoves(true)` . * * @remarks * RAM cost: 8 GB - * (This is intentionally expensive; you can derive this info from just getBoardState() ) + * (This is intentionally expensive; you can derive this info from just getBoardState() and getMoveHistory() ) + * + * @param boardState - Optional. The board state to analyze, in the string[] format used by getBoardState(). Defaults to the current board state. Alternatively can be simply "true" to get current valid moves for white. + * @param priorBoardState - Optional. The move before the board state to analyze, in the format used by getBoardState(). Defaults to the current board's prior move state. + * @param playAsWhite - Optional. Whether to analyze the board state as if the white player is the current player. Defaults to false. Intended to be used when playing as white when the opponent is set to "No AI". + * @returns A 2D array of booleans indicating the validity of each move. */ - getValidMoves(boardState?: string[], priorBoardState?: string[], playAsWhite = false): boolean[][]; + getValidMoves(boardState?: string[] | boolean, priorBoardState?: string[], playAsWhite?: boolean): boolean[][]; /** * Returns an ID for each point. All points that share an ID are part of the same network (or "chain"). Empty points @@ -4416,6 +4421,9 @@ export interface GoAnalysis { * RAM cost: 16 GB * (This is intentionally expensive; you can derive this info from just getBoardState() ) * + * @param boardState - Optional. The current board state, as an array of strings. Defaults to the current board state. + * @returns A 2D array of numbers identifying the chain ID of each point. + * */ getChains(boardState?: string[]): (number | null)[][]; @@ -4440,6 +4448,9 @@ export interface GoAnalysis { * @remarks * RAM cost: 16 GB * (This is intentionally expensive; you can derive this info from just getBoardState() ) + * + * @param boardState - Optional. The current board state, as an array of strings. Defaults to the current board state. + * @returns A 2D array of numbers counting the liberties of each point. */ getLiberties(boardState?: string[]): number[][]; @@ -4466,6 +4477,9 @@ export interface GoAnalysis { * @remarks * RAM cost: 16 GB * (This is intentionally expensive; you can derive this info from just getBoardState() ) + * + * @param boardState - Optional. The current board state, as an array of strings. Defaults to the current board state. + * @returns A 2D array of characters indicating the player who controls each empty point. */ getControlledEmptyNodes(boardState?: string[]): string[]; @@ -4487,14 +4501,16 @@ export interface GoAnalysis { * } * } * + * + * @returns A dictionary of opponent stats keyed by opponent name. */ getStats(): Partial>; /** * Reset all win/loss and winstreak records for the No AI opponent. - * @param resetAll if true, reset win/loss records for all opponents. Leaves node power and bonuses unchanged. + * @param resetAll - Optional. if true, reset win/loss records for all opponents. Leaves node power and bonuses unchanged. Defaults to false. */ - resetStats(resetAll = false): void; + resetStats(resetAll?: boolean): void; /** * Starts a new game against the "No AI" opponent, and sets the initial board size, pieces, and offline nodes to the given board state. @@ -4523,23 +4539,26 @@ export interface GoCheat { * Warning: if you fail to play a cheat move, your turn will be skipped. After your first cheat attempt, if you fail, there is a * small (~10%) chance you will instantly be ejected from the subnet. * + * @remarks + * RAM cost: 1 GB + * Requires BitNode 14.2 to use + * * @param cheatCount - Optional override for the number of cheats already attempted. Defaults to the number of cheats attempted in the current game. * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. - * - * @remarks - * RAM cost: 1 GB - * Requires BitNode 14.2 to use + * @returns Your chance of successfully playing a cheat move. */ - getCheatSuccessChance(cheatCount?: number, playAsWhite = false): number; + getCheatSuccessChance(cheatCount?: number, playAsWhite?: boolean): number; /** * Returns the number of times you've attempted to cheat in the current game. - * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. * * @remarks * RAM cost: 1 GB * Requires BitNode 14.2 to use + * + * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. + * @returns The number of times you've attempted to cheat in the current game. */ - getCheatCount(playAsWhite = false): number; + getCheatCount(playAsWhite?: boolean): number; /** * Attempts to remove an existing router, leaving an empty node behind. * @@ -4548,21 +4567,19 @@ export interface GoCheat { * Warning: if you fail to play a cheat move, your turn will be skipped. After your first cheat attempt, if you fail, there is a * small (~10%) chance you will instantly be ejected from the subnet. * - * - * @param x - x coordinate of router to remove - * @param y - y coordinate of router to remove - * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. - * * @remarks * RAM cost: 8 GB * Requires BitNode 14.2 to use * + * @param x - x coordinate of router to remove + * @param y - y coordinate of router to remove + * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ removeRouter( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4577,17 +4594,15 @@ export interface GoCheat { * Warning: if you fail to play a cheat move, your turn will be skipped. After your first cheat attempt, if you fail, there is a * small (~10%) chance you will instantly be ejected from the subnet. * + * @remarks + * RAM cost: 8 GB + * Requires BitNode 14.2 to use * * @param x1 - x coordinate of first move to make * @param y1 - y coordinate of first move to make * @param x2 - x coordinate of second move to make * @param y2 - y coordinate of second move to make * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. - * - * @remarks - * RAM cost: 8 GB - * Requires BitNode 14.2 to use - * * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ playTwoMoves( @@ -4595,7 +4610,7 @@ export interface GoCheat { y1: number, x2: number, y2: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4610,20 +4625,19 @@ export interface GoCheat { * Warning: if you fail to play a cheat move, your turn will be skipped. After your first cheat attempt, if you fail, there is a * small (~10%) chance you will instantly be ejected from the subnet. * - * @param x - x coordinate of offline node to repair - * @param y - y coordinate of offline node to repair - * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. - * * @remarks * RAM cost: 8 GB * Requires BitNode 14.2 to use * + * @param x - x coordinate of offline node to repair + * @param y - y coordinate of offline node to repair + * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ repairOfflineNode( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4639,20 +4653,19 @@ export interface GoCheat { * Warning: if you fail to play a cheat move, your turn will be skipped. After your first cheat attempt, if you fail, there is a * small (~10%) chance you will instantly be ejected from the subnet. * - * @param x - x coordinate of empty node to destroy - * @param y - y coordinate of empty node to destroy - * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. - * * @remarks * RAM cost: 8 GB * Requires BitNode 14.2 to use * + * @param x - x coordinate of empty node to destroy + * @param y - y coordinate of empty node to destroy + * @param playAsWhite - Optional override for playing as white. Can only be used when playing on a 'No AI' board. * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ destroyNode( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4669,17 +4682,18 @@ export interface Go { * Make a move on the IPvGO subnet game board, and await the opponent's response. * x:0 y:0 represents the bottom-left corner of the board in the UI. * - * playAsWhite is optional, and attempts to make a move as the white player. Only can be used when playing against "No AI". - * * @remarks * RAM cost: 4 GB * + * @param x - x coordinate of move to make + * @param y - y coordinate of move to make + * @param playAsWhite - optional. If true, attempts to play as white and then wait for black's move. Can only be used when playing as white when the opponent is set to "No AI" * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ makeMove( x: number, y: number, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4693,15 +4707,14 @@ export interface Go { * This can also be used if you pick up the game in a state where the opponent needs to play next. For example: if BitBurner was * closed while waiting for the opponent to make a move, you may need to call passTurn() to get them to play their move on game start. * - * passAsWhite is optional, and attempts to pass while playing as the white player. Only can be used when playing against "No AI". - * - * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended - * * @remarks * RAM cost: 0 GB * + * @param passAsWhite - optional. If true, attempts to pass as white and then wait for black's move. Only can be used when playing against "No AI". + * @returns a promise that contains the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended + * */ - passTurn(passAsWhite = false): Promise<{ + passTurn(passAsWhite?: boolean): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; y: number | null; @@ -4711,17 +4724,16 @@ export interface Go { * Returns a promise that resolves with the success or failure state of your last move, and the AI's response, if applicable. * x:0 y:0 represents the bottom-left corner of the board in the UI. * - * @param logOpponentMove - optional, defaults to true. if false prevents logging opponent move - * @param playAsWhite - optional. If true, waits to get the next move the black player makes. Intended to be used when playing as white when the opponent is set to "No AI" - * * @remarks * RAM cost: 0 GB * + * @param logOpponentMove - optional, defaults to true. if false prevents logging opponent move + * @param playAsWhite - optional. If true, waits to get the next move the black player makes. Intended to be used when playing as white when the opponent is set to "No AI" * @returns a promise that contains if your last move was valid and successful, the opponent move's x and y coordinates (or pass) in response, or an indication if the game has ended */ opponentNextTurn( logOpponentMove?: boolean, - playAsWhite = false, + playAsWhite?: boolean, ): Promise<{ type: "move" | "pass" | "gameOver"; x: number | null; @@ -4799,15 +4811,14 @@ export interface Go { * Gets new IPvGO subnet with the specified size owned by the listed faction, ready for the player to make a move. * This will reset your win streak if the current game is not complete and you have already made moves. * - * * Note that some factions will have a few routers already on the subnet after a reset. * - * opponent is "Netburners" or "Slum Snakes" or "The Black Hand" or "Tetrads" or "Daedalus" or "Illuminati" or "????????????" or "No AI", - * - * @returns a simplified version of the board state as an array of strings representing the board columns. See ns.Go.getBoardState() for full details - * * @remarks * RAM cost: 0 GB + * + * @param opponent - The opponent faction to play against. "Netburners" | "Slum Snakes" | "The Black Hand" | "Tetrads" | "Daedalus" | "Illuminati" | "????????????" | "No AI" + * @param boardSize - The size of the board to play on. Must be 5, 7, 9, or 13. + * @returns a simplified version of the board state as an array of strings representing the board columns. See ns.Go.getBoardState() for full details */ resetBoardState(opponent: GoOpponent, boardSize: 5 | 7 | 9 | 13): string[] | undefined;