tictactoe-random
v1.4.1
Published
A Tic Tac Toe Random Algorithm NPM module in typescript to find random index on a given board
Downloads
3
Maintainers
Readme
Tic Tac Toe Random
A Tic Tac Toe Random Algorithm NPM module in typescript to find random index on a given board
NPM Package
Installation
Random Module
npm install tictactoe-random --save
Board Module
npm install tictactoe-board --save
Usage
import Random from 'tictactoe-random'
import Board from 'tictactoe-board'
Intialize an instance object of the Random and Board
const board = new Board();
const random = new Random(board);
You can pass in an optional
custom Array of Strings as parameter to the Board
Example:
board = new Board(['X', 'X', '', '', 'O', 'O', '', '', ''])
now board.grid = ['X', 'X', '', '', 'O', 'O', '', '', '']
instead of default grid = ['', '', '', '', '', '', '', '', '']
Method
random.findRandomMove(board)
This returns a random index of the given board
Example sceenerio:
const baord = new Board();
random.findRandomMove(board) = random index
This means position on the board is a random index from the available board index's