1.0.1-ab • Published 5 years ago
basic-tictactoe v1.0.1-ab
Simple TicTacToe
this is a simple tic tac toe npm module
Installation
npm i basic-tictactoe
Documentation
using the module
const ttt = require("basic-tictactoe");
var game = new ttt();
/*
the constructor also can receive an optional design object
default:
{
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
"X": "X",
"O": "O"
}
*/
initializing the variable
var player = true;
var gameBoard = game.init(); //game.init returns board array [0,1,2,3...,8]
rendering the board
console.log(game.render()); // render output a string eg 123\n456\n...
marking the o or x;
const { state, board, render } = game.move(
gameBoard,
game.getPlayer(player),
move
);
/*
game.getPlayer(player)
returns "X" if player is true or "O" if player is false
state
-1 = tie
0 = normal
1 = wins
2 = illegal move
move
follow the displayed number on the render not the index of the array
*/
reseting the board
gameBoard = game.init(); //game.init returns board array [0,1,2,3...,8]