Skip to content

german1608/tic-tac-toe-eng-fcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tic-tac-toe-eng-fcc

JavaScript Style Guide license coverage

A tic-tac-toe cpu engine for a freeCodeCamp project

Installation

Install it via npm

npm install --save ttt-eng-fcc

Usage

This module is to emulate a tic-tac-toe game against the cpu. It all depends on the state of the game. So all you going to do is something like this:

const gameEngine = require('ttt-eng-fcc')

gameEngine.init()

// In production, you should use gameEngine.cpuFirstPlayer()
// to decide who will go first. For demos purposes, assume the
// starts
while (!gameEngine.isFinish()) {
  let humanInput = someInputFunction()

  // setPlay only accepts integers that are between 0 and 8 
  // (both inclusive)
  while (!gameEngine.setPlay(humanInput())) {
    humanInput = someInputFunction()
  }

  // here the gameEngine will compute the best move for THAT turn
  gameEngine.bestMove()
}

switch(gameEngine.whoWon()) {
  case 'human':
    // handle win for human. gameEngine.getWinPos() may be useful
  case 'cpu':
    // handle win for cpu.
  default:
    // handle tie
}

Contribution

For the moment I'm not accepting pull requests. This is because I need to test the coverage of the code when someone makes a PR and I haven't configured codecov yet.

License

MIT

About

A tic-tac-toe AI engine for a fcc project

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published