ttt-minimax-typescript
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

Tic Tac Toe Minimax

A Tic Tac Toe Minimax Algorithm module in typescript to find best move on a given board

Node.js CI

Installation

Minimax Module

npm install ttt-minimax-typescript --save

Board Module

npm install ttt-minimax-typescript --save

Usage

import Minimax from ttt-minimax-typescript

import Board from tictactoe-board

Intialize an instance object of the Minimax and Board

const board = new Board();

const minimax = new Minimax(currentPlayer: string, opponent: string);
Example:

const minimax = new Minimax('X, 'O);

You can pass in an optional custom Array of Strings as parameter to the Board

Example:
 
board = new Board(['X', 'X', '', '', 'O', 'O', '', '', ''])

now board.grid = ['X', 'X', '', '', 'O', 'O', '', '', '']

instead of default grid = ['', '', '', '', '', '', '', '', '']

Methods

minimax.findBestMove(board)

This returns the best winning index of the given board

Example sceenerio:

const baord = new Board();

minimax.findBestMove(board) = ['X', '', '', '', '', '', '', '', ''] = 1

That means position one is the best optimal position for the opponent to pick

Package Sidebar

Install

npm i ttt-minimax-typescript

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

15.4 kB

Total Files

12

Last publish

Collaborators

  • chokonaira