UNPKG

@rbxts/tic-tac-toe

Version:

Modular tic-tac-toe without dependencies, because why not.

95 lines (94 loc) 3.01 kB
/// <reference types="@rbxts/compiler-types" /> import { TicTacToeState } from "./enum/TicTacToeState"; import { TicTacToeCell } from "./TicTacToeCell"; import { TicTacToeMove } from "./TicTacToeMove"; /** * The representation of a TicTacToe board. */ export declare class TicTacToeBoard { /** The array representation of the board cells. */ private board; /** * Constructs a new TicTacToeBoard with the given cells. * * @param board The cells to use, these will be copied. */ constructor(board?: TicTacToeCell[]); /** * Returns the cell at the specified coordinates. * * @param row The row of the cell. * @param col The column of the cell. * @returns The cell at the specified coordinates. */ getCell(row: number, col: number): TicTacToeCell | undefined; /** * Returns the cells of the specified row. * * @param row The row to get the cells of. * @returns The cells of the specified row. */ getRow(row: number): TicTacToeCell[]; /** * Returns the cells of the specified column. * * @param col The column to get the cells of. * @returns The cells of the specified column. */ getCol(col: number): TicTacToeCell[]; /** * Returns the cells of the left to right diagonal. */ getFirstDiagonal(): TicTacToeCell[]; /** * Returns the cells of the right to left diagonal. */ getSecondDiagonal(): TicTacToeCell[]; /** * Inserts the specified cell into the board. * This will overwrite any existing cell with the * same coordinates. * * @param cell The cell to insert. */ setCell(cell: TicTacToeCell): void; /** * Runs over the board and checks if any state conditions are met. * If a win state is met, the state is returned with the winning cells. * Otherwise the state is returned with undefined. * * This checks in the order of rows (top to bottom), columns (left to right), diagonals (first then second). * * @returns The state of the game and the winning cells if applicable. */ getCurrentState(): [ Exclude<TicTacToeState, TicTacToeState.CANCELLED>, TicTacToeCell[] | undefined ]; /** * Returns the cells on the board that are empty. */ getEmptyCells(): TicTacToeCell[]; /** * Returns whether all the cells on the board are empty. */ isEmpty(): boolean; /** * Returns whether all the cells on the board are full. */ isFull(): boolean; /** * Returns whether the specified move is valid. * * @param move The move to check. */ isValidMove(move: TicTacToeMove): boolean; /** * Returns the cells of the board. */ getCells(): TicTacToeCell[]; /** * Returns a board with all the cells empty. */ static empty(): TicTacToeCell[]; }