Ninjas Practicing Multidimensionality

npm

Need private packages and team management tools?Check out npm Orgs. »

tttai

0.0.3 • Public • Published

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'
])
// true

tttai.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

Keywords

install

npm i tttai

Downloadsweekly downloads

1

version

0.0.3

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability