0.0.3 • Published 7 years ago
tttai v0.0.3
tttai
Get informations about a tic-tac-toe game.
Installation
Install it with npm or yarn.
You can try:
npm install tttai- ...or
yarn add tttai
Usage
var tttai = require('tttai')This will be an object with some methods:
.isFinish(state).getNextState(player, state).whoWon(state)
tttai.isFinish(state)
It will check if a game already is finished.
See the example:
tttai.isFinish([
'x', null, 'o',
'o', 'x', null,
null, 'o', 'x'
])
// truetttai.getNextState(player, state)
It will return the next state of the game for a player.
See the example:
tttai.getNextState('x', [
'x', null, 'o',
'o', null, null,
null, 'o', 'x'
])
// [
// 'x', null, 'o',
// 'o', 'x', null,
// null, 'o', 'x'
// ]tttai.whoWon(state)
It will return the winner of the game.
NOTE: if have a draw, it will return null.
See the example:
tttai.whoWon([
'x', null, 'o',
'o', 'x', null,
null, 'o', 'x'
])
// 'x'License
MIT © Matheus Alves