npm.io
1.0.3 • Published 8 years ago

tic-tac-toe-playing-algorithms

Licence
MIT
Version
1.0.3
Deps
0
Size
5 kB
Vulns
0
Weekly
0

Tic Tac Toe Playing Algorithms

An implementation of various algorithms for playing a 3x3 tic tac toe game.

The algorithms includes:

  • Minimax

Usage

ES5:

var minimax = require ('tic-tac-toe-playing-algorithms').minimax;

var myPlayer = 'X';
var otherPlayer = 'O';
var currentPlayer = myPlayer;

var board = [
	[0, 0, 0],
	[0, 0, 0],
	[0, 0, 0]
];

var nextMove = minimax(board, currentPlayer, myPlayer, otherPlayer);

console.log(nextMove);

ES6:

import { minimax } from 'tic-tac-toe-playing-algorithms';

const myPlayer = 'X';
const otherPlayer = 'O';
const currentPlayer = myPlayer;

const board = [
	[0, 0, 0],
	[0, 0, 0],
	[0, 0, 0]
];

const nextMove = minimax(board, currentPlayer, myPlayer, otherPlayer);

console.log(nextMove);