Update
This commit is contained in:
parent
99e8181bdc
commit
671c98ff3a
5 changed files with 162 additions and 25 deletions
30
chess.md
30
chess.md
|
@ -1,6 +1,6 @@
|
|||
# Chess
|
||||
|
||||
Chess is a very [old](old.md) two-player board [game](game.md), perhaps most famous and popular among all board games in [history](history.md). It is a [complete information](complete_information.md) game with no element of randomness, that simulates a battle of two armies on an 8x8 board with different battle pieces, also called *chessmen* or just *men*. Chess is also called the King's Game, it has a world-wide competitive community and is considered an intellectual [sport](sport.md) but it's also been a topic of research and [programming](programming.md) (many chess engines, [AI](ai.md)s and frontends are being actively developed). Chess is similar to games such [shogi](shogi.md) ("Japanese chess"), [xiangqi](xiangqi.md) ("Chinese chess") and [checkers](checkers.md). As the estimated number of chess games is bigger than [googol](googol.md), it is unlikely to ever be solved; though the complexity of the game in sheer number of possibilities is astronomical, among its shogi, go and xiangqi cousins it is actually considered one of the "simplest" (the board is relatively small and the game tends to simplify as it goes on as there are no rules to get men back to the game etc.).
|
||||
Chess (from Persian *shah*, *king*) is a very [old](old.md) two-player board [game](game.md), perhaps most famous and popular among all board games in [history](history.md). It is a [zero sum](zero_sum.md), [complete information](complete_information.md) game with no element of randomness, that simulates a battle of two armies on an 8x8 board with different battle pieces, also called *chessmen* or just *men*. Chess is also called the King's Game, it has a world-wide competitive community and is considered an intellectual [sport](sport.md) but it's also been a topic of research and [programming](programming.md) (many chess engines, [AI](ai.md)s and frontends are being actively developed). Chess is similar to games such [shogi](shogi.md) ("Japanese chess"), [xiangqi](xiangqi.md) ("Chinese chess") and [checkers](checkers.md). As the estimated number of chess games is bigger than [googol](googol.md), it is unlikely to ever be solved; though the complexity of the game in sheer number of possibilities is astronomical, among its shogi, go and xiangqi cousins it is actually considered one of the "simplest" (the board is relatively small and the game tends to simplify as it goes on as there are no rules to get men back to the game etc.).
|
||||
|
||||
{ There is a nice black and white indie movie called *Computer Chess* about chess programmers of the 1980s, it's pretty good, very oldschool, starring real programmers and chess players, check it out. ~drummyfish }
|
||||
|
||||
|
@ -69,17 +69,17 @@ Chess stats are pretty [interesting](interesting.md).
|
|||
|
||||
**Number of possible games** is not known exactly, Shannon estimated it at 10^120 (lower bound, known as *Shannon number*). Number of possible games by plies played is 20 after 1, 400 after 2, 8902 after 3, 197281 after 4, 4865609 after 5, and 2015099950053364471960 after 15.
|
||||
|
||||
Similarly the number of possibly reachable positions (position for which so called *proof game* exists) is not known exactly, it is estimated to at least 10^40 and 10^50 at most. Numbers of possible positions by plies is 20 after 1, 400 after 2, 5362 after 3, 72078 after 4, 822518 after 5, and 726155461002 after 11.
|
||||
Similarly the **number of possibly reachable positions** (position for which so called *proof game* exists) is not known exactly, it is estimated to at least 10^40 and 10^50 at most. Numbers of possible positions by plies is 20 after 1, 400 after 2, 5362 after 3, 72078 after 4, 822518 after 5, and 726155461002 after 11.
|
||||
|
||||
Shortest possible checkmate is by black on ply number 4 (so called *fool's mate*). As of 2022 the longest known forced checkmate is in 549 moves -- it has been discovered when computing the Lomonosov Tablebases.
|
||||
**Shortest possible checkmate** is by black on ply number 4 (so called *fool's mate*). As of 2022 the **longest known forced checkmate** is in 549 moves -- it has been discovered when computing the Lomonosov Tablebases.
|
||||
|
||||
Average game of chess lasts 40 moves. Average [branching factor](branching_factor.md) (number of possible moves at a time) is around 33.
|
||||
Average game of chess lasts 40 moves. **Average [branching factor](branching_factor.md)** (number of possible moves at a time) is around 33. **Maximum number of possible moves in a position** seems to be 218 (FEN: `R6R/3Q4/1Q4Q1/4Q3/2Q4Q/Q4Q2/pp1Q4/kBNN1KB1 w - - 0 1`).
|
||||
|
||||
White wins about 38% of games, black wins about 34%, the remaining 28% are draws.
|
||||
|
||||
What is the **longest possible game**? It depends on the exact rules and details we set, for example if a 50 move rule applies, a player MAY claim a draw but also doesn't have to -- but if neither player ever claims a draw, a game can be played infinitely -- so we have to address details such as this. Nevertheless the longest possible chess game upon certain rules has been computed by [Tom7](tom7.md) at 17697 half moves in a paper for [SIGBOVIK](sigbovik.md) 2020.
|
||||
What is the **longest possible game**? It depends on the exact rules and details we set, for example if a 50 move rule applies, a player MAY claim a draw but also doesn't have to -- but if neither player ever claims a draw, a game can be played infinitely -- so we have to address details such as this. Nevertheless the longest possible chess game upon certain rules has been computed by [Tom7](tom7.md) at 17697 half moves in a paper for [SIGBOVIK](sigbovik.md) 2020. Chess programming wiki states 11798 half moves as the maximum length of a chess game which considers a 50 move rule (1966 publication).
|
||||
|
||||
The longest game played in practice is considered to be the one between Nikolic and Arsovic from 1989, a draw with 269 moves lasting over 20 hours. For a shortest game there have been ones with zero moves; serious decisive shortest game has occurred multiple times like this: `1.d4 Nf6 2.Bg5 c6 3.e3 Qa5+` (white resigned).
|
||||
The **longest game played in practice** is considered to be the one between Nikolic and Arsovic from 1989, a draw with 269 moves lasting over 20 hours. For a shortest game there have been ones with zero moves; serious decisive shortest game has occurred multiple times like this: `1.d4 Nf6 2.Bg5 c6 3.e3 Qa5+` (white resigned).
|
||||
|
||||
**Best player ever**: a 2017 paper called *Who is the Master?* analyzed 20 of the top players of history based on how good their moves were compared to Stockfish, the strongest engine. The resulting top 10 is (from best): Carlsen, Kramnik, Fischer, Kasparov, Anand, Khalifman, Smyslov, Petrosian, Karpov, Kasimdzhanov. It also confirmed that the quality of chess play at top level has been greatly increasing.
|
||||
|
||||
|
@ -126,7 +126,7 @@ There is also a great online wiki focused on programming chess engines: https://
|
|||
|
||||
Programming chess is a [fun](fun.md) and enriching experience and is therefore recommended as a good exercise. There is nothing more satisfying than writing a custom chess engine and then watching it play on its own.
|
||||
|
||||
The core of chess programming is writing the [AI](ai.md), everything else, i.e. implementing the rules, communication protocols etc., is pretty straightforward (but still a good programming exercise). Nevertheless, as the chess programming wiki stresses, one has to pay a great attention to eliminating as many [bugs](bug.md) as possible; really, the importance of writing automatic tests can't be stressed enough as debugging the AI will be hard enough and can become unmanageable with small bugs creeping in.
|
||||
The core of chess programming is writing the [AI](ai.md). Everything else, i.e. implementing the rules, communication protocols etc., is pretty straightforward (but still a good programming exercise). Nevertheless, as the chess programming wiki stresses, one has to pay a great attention to eliminating as many [bugs](bug.md) as possible; really, the importance of writing automatic tests can't be stressed enough as debugging the AI will be hard enough and can become unmanageable with small bugs creeping in. Though has to go into choosing right [data structures](data_structure.md) so as to allow nice [optimizations](optimization.md), for example board representation plays an important role (two main approaches are a 64x64 2D array holding each square's piece vs keeping a list of pieces, each one recording its position).
|
||||
|
||||
The AI itself works traditionally on the following principle: firstly we implement so called static **evaluation function** -- a function that takes a chess position and outputs its evaluation number which says how good the position is for white vs black (positive number favoring white, negative black, zero meaning equal). This function considers a number of factors such as total material of both players, pawn structure, king safety, men mobility and so on. Traditionally this function has been hand-written, nowadays it is being replaced by a learned [neural network](neural_network.md) ([NNUE](nnue.md)) which showed to give superior results (e.g. Stockfish still offers both options); for starters you probably want to write a simple evaluation function manually. Secondly we implement a **search** algorithm -- typically some modification of [minimax](minimax.md) algorithm, e.g. with alpha-beta pruning -- that recursively searches the game tree and looks for a move that will lead to the best result in the future, i.e. to position for which the evaluation function gives the best value. This basic principle, especially the search part, can get very complex as there are many possible weaknesses and optimizations.
|
||||
|
||||
|
@ -160,14 +160,16 @@ The start setup of a chessboard is following (lowercase letters are for black me
|
|||
|
||||
Players take turns in making moves, white always starts. A move consists of moving one (or in special cases two) of own men from one square to another, possibly capturing (removing from the board) one opponent's man -- except for a special *en passant* move capturing always happens by moving one man to the square occupied by the opposite color man (which gets removed). Of course no man can move to a square occupied by another man of the same color. A move can NOT be skipped. A player wins by giving a **checkmate** to the opponent (making his king unable to escape attack) or if the opponent resigns. If a player is to move but has no valid moves, the game is a draw, so called **stalemate**. If neither player has enough men to give a checkmate, the game is a draw, so called **dead position**. There are additional situation in which game can be drawn (threefold repetition of position, 50 move rule). Players can also agree to a draw. A player may also be declared a loser if he cheated, if he lost on time in a game with clock etc.
|
||||
|
||||
The individual men and their movement rules are:
|
||||
The individual men and their movement rules are (no man can move beyond another, except for knight who jumps over other men):
|
||||
|
||||
- **pawn** (`P`): Moves 1 square forward (white towards 8th rank, black towards 1st rank), unless that square is occupied by any man (even enemy men, pawns cannot capture going forward). From its start position a pawn can optionally move 2 squares if neither of the 2 forward squares are occupied. Pawn can capture enemy men 1 square diagonally forward (i.e. 1 square forward right or 1 square forward left).
|
||||
- **rook** (`R`): Moves any number of squares either horizontally or vertically, but cannot jump over any men, however can capture (i.e. land) on a square occupied by enemy man and capture it.
|
||||
- **knight** (`N`): Can jump over men (both friendly and enemy), moves in "L" shapes, i.e. from its square a knight can jump to (with a possible capture) a square 2 squares in one direction and 1 square in the perpendicular direction (e.g. 2 squares down and 1 square right, or 2 squares right and 1 square up etc.).
|
||||
- **bishop** (`B`): Moves like rook but diagonally, i.e. a bishop will only ever be able to move on squares of one color (the one it starts on).
|
||||
- **queen** (`Q`): Can move both like bishop and rook.
|
||||
- **king** (`K`): Can move (and capture) to any of the 8 immediately neighboring squares.
|
||||
| man | symbol | ~value | movement | comment |
|
||||
| -------------- | -------| ------ | ------------------------------------------------------------------ | --------------------- |
|
||||
| pawn | P | 1 |1F, may also 2F from start, captures 1F1L or 1F1R, also *en passant*| promotes on last row |
|
||||
| knight | N | 3 |L-shape (2U1L, 2U1R, 2R1U, 2R1D, 2D1R, 2D1L, 2L1U, 2L1D), jumps over| |
|
||||
| bishop | B | 3.25 | any distance diagonally |stays on same color sq.|
|
||||
| rook | R | 5 | any distance orthogonally (U, R, D or L) |can reach all sq. |
|
||||
| queen | Q | 9 | like both bishop and rook |strongest piece |
|
||||
| king | K | inf | any of 8 neighboring squares | |
|
||||
|
||||
**Check**: If the player's king is attacked, i.e. it is immediately possible for an enemy men to capture the king, the player is said to be in check. A player in check has to make such a move as to not be in check after that move.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue