1.0.4 • Published 4 years ago

tictactoe_model v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Tic Tac Toe Model

Copyright (c) 2019 Seán D. Murray SEE MIT LICENSE FILE

A logical model playing the tic-tac-toe (naughts & crosses, Xs & Os) game.

Usage

const TicTacToe = require('tictactoe_model');
const ticTacToe = new TicTacToe();

// Get whoes turn it is.
ticTacToe.turn();

// Make a move.
ticTacToe.move(0, 0); // X played
ticTacToe.move(1, 0);// O played
ticTacToe.move(0, 1);// X played

ticTacToe.turn(); // returns O

// Is the game done?
ticTacToe.isDone(); // returns false.

ticTacToe.move(1, 1);// O played
ticTacToe.move(0, 2);// X played
ticTacToe.move(2, 2);// O played

// Get the value at this coordinate.
ticTacToe.value(2, 2);// returns O

ticTacToe.isDone(); // returns true.

// Retrrns who the winner is.
ticTacToe.winner(); // returns player O