Need private packages and team management tools?Check out npm Teams »

connect-four-lib

3.0.1 • Public • Published

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

Keywords

none

Install

npm i connect-four-lib

DownloadsWeekly Downloads

0

Version

3.0.1

License

ISC

Last publish

Collaborators

  • avatar