Skip to content
No description, website, or topics provided.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
connect-four-lib.js
package.json
yarn.lock

README.md

Connect Four Library

build status npm version Standard - JavaScript Style Guide

This is a project to implement the game logic for the classic game Connect Four.

This is a collaborative project of the students of the The Iron Yard Houston 24-week 2017 front-end class.

Development Setup

Install Yarn, then from this directory:

# install node_modules folder
yarn install

# run the test suite
yarn test

API Documentation

The Connect Four Library has three public functions:

board Array

The Connect Four board is represented as a 7x6 Array of Arrays (columns / rows). Each element in the Array is either null, 'r', or 'y'.

createEmptyBoard()

This method returns a new, empty board array. A square without a piece is represented with null, so an empty board looks like this in JSON format:

[
  [null, null, null, null, null, null],
  [null, null, null, null, null, null],
  [null, null, null, null, null, null],
  [null, null, null, null, null, null],
  [null, null, null, null, null, null],
  [null, null, null, null, null, null],
  [null, null, null, null, null, null]
]

gameStatus(board)

This function accepts a game board and returns the current game status:

  • If the board is not in a valid 7x6 Array format:
    • null
  • If neither color has won and the game is still in progress:
    • {status: 'in_progress'}
  • If neither color has won, and the game is over (the board is full):
    • {status: 'tie'}
  • If red has won:
    • {status: 'winner_red', coordinates: [[0, 0], [1, 0], [2, 0], [3, 0]]}
  • If yellow has won:
    • {status: 'winner_yellow', coordinates: [[0, 3], [1, 3], [2, 3], [3, 3]]}

In the winning cases, coordinates will be an array of the winning pieces column / row coordinates.

validBoard(board)

Predicate function to ensure that the board format is valid.

License

ISC License

You can’t perform that action at this time.