Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tic-tac-toe-ai-engine with all npm packages installed. Try it out:

var ticTacToeAiEngine = require("tic-tac-toe-ai-engine")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tic-tac-toe-ai-engine v1.0.9

Agnostic Tic Tac Toe game engine. Should be able to plug into any javascript program and provide a simple Tic Tac Toe AI API.

Build Status Build Status

tic-tac-toe-ai-engine

Stateless Tic Tac Toe engine. Given a position the engine will give next best move, winner given perfect play, and the number of moves left with perfect play.

Test in browser

Tic Tac Toe AI Engine in Runkit

Example:

var ticTacToeAiEngine = require("tic-tac-toe-ai-engine");

var gameState = ['X', '', '', 'O', '', '', 'X', 'O', ''];
console.log(ticTacToeAiEngine.computeMove(gameState));

/*
Output:
  { winner: 'X',
    depth: 3,
    nextBestGameState: [ 'X', '', 'X', 'O', '', '', 'X', 'O', '' ] }
*/
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free