AI Gaming
Search
⌃K

Chess

Objective

Chess is a classic strategy board game, where the objective is to make it so the enemy king has no positions to move to where it would not be captured next turn. When the enemy king has no legal moves that would prevent it from being captured, you are said to have won by Checkmate.

Rules

In chess, each type of game piece can move in a unique way. If a piece moves to a square that contains an enemy piece, then that enemy piece is captured and removed from the game.

Pawn

A Pawn can move one square forward (towards the enemies side of the board). If a Pawn has not moved in the game yet, it is able to move two squares forward. A Pawn is unable to capture an enemy piece by moving forward. To capture an enemy piece, the pawn must move 1 square forward diagonally. A Pawn can only move diagonally if it is capturing an enemy piece.

Knight

A Knight can move in an L shape. The Knight starts by moving either 1 or 2 squares in any direction and then 2 or 1 squares in any direction perpendicular to its original direction, respectively.

Bishop

A Bishop can move up to as many squares as it can (before it reaches another piece or the edge of the board) diagonally in any direction. A Bishop can only move diagonally.

Rook

A Rook can move up to as many squares as it can (before it reaches another piece or the edge of the board) orthogonally in any direction. A Rook can only move orthogonally.

Queen

A Queen can move up to as many squares as it can (before it reaches another piece or the edge of the board) in any direction. A Queen can move diagonally and orthogonally.

King

A King can move 1 square in any direction.

Special Moves

Castling

Once per game the King and the Rook can perform a special move called Castling. In this move, the King moves 2 squares along the first rank and then the Rook is placed in the last square the King passed through. This move can only be performed if the following conditions are met:
  • Neither the King or the Rook being moved and moved yet this game.
  • There are no pieces between the King and the Rook.
  • The King is not in check and cannot pass through a square that would ordinarily put it in check.

En Passent

If a Pawn moves 2 squares from its original position and finishes in a square adjacent to an enemy Pawn in the next file, the enemy Pawn may take it by moving diagonally behind the first Pawn.

Promotion

If a Pawn reaches the enemies edge of the board, you may remove it from the game and replace it with a Knight, Rook, Bishop, or Queen.

What Ends the Game?

Checkmate

If the current player has no legal ways to remove their King from Check, they are in Checkmate and lose the game. Check occurs if your King is in a vulnerable position and could be captured on the opponents next turn.

Stalemate

If the current player has no legal moves and their King is not in check, the game ends in a draw.

Fifty-Move Rule

If fifty turns have passed since a pawn was last moved, the game ends in a draw.

Programmer's Reference

gamestate

Example gamestate JSON:
{
'Board': [
['NA', 'BN', 'BB', 'BQ', 'BK', 'BB', 'NA', 'NA'],
['NA', 'NA', 'BP', 'BP', 'BP', 'NA', 'BP', 'BR'],
['NA', 'NA', 'NA', 'NA', 'NA', 'BP', 'NA', 'NA'],
['NA', 'WP', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA'],
['NA', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA'],
['NA', 'NA', 'WP', 'NA', 'NA', 'NA', 'NA', 'NA'],
['NA', 'WP', 'NA', 'WP', 'WP', 'WP', 'NA', 'NA'],
['BR', 'WN', 'WB', 'WQ', 'WK', 'WB', 'NA', 'NA']
],
'Role': 0,
'IsMover': True,
'PossibleMoves': {
'[3, 1]': [
[2, 1]
],
'[5, 2]': [
[4, 2]
],
'[6, 1]': [
[5, 1],
[4, 1]
],
'[6, 3]': [
[5, 3],
[4, 3]
],
'[6, 4]': [
[5, 4],
[4, 4]
],
'[6, 5]': [
[5, 5],
[4, 5]
],
'[7, 1]': [
[5, 0]
],
'[7, 3]': [
[6, 2],
[5, 1],
[4, 0]
],
'[7, 5]': [
[6, 6],
[5, 7]
]
},
'PiecesTaken': ['WP', 'WP', 'BN', 'BP', 'WR', 'BP', 'WN', 'BP', 'WR'],
'ResponseDeadline': 1561042944337,
'GameStatus': 'RUNNING',
'Steps': 20,
'InvalidMove': None,
'OpponentId': 'housebot-practise'
}
A description of each field in the gamestate:
Key
Description
Board
A list of lists representing each row of the board.
Role
This identifies whether you are playing with the Black or White pieces. White pieces move first. A value of 0 indicates you are the White player and a value of 1 indicates you are the Black player.
IsMover
This is a boolean value that indicates whether it is your turn. This will always be true in the calculate_move() function.
PossibleMoves
This is a python dictionary that contains all possible moves. Each key represents a location on the board, such as '[0,1]' or '[5,2]' (these are lists in string representation). Each value will be a list of lists indicating where the piece at the key location can move, for example: [[5, 4], [4, 4]].
PiecesTaken
This is a list that contains all the pieces that have been captured so far.
ResponseDeadline
The epoch time, in milliseconds, that a successful move has to be sent and received by to prevent you from timing out.
GameStatus
A string that will have value "RUNNING" if the game is in progress or a reason the game has ended otherwise.
Steps
An integer that indicates what turn of the game it is.
OpponentId
A string containing the name of your opponent.

Understanding the Board

Each string in the list of lists represents a piece on the board. Each string contains two characters, the first indicating whether the piece is Black or White and the second indicates what type of piece it is. If the piece is Black the first character will be 'B' if it is White the first character will be 'W'. The following characters are used to represent the types of pieces:
  • 'P' - Pawn
  • 'N' - Knight
  • 'B' - Bishop
  • 'R' - Rook
  • 'Q' - Queen
  • 'K' - King
Full examples of pieces are:
  • 'BK' - Black King
  • 'WP' - White Pawn
  • 'BN' - Black Knight
  • 'WQ' - White Queen

Making a Valid Move

The value you have to return from calculate_move() states the location of the piece that is moving and the location the piece will move to. This should be returned as JSON.
{"From": [1,1], "To": [2,2]}