This is a book that describe our game chess with a GUI.

System requirement

  1. Any system with basic configuration.
  2. Operating System : Any (Windows / Linux / Mac).

Software requirement

  1. Cargo/Rust installed (If not download it here).

Cargo installation

cargo install rg-chess

Manual installation

# clone https
git clone https://github.com/rust-games/rg-chess.git
# or
# clone ssh
git clone git@github.com:rust-games/rg-chess.git

# Build
cargo build

Tests

cargo test

Run

cargo run --release

Note: if you don't build in release, the game may be slow.

Use this page in order to help users to configure your project.

Chess

Chess is a board game played between two players. It is sometimes called Western chess or international chess to distinguish it from related games such as xiangqi and shogi. The current form of the game emerged in Spain and the rest of Southern Europe during the second half of the 15th century after evolving from chaturanga, a similar but much older game of Indian origin. Today, chess is one of the world's most popular games, played by millions of people worldwide.

Chess is an abstract strategy game and involves no hidden information. It is played on a square chessboard with 64 squares arranged in an eight-by-eight grid. At the start, each player (one controlling the white pieces, the other controlling the black pieces) controls sixteen pieces: one king, one queen, two rooks, two bishops, two knights, and eight pawns. The object of the game is to checkmate the opponent's king, whereby the king is under immediate attack (in "check") and there is no way for it to escape. There are also several ways a game can end in a draw.

Organized chess arose in the 19th century. Chess competition today is governed internationally by FIDE (International Chess Federation). The first universally recognized World Chess Champion, Wilhelm Steinitz, claimed his title in 1886; Magnus Carlsen is the current World Champion. A huge body of chess theory has developed since the game's inception. Aspects of art are found in chess composition, and chess in its turn influenced Western culture and art and has connections with other fields such as mathematics, computer science, and psychology.

One of the goals of early computer scientists was to create a chess-playing machine. In 1997, Deep Blue became the first computer to beat the reigning World Champion in a match when it defeated Garry Kasparov. Today's chess engines are significantly stronger than the best human players, and have deeply influenced the development of chess theory.

Rules

The rules of chess (also known as the laws of chess) govern the play of the game of chess. While the exact origins of chess are unclear, modern rules first took form during the Middle Ages. The rules continued to be slightly modified until the early 19th century, when they reached essentially their current form. The rules also varied somewhat from place to place. Today, the standard rules are set by FIDE (Fédération Internationale des Échecs), the international governing body for chess. Slight modifications are made by some national organizations for their own purposes. There are variations of the rules for fast chess, correspondence chess, online chess, and Chess960.

Chess is a two-player board game using a chessboard and sixteen pieces of six types for each player. Each type of piece moves in a distinct way. The object of the game is to checkmate (threaten with inescapable capture) the opponent's king. Games do not necessarily end in checkmate; a player who expects to lose may resign. A game can also end in a draw in several ways.

Besides, the basic moves of the pieces, rules also govern the equipment used, time control, conduct and ethics of players, accommodations for physically challenged players, and recording of moves using chess notation. Procedures for resolving irregularities that can occur during a game are provided as well.

Initial Setup

Chess is played on a chessboard, a square board divided into 64 squares (eight-by-eight) of alternating color, which is similar to that used in draughts (checkers). No matter what the actual colors of the board, the lighter-colored squares are called "light" or "white", and the darker-colored squares are called "dark" or "black". Sixteen "white" and sixteen "black" pieces are placed on the board at the beginning of the game. The board is placed so that a white square is in each player's near-right corner. Horizontal rows are called ranks and vertical rows are called files.

Each player controls sixteen pieces:

PieceKingQueenRookBishopKnightPawn
Number of Pieces112228
Symbols Whiteking_wqueen_wrook_wbishop_wknight_wpawn_w
Symbols Blackking_bqueen_brook_bbishop_bknight_bpawn_b

At the beginning of the game, the pieces are arranged as shown in the diagram: for each side one king, one queen, two rooks, two bishops, two knights, and eight pawns.

The pieces are placed, one on a square, as follows:

  • The rooks are placed on the outside corners, right and left edge.
  • The knights are placed immediately inside the rooks.
  • The bishops are placed immediately inside the knights.
  • The queen is placed on the central square of the same color of that of the player: white queen on the white square and black queen on the black square.
  • The king takes the vacant spot next to the queen.
  • The pawns are placed one square in front of all the other pieces.

Popular mnemonics used to remember the setup are "queen on her own color" and "white on right". The latter refers to setting up the board so that the square closest to each player's right is white.

Gameplay

The player controlling the white pieces is named "White"; the player controlling the black pieces is named "Black". White moves first, then players alternate moves. Making a move is required; it is not legal to skip a move, even when having to move is detrimental. Play continues until a king is checkmated, a player resigns, or a draw is declared, as explained below. In addition, if the game is being played under a time control, a player who exceeds the time limit loses the game unless they cannot be checkmated.

The official chess rules do not include a procedure for determining who plays White. Instead, this decision is left open to tournament-specific rules (e.g. a Swiss system tournament or round-robin tournament) or, in the case of non-competitive play, mutual agreement, in which case some kind of random choice is often employed.

Movement

Basic Moves

Each type of chess piece has its own method of movement. A piece moves to a vacant square except when capturing an opponent's piece.

Except for any move of the knight and castling, pieces cannot jump over other pieces. A piece is captured (or taken) when an attacking enemy piece replaces it on its square except in the case of en passant. The captured piece is thereby permanently removed from the game. The king can be put in check but cannot be captured (see below).

  • The king moves exactly one square horizontally, vertically, or diagonally. A special move with the king known as castling is allowed only once per player, per game (see below).

  • A rook moves any number of vacant squares horizontally or vertically. It also is moved when castling.

  • A bishop moves any number of vacant squares diagonally.

  • The queen moves any number of vacant squares horizontally, vertically, or diagonally.

  • A knight moves to one of the nearest squares not on the same rank, file, or diagonal. (This can be thought of as moving two squares horizontally then one square vertically, or moving one square horizontally then two squares vertically—i.e. in an "L" pattern.) The knight is not blocked by other pieces; it jumps to the new location.

  • Pawns have the most complex rules of movement:

    • A pawn moves straight forward one square, if that square is vacant. If it has not yet moved, a pawn also has the option of moving two squares straight forward, provided both squares are vacant. Pawns cannot move backwards.
    • A pawn, unlike other pieces, captures differently from how it moves. A pawn can capture an enemy piece on either of the two squares diagonally in front of the pawn. It cannot move to those squares when vacant except when capturing en passant.

    The pawn is also involved in the two special moves en passant and promotion.

Castling

Castling consists of moving the king two squares towards a rook, then placing the rook on the other side of the king, adjacent to it. Castling is only permissible if all the following conditions hold:

  • The king and rook involved in castling must not have previously moved
  • There must be no pieces between the king and the rook
  • The king may not currently be under attack, nor may the king pass through or end up in a square that is under attack by an enemy piece (though the rook is permitted to be under attack and to pass over an attacked square)
  • The castling must be kingside (blue) or queenside (red).

king and queen side diagram

En Passant

When a pawn advances two squares from its original square and ends the turn adjacent to a pawn of the opponent's on the same rank, it may be captured by that pawn of the opponent's, as if it had moved only one square forward. This capture is only legal on the opponent's next move immediately following the first pawn's advance. The diagrams below demonstrate an instance of this: if the white pawn moves from a2 to a4, the black pawn on b4 can capture it en passant, moving from b4 to a3 while the white pawn on a4 is removed from the board.

en passant image

Promotion

If a player advances a pawn to its eighth rank, the pawn is then promoted (converted) to a queen, rook, bishop, or knight of the same color at the choice of the player (a queen is usually chosen). The choice is not limited to previously captured pieces. Hence, it is theoretically possible for a player to have up to nine queens or up to ten rooks, bishops, or knights if all of their pawns are promoted.

Specific Rules

Fifty-move Rule

The fifty-move rule in chess states that a player can claim a draw if no capture has been made and no pawn has been moved in the last fifty moves (for this purpose a "move" consists of a player completing a turn followed by the opponent completing a turn). The purpose of this rule is to prevent a player with no chance of winning from obstinately continuing to play indefinitely or seeking to win by tiring the opponent.

Chess positions with only a very few pieces can be "solved", that is, the outcome of best play for both sides can be determined by exhaustive analysis; and if the outcome is a win for one side or the other (rather than a draw), it is of interest to know whether the defending side can hold out long enough to invoke the fifty-move rule. The simplest common endings, called the basic checkmates, such as king and queen versus king, can all be won in well under 50 moves. However, in the 20th century it was discovered that certain endgame positions are winnable but require more than 50 moves (without a capture or a pawn move). The rule was therefore changed to allow certain exceptions in which 100 moves were allowed with particular material combinations. However, winnable positions that required even more moves were later discovered, and in 1992, FIDE abolished all such exceptions and reinstated the strict 50-move rule.

Check

A king is in check when it is under attack by at least one enemy piece. A piece unable to move because it would place its own king in check (it is pinned against its own king) may still deliver check to the opposing player.

It is illegal to make a move that places or leaves one's king in check. The possible ways to get out of check are:

  • Move the king to a square where it is not in check.
  • Capture the checking piece (possibly with the king).
  • Block the check by placing a piece between the king and the opponent's threatening piece.

If it is not possible to get out of check, the king is checkmated and the game is over (see the next section).

In informal games, it is customary to announce "check" when making a move that puts the opponent's king in check. However, in formal competitions, check is rarely announced.

End of the Game

Checkmate

If a player's king is placed in check and there is no legal move that player can make to escape check, then the king is said to be checkmated, the game ends, and that player loses. Unlike other pieces, the king is never captured.

The diagram shows an example checkmate position. The white king is threatened by the black queen; the empty square to which the king could move is also threatened; and the king cannot capture the queen, because it would then be in check by the rook.

Resigning

Either player may resign at any time, conceding the game to the opponent. A player may resign by saying it verbally or by indicating it on the scoresheet in any of three ways: (1) by writing "resigns", (2) by circling the result of the game, or (3) by writing "1–0" if Black resigns or "0–1" if White resigns. Tipping over the king also indicates resignation, but it should be distinguished from accidentally knocking the king over. Stopping both clocks is not an indication of resigning, since clocks can be stopped to call the arbiter. An offer of a handshake is sometimes used, but it could be mistaken for a draw offer.

Draws

The game ends in a draw if any of these conditions occur:

  • The player to move is not in check and has no legal move. This situation is called a stalemate. An example of such a position is shown in the diagram below. stalemate example

    Black to move is in stalemate, since Black's king has no legal move, and is not in check. The game is drawn.

  • The game reaches a dead position.
  • Both players agree to a draw after one of the players makes such an offer.
  • The player having the move claims a draw by correctly declaring that one of the following conditions exists, or by correctly declaring an intention to make a move which will bring about one of these conditions:
    • The same board position has occurred three times with the same player to move and all pieces having the same rights to move, including the right to castle or capture en passant (see threefold repetition rule).
    • There has been no capture or pawn move in the last fifty moves by each player, if the last move was not a checkmate (see fifty-move rule).
  • The arbiter intervenes to declare a draw, without a draw request necessary:
    • When the same board position has occurred five times (see fivefold repetition rule).
    • When the moves without capture or pawn move extend up to seventy-five.

At one time, if a player was able to check the opposing king continually (perpetual check) and the player indicated their intention to do so, the game was drawn. This rule is no longer in effect; however, players will usually agree to a draw in such a situation, since either the rule on threefold repetition or the fifty-move rule will eventually be applicable.

Dead Position

A dead position is defined as a position where neither player can checkmate their opponent's king by any sequence of legal moves.

  • Any positions with only the following pieces are dead positions, and are known as draws by insufficient material:
    • king against king
    • king against king and bishop
    • king against king and knight
    • king and bishop against king and bishop, with both bishops on squares of the same color (see King and two bishops).
  • However, insufficient material is not the only condition for a dead position. There are positions in which checkmate is impossible but the pieces on the board would be sufficient to mate if arranged otherwise. This usually occurs in blocked king and pawn endings where it is impossible for either king to capture the pawns. See the diagram below.

Flag-Fall

A game played under time control will end as a loss for a player who uses up all the time allotted on the player's clock, which is called flag-fall, unless the opponent has no possibility of effecting checkmate. There are different types of time control. A player may have a fixed amount of time for the entire game, or may have to make a certain number of moves within a specified time. Also, a small increment of time may be added for each move made.

Notations

Forsyth-Edwards Notation (FEN)

see here

Standard Algebraic Notation (SAN)

see here

Here is a list of the contributors who have helped to improve this project. Big shout-out to them!

If you feel you're missing from this list, feel free to add yourself in a PR.