Skip to content

juice49/connect-4

Repository files navigation

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