Connect Four API Endpoint

The source is on the GitHub repository

https://kevinalbs.com/connect4/back-end/index.php/getMoves

Returns scores for moves.

Parameters

  • board_data A string of 42 characters representing a 6x7 board (going left to right, top to bottom). For backwards compatibility, a non-standard 7x7 board is supported.
  • player (optional) Which player (1 or 2) to find moves for. Default is player 1.

Returns a JSON object mapping the column of the move (zero-based, so 0 is the left-most column and 6 is the right-most) to a score.

Example

$ curl -s 'https://kevinalbs.com/connect4/back-end/index.php/getMoves?board_data=0000000000000000020000001200000210000021001012100&player=2'
{"0":10,"1":10,"2":13,"3":13,"4":13,"5":12,"6":12}
https://kevinalbs.com/connect4/back-end/index.php/hasWon

Checks if a player has won. Only checks for a single piece.

  • board_data A string of 42 characters representing a 6x7 board (going left to right, top to bottom). For backwards compatibility, a non-standard 7x7 board is supported.
  • player (optional) Which player (1 or 2) to find moves for. Default is player 1.
  • i The ith row (with 0 being top and 6 being bottom) of the piece to check
  • j The jth column (with 0 being left and 6 being right) of the piece to check

Example

$ curl -s 'https://kevinalbs.com/connect4/back-end/index.php/hasWon?board_data=0002000001102000222100012220002111000122100012110&player=2&i=3&j=3'
true