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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i tttai

      Weekly Downloads

      1

      Version

      0.0.3

      License

      MIT

      Unpacked Size

      5.81 kB

      Total Files

      4

      Last publish

      Collaborators

      • theuves