Skip to content

juice49/connect-4

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

Connect 4

Given an array representing a Connect 4 game, findWin will return an array containing the indexes of the first winning line found.

The search begins from the top left of the grid.

An example of game state:

[
  null, null, null, null, null, null, null,
  null, null, null, null, null, null, null,
  null, 1   , null, null, null, null, null,
  null, 0   , 1   , null, null, null, null,
  null, 0   , 0   , 1   , null, null, null,
  1   , 1   , 0   , 0   , 1   , 0   , null
]

The winning line is:

[15, 23, 31, 39]

Todo

  • Unit tests.
  • Types.

Ideas

  • It may be (insignificantly) faster to search bottom up, because counters are placed bottom up.
  • To benchmark the code, we could look for longer lines in a larger grid.

About

Connect 4 game with a React hook and UI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published