ultimate-tic-tac-toe
A client and react component for the Ultimate Tic Tac Toe game. Includes Mist, a strong AI I built for the game.
Last updated a year ago by alexeidarmin .
MIT · Original npm · Tarball · package.json
$ cnpm install ultimate-tic-tac-toe 
SYNC missed versions from official npm registry.

Ultimate Tic Tac Toe

A client and react component for the Ultimate Tic Tac Toe game. Includes Mist, a strong AI I built for the game.

midgame v0.1.0

Try the Demo

Installation

npm i ultimate-tic-tac-toe

Usage

To import and render the react component, note all props are optional and the TicTacToe component takes no props:

import { UltimateTicTacToe, TicTacToe } from 'ultimate_tic_tic_toe';

class App extends React.Component {

  render() {
    return <div>
      <UltimateTicTacToe 
      playerOne="human" 
      playerTwo="bot_level_two" 
      loopGame={true} 
      moveDelay={50}
    />
    <TicTacToe />
    </div>
  }
}
Prop Data type Default value Values available Additional information
playerOne string 'human' 'human', 'bot_level_zero', 'bot_level_one', 'bot_level_two' The higher the level the higher the skill of the bot
playerTwo string 'human' 'human', 'bot_level_zero', 'bot_level_one', 'bot_level_two' The higher the level the higher the skill of the bot
loopGame boolean false true, false Resets the game once it's complete, useful for comparing bots over many games
moveDelay number 1000 A number in milliseconds Represents the time between bot moves

To import and run the client only:

import { Game } from 'ultimate-tic-tac-toe'
const game = new Game()

while (!game.isGameOver()) {
  const moves = game.getMoves()
  const move = moves[Math.floor(Math.random() * moves.length)];
  game.move(move)
}
console.log(game.print());

API

.move(index)

Attempts to make a move to the specificed index, a number between 0 - 80. Returns true upon success.

.getMoves()

Returns an array of numbers representing the cells where the current player can move.

game.getMoves() // -> [0, 2, 3, 11, 13]

getMoveCount()

Returns a number representing the number of moves that have been played in the current game.

game.getMoveCount() // -> 5 

getMoveFromBot({ skill })

Takes an object with a skill attribute which is a number, currently 0 or 1. Runs a bot of that skill level on the current game position and returns a move suggestion by that bot.

game.getMoveFromBot({ skill: 1 }) // -> 17

.getBoard()

Returns the current board state as an array of length 81. 0s represet empty cells. 1s represent cells where player_one has moved. 2s represent where player_two has moved.

game.getBoard() // -> [1, 1, 1, 0, 0, 2, 2, 1, 1, 2, 0, 1, 1, 2, 0, 2, 0, 2, 2, 1, 0, 2, 1, 1, 0, 2, 1, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 0, 1, 0, 2, 0, 2, 2, 1, 1, 2, 1, 0, 0, 2, 2, 2, 2, 1, 2, 2, 2, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 2, 2, 1, 0, 1, 0, 2]

.isGameOver()

Returns true if the game has ended by either player winning or a draw. Returns false otherwise.

game.isGameOver() // -> true

.print()

Prints a text representation of the board.

game.print()
/* ->
...........
xxo|ooo|ooo
xxo|ooo|---
xxo|---|---
...........
xxo|---|xxx
xxo|xxx|---
xxo|---|---
...........
xxo|---|---
xxo|---|---
xxo|---|---
...........
*/

.undoMove() - coming soon

Undoes the previous move.

Current Tags

  • 0.3.3                                ...           latest (a year ago)

16 Versions

  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.2                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 16
Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |