mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-08 08:43:53 +01:00
IPVGO: Add history, and details to status, to go API (#1348)
This commit is contained in:
parent
30a6419b11
commit
cf48d666f5
@ -612,6 +612,15 @@ export function boardStringFromBoard(board: Board): string {
|
||||
* ```
|
||||
*/
|
||||
export function boardFromBoardString(boardString: string): Board {
|
||||
const simpleBoardArray = simpleBoardFromBoardString(boardString);
|
||||
|
||||
return boardFromSimpleBoard(simpleBoardArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slices a string representation of a board into an array of strings representing the rows on the board
|
||||
*/
|
||||
export function simpleBoardFromBoardString(boardString: string): SimpleBoard {
|
||||
// Turn the SimpleBoard string into a string array, allowing access of each point via indexes e.g. [0][1]
|
||||
const boardSize = Math.round(Math.sqrt(boardString.length));
|
||||
const boardTiles = boardString.split("");
|
||||
@ -621,7 +630,7 @@ export function boardFromBoardString(boardString: string): Board {
|
||||
.fill("")
|
||||
.map((_, index) => boardTiles.slice(index * boardSize, (index + 1) * boardSize).join(""));
|
||||
|
||||
return boardFromSimpleBoard(simpleBoardArray);
|
||||
return simpleBoardArray;
|
||||
}
|
||||
|
||||
/** Creates a board object from a simple board. The resulting board has no analytics (liberties/chains) */
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Play, SimpleOpponentStats } from "../Types";
|
||||
import { Play, SimpleBoard, SimpleOpponentStats } from "../Types";
|
||||
|
||||
import { Player } from "@player";
|
||||
import { AugmentationName, GoColor, GoOpponent, GoPlayType, GoValidity } from "@enums";
|
||||
@ -10,6 +10,7 @@ import {
|
||||
getControlledSpace,
|
||||
getPreviousMove,
|
||||
simpleBoardFromBoard,
|
||||
simpleBoardFromBoardString,
|
||||
} from "../boardAnalysis/boardAnalysis";
|
||||
import { endGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
|
||||
import { WHRNG } from "../../Casino/RNG";
|
||||
@ -223,6 +224,8 @@ export function getControlledEmptyNodes() {
|
||||
* 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.
|
||||
*
|
||||
* Also provides the white player's komi (bonus starting score), and the amount of bonus cycles from offline time remaining
|
||||
*/
|
||||
export function getGameState() {
|
||||
const currentPlayer = getCurrentPlayer();
|
||||
@ -234,9 +237,15 @@ export function getGameState() {
|
||||
whiteScore: score[GoColor.white].sum,
|
||||
blackScore: score[GoColor.black].sum,
|
||||
previousMove,
|
||||
komi: score[GoColor.white].komi,
|
||||
bonusCycles: Go.storedCycles,
|
||||
};
|
||||
}
|
||||
|
||||
export function getMoveHistory(): SimpleBoard[] {
|
||||
return Go.currentGame.previousBoards.map((boardString) => simpleBoardFromBoardString(boardString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'None' if the game is over, otherwise returns the color of the current player's turn
|
||||
*/
|
||||
|
@ -250,6 +250,7 @@ const go = {
|
||||
makeMove: 4,
|
||||
passTurn: 0,
|
||||
getBoardState: 4,
|
||||
getMoveHistory: 0,
|
||||
getCurrentPlayer: 0,
|
||||
getGameState: 0,
|
||||
getOpponent: 0,
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
getCurrentPlayer,
|
||||
getGameState,
|
||||
getLiberties,
|
||||
getMoveHistory,
|
||||
getOpponentNextMove,
|
||||
getStats,
|
||||
getValidMoves,
|
||||
@ -58,6 +59,9 @@ export function NetscriptGo(): InternalAPI<NSGo> {
|
||||
getBoardState: () => () => {
|
||||
return simpleBoardFromBoard(Go.currentGame.board);
|
||||
},
|
||||
getMoveHistory: () => () => {
|
||||
return getMoveHistory();
|
||||
},
|
||||
getCurrentPlayer: () => () => {
|
||||
return getCurrentPlayer();
|
||||
},
|
||||
|
17
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
17
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4049,6 +4049,21 @@ export interface Go {
|
||||
*/
|
||||
getBoardState(): string[];
|
||||
|
||||
/**
|
||||
* 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:
|
||||
*
|
||||
* [<br/>
|
||||
* "XX.O.",<br/>
|
||||
* "X..OO",<br/>
|
||||
* ".XO..",<br/>
|
||||
* "XXO.#",<br/>
|
||||
* ".XO.#",<br/>
|
||||
* ]
|
||||
*/
|
||||
getMoveHistory(): string[][];
|
||||
|
||||
/**
|
||||
* Returns the color of the current player, or 'None' if the game is over.
|
||||
* @returns "White" | "Black" | "None"
|
||||
@ -4065,6 +4080,8 @@ export interface Go {
|
||||
whiteScore: number;
|
||||
blackScore: number;
|
||||
previousMove: [number, number] | null;
|
||||
komi: number;
|
||||
bonusCycles: number;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -104,6 +104,8 @@ describe("Netscript Go API unit tests", () => {
|
||||
whiteScore: 6.5,
|
||||
blackScore: 6,
|
||||
previousMove: [0, 2],
|
||||
bonusCycles: 0,
|
||||
komi: 5.5,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user