diff --git a/types/tictactoejs/index.d.ts b/types/tictactoejs/index.d.ts new file mode 100644 index 0000000000..7bab95ae6b --- /dev/null +++ b/types/tictactoejs/index.d.ts @@ -0,0 +1,80 @@ +// Type definitions for tictactoejs 1.0 +// Project: https://www.npmjs.com/package/tictactoejs +// Definitions by: VenNeptury +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class TicTacToe { + /** + * The game's constructor + */ + constructor(requestSize?: number); + /** + * Restart the game + */ + reset(requestSize?: number): void; + /** + * Get the current game's size + * @returns the game size + */ + getSize(): number; + /** + * Check, whether it's X' turn or O's + * @returns whose turn it is + */ + turn(): "X" | "O"; + /** + * Get the current board + * @returns the current board as ascii + */ + ascii(): string; + /** + * Get the current board + * @returns the current board as ascii (alternative style) + */ + ascii2(): string; + /** + * Does a move (bottom left is 1|1, bottom right is 3|1) + * @returns whether the move was successful + */ + move(x: number, y: number): boolean; + /** + * Check whether the provided coordinates exist on the current board + * @returns whether the current coordinates exist + */ + exists(x: number, y: number): boolean; + /** + * Check which player occupies the provided coordinates + * @returns the player occupying these coordinates + */ + get(x: number, y: number): "X" | "O" | null; + /** + * Do a move with array style coordinates (top left is 0|0, top right is 0|2) + * @returns whether the move was successful + */ + moveArray(row: number, col: number): boolean; + /** + * Check the game's current state + * @returns the game state + */ + status(): "X" | "O" | "draw" | "in progress"; + /** + * Check whether the game is over + * @returns the game state + */ + gameOver(): boolean; + /** + * Check whether the game ended in a draw + * @returns the game state + */ + isDraw(): boolean; + /** + * Check the valid moves (all unoccupied coordinates) + * @returns an array of objects with the x and y values + */ + legalMoves(): [{ x: number; y: number }]; + /** + * Do a random move (no logic or AI involved, this is completely random) + * @returns an object with the x and y value of the random move + */ + randomMove(): { x: number; y: number }; +} diff --git a/types/tictactoejs/tictactoejs-tests.ts b/types/tictactoejs/tictactoejs-tests.ts new file mode 100644 index 0000000000..50bc44a17d --- /dev/null +++ b/types/tictactoejs/tictactoejs-tests.ts @@ -0,0 +1,18 @@ +import { TicTacToe } from "tictactoejs"; + +const game = new TicTacToe(3); + +game.reset(3); +game.getSize(); +game.turn(); +game.ascii(); +game.ascii2(); +game.move(1, 1); +game.exists(1, 1); +game.get(1, 1); +game.moveArray(0, 0); +game.status(); +game.gameOver(); +game.isDraw(); +game.legalMoves(); +game.randomMove(); diff --git a/types/tictactoejs/tsconfig.json b/types/tictactoejs/tsconfig.json new file mode 100644 index 0000000000..3088ec0c91 --- /dev/null +++ b/types/tictactoejs/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tictactoejs-tests.ts" + ] +} diff --git a/types/tictactoejs/tslint.json b/types/tictactoejs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tictactoejs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }