This commit is contained in:
Miloslav Ciz 2024-11-14 20:34:08 +01:00
parent da00222f76
commit 0266d219be
18 changed files with 1971 additions and 1931 deletions

106
chess.md
View file

@ -68,7 +68,7 @@ Fun fact: there seem to be **almost no black people in [chess](chess.md)** :D th
{ [This](https://www.youtube.com/watch?v=DpXy041BIlA) is an absolutely amazing video about weird chess algorithms :) And here is a very lovely article about someone's memories of his old competitive chess program: https://www.lkessler.com/brutefor.shtml. ~drummyfish }
Computers not only help people play chess, train their skills, analyze positions and perform research of games, but they also allow mathematical analysis of the game of chess itself and present a platform for things such as [artificial intelligence](ai.md). Knowledge gained from programming chess engines can then be applied in other areas as well. Since the dawn of the computer era computer chess has been a topic of passion and interest to [computer scientists](compsci.md) and [programmers](programming.md) -- not just because nerds usually love both chess and computer and it's only natural they will desire to combine the two, and not only because making a machine beat human at the most famous and iconic of all intellectual games is just a great and symbolic achievement in itself, but also because computer chess is just so much [fun](fun.md). For example you may let various engines play against each other, just sit back and make your own mini computer engine tournament, compare the strength of your engines, let them play from funny starting positions, let a strong engine with material handicap play a weak engine, program a strong engine to play the worst moves possible or program it completely arbitrary or weird goals such as that it can only checkmate with a pawn or that it will just want to place all its pieces on white squares, and then watch it try hard to achieve the goal. It's endless joy.
[Computers](computer.md) not only help people play chess, train their skills, analyze positions and perform research of games, but they also allow mathematical analysis of the game of chess itself and present a platform for things such as [artificial intelligence](ai.md). Knowledge gained from programming chess engines can then be applied in other areas as well. Since the dawn of the computer era computer chess has been a topic of passion and interest to [computer scientists](compsci.md) and [programmers](programming.md) -- not just because nerds usually love both chess and computer and it's only natural they will desire to combine the two, and not only because making a machine beat human at the most famous and iconic of all intellectual games is just a great and symbolic achievement in itself, but also because computer chess is just so much [fun](fun.md). For example you may let various engines play against each other, just sit back and make your own mini computer engine tournament, compare the strength of your engines, let them play from funny starting positions, let a strong engine with material handicap play a weak engine, program a strong engine to play the worst moves possible or program it completely arbitrary or weird goals such as that it can only checkmate with a pawn or that it will just want to place all its pieces on white squares, and then watch it try hard to achieve the goal. It's endless joy.
**Chess [software](software.md)** is usually separated to **[libraries](library.md)**, **chess engines** and **[frontends](frontend.md)**. Library is just that -- a programming library that will help a programmer create some kind of chess program. Chess engine on the other hand is a complete program whose main purpose is to compute good chess moves, it is typically a [CLI](cli.md) program capable of playing chess but also doing other things such as evaluating arbitrary positions, hinting best moves, saving and loading games etc. -- commonly the engine has some kind of custom CLI interface (flags, interactive commands it understands, ...) plus a support of some standardized text communication protocol, most notably XBoard (older one, more [KISS](kiss.md)) and/or UCI (newer, more [bloated](bloat.md)). It is also a must for an engine to support other standard formats such as **FEN** (ForsythEdwards notation, way of encoding a chess position as a text string), **PGN** (portable game notation, way of encoding games as text strings) etc. And then there are frontends (also called *boards*) -- these are, almost by definition, [GUI](gui.md) programs that help people interact with the underlying engine (and do other things like play against other humans, annotate games and so on). There may also exist other kind of programs, e.g. tournament managers that will automatically run a tournament of several chess engines, calculate their strength etc. As seen, the chess "ecosystem" is pretty modular (it is possible to easily drop-in replace any part of your chess system as they are all just black boxes with the same interface) and the whole system is based on standardized, relatively simple plain text protocols, i.e. this is all very close to [Unix philosophy](unix_philosophy.md) and [good design](lrs.md). This is an example of how games should be implemented.
@ -114,6 +114,7 @@ Here are some notable chess engines/computers/entities, as of 2024:
- **Magnus Carlsen**: Human, most likely the strongest player ever, has been quite comfortably winning every tournament he entered including the world championship until he quit, basically because he got "bored". His top FIDE Elo was 2882.
- **Komodo Dragon**: [Proprietary](proprietary.md), currently seems to be the second strongest engine, its main feature is [Monte Carlo] ("randomized") search algorithm. Current CCRL Elo is 3624.
- **Hikaru Nakamura**: Human, popularly considered "the second best" right after Magnus (who the mainstream likes to see as his biggest "rival") -- although this is not really so clear, he is definitely among the very top (his peak rating was 2816); We mention him here for his style of play: he likes to [troll](trolling.md) and do various lulz even on high level, many hate him for it. Some say he is a bit of a dick but his chess is definitely extremely entertaining. He also often plays strong computer engines, which is something that Magnus refuses to do (for commercial reasons Magnus only plays his shitty mobile "[app](app.md)"), so thanks to Nakamura we can really watch the best humans play the best computers.
- **Bobby Fischer**: [American](usa.md) player of the 20th century who is now dead already but who used to be, and by some still is, considered the best player of all time, although objectively speaking he probably isn't as good as some of the top today's players -- anyway he was funny in that he turned kind of [schizo](schizo.md) later on and started to make some lulz, which was yet amplified by the fact that he took part in the great cold war intellectual battle with Soviet Russia, his match against Spassky became legendary, it was extremely tense and also funny (look it up).
- **[Leela Chess Zero](lc0.md)** (lc0): FOSS engine (written in C++), among top strongest engines (currently top 50 on CCRL), it is interesting mainly for how it works: it is a neural network engine that's **completely self-taught** from the ground up, i.e. it didn't learn chess by watching anyone else play, it was only allowed to learn by playing against itself. Current CCRL Elo is 3441.
- **[Deep Blue](deep_blue.md)**: A historically famous supercomputer, the first one to have beaten the human world chess champion in 1997.
- **[GNU chess](gnu_chess.md)** Free engine by [GNU](gnu.md), not among absolute top by strength but still very strong. Current CCRL Elo is 2825.
@ -124,6 +125,57 @@ Here are some notable chess engines/computers/entities, as of 2024:
- **Turochamp**: Probably the first chess program ever, made by David Champernowne and [Alan Turing](turing.md) himself in 1948, in times when computers still couldn't execute it! It was very primitive, looking only two moves ahead, and was only ever executed manually -- of course, it got raped pretty bad the human opponent.
- ...
## Rules
The exact rules of chess and their scope may depend on situation, this is just a sum up of rules generally used nowadays. Nowadays the official rules are considered to be those defined by FIDE.
The start setup of a chessboard is following (lowercase letters are for black men, uppercase for white men, on a board with colored squares A1 is black):
```
_______________
/8 |r n b q k b n r|
r | 7 |p p p p p p p p|
a | 6 |. . . . . . . .|
n | 5 |. . . . . . . .|
k | 4 |. . . . . . . .|
s | 3 |. . . . . . . .|
| 2 |P P P P P P P P|
\1 |R N B Q K B N R|
"""""""""""""""
A B C D E F G H
\_____________/
files
```
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 (no man can move beyond another, except for knight who jumps over other men):
| 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 | |
{ Cool players call knights *horses* or *ponies* and pawns *peasants*, rook may be called a *tower* and bishop a *sniper* as he often just sits on the main diagonal and shoot pieces that wonder through. Also pronounce *en passant* as "en peasant". Nakamura just calls all pieces a *juicer*. ~drummyfish }
**Check**: If the player's king is attacked, i.e. it is immediately possible for an enemy man 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.
A player cannot make a move that would leave him in check!
**Castling**: If a player hasn't castled yet and his king hasn't been moved yet and his kingside (queenside) rook hasn't been moved yet and there are no men between the king and the kingside (queenside) and the king isn't and wouldn't be in check on his square or any square he will pass through or land on during castling, short (long) castling can be performed. In short (long) castling the king moves two squares towards the kingside (queenside) rook and the rook jumps over the king to the square immediately on the other side of the king.
**Promotion**: If a pawn reaches the 1st or 8th rank, it is promoted, i.e. it has to be switched for either queen, rook, bishop or knight of the same color.
**Checkmate**: If a player is in check but cannot make any move to get out of it, he is checkmated and lost.
**En passant** (aka "surprise motherfucker", pronounced as *en peasant*): If a pawn moves 2 squares forward (from the start position), in the immediate next move the opponent can take it with a pawn in the same way as if it only moved 1 square forward (the only case in which a man captures another man by landing on an empty square).
Threefold repetition is a rule allowing a player to claim a draw if the same position (men positions, player's turn, castling rights, en passant state) occurs three times (not necessarily consecutively). The 50 move rule allows a player to claim a draw if no pawn has moved and no man has been captured in last 50 moves (both players making their move counts as a single move here).
## Stats And Records
Chess stats are pretty [interesting](interesting.md). Thanks a lot e.g. to Lichess (and NOT thanks to fucking capitalist idiots like chess dot com) we have some great [public domain](public_domain.md) databases of billions of games played between both people and computers, and thanks to chess engines we can generate new and new on demand, so naturally many people create cool statistics, look for patterns and oddities. This can be very insightful and entertaining.
@ -259,6 +311,7 @@ What's the **theoretically worst game possible**, and how to find out? This is e
290. Na4+ Kc1 291. Nb2 Nxb2+ 292. Kc3 Na4+ 293. Kd3 Nc5+ 294. Kc3 Na4+ 295. Kd3 Nc5+
296. Kc3 Ne4+ 297. Kd3 Nf2+ 298. Kc3 Ne4+ 299. Kd3 Nf2+ 300. Kc3 Nd1+ 301. Kd3 Kb2
302. Ne1 a4 303. Kd2 Nf2 304. Ke2 Nh1 305. Nd3+ Kb1 306. Kf3 a3 307. Nb4 a2 308. Nxa2 Kxa2
1/2-1/2
```
Lichess analysis seems to only handle the first 150 moves, the evaluation graph explodes up and down and almost jumps out of the roof. The following are the analysis results (for the first 150 moves). White: 15 inaccuracies, 15 mistakes, 97 blunders, 581 average centipawn loss, accuracy: 21%. Black: 11 inaccuracies, 17 mistakes, 97 blunders, 587 average centipawn loss, accuracy: 21%. That doesn't seem that bad, why aren't all moves blunders? Well, firstly the analysis is relatively quick (takes like 10 seconds for whole game), it likely doesn't see as deep as the engines who were given hours to play, but secondly we changed the rules of the game: the analyzing engine still assumes the players will be playing good moves, which is not the case.
@ -341,57 +394,6 @@ Anyway, you can try to derive your own stats, there are huge free game databases
{ TODO: Derive stats about the best move, i.e. for example "best move is usually by queen by three squares" or something like that. Could this actually help the play somehow? Maybe could be used for move ordering in alpha-beta. ~drummyfish }
## Rules
The exact rules of chess and their scope may depend on situation, this is just a sum up of rules generally used nowadays. Nowadays the official rules are considered to be those defined by FIDE.
The start setup of a chessboard is following (lowercase letters are for black men, uppercase for white men, on a board with colored squares A1 is black):
```
_______________
/8 |r n b q k b n r|
r | 7 |p p p p p p p p|
a | 6 |. . . . . . . .|
n | 5 |. . . . . . . .|
k | 4 |. . . . . . . .|
s | 3 |. . . . . . . .|
| 2 |P P P P P P P P|
\1 |R N B Q K B N R|
"""""""""""""""
A B C D E F G H
\_____________/
files
```
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 (no man can move beyond another, except for knight who jumps over other men):
| 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 | |
{ Cool players call knights *horses* or *ponies* and pawns *peasants*, rook may be called a *tower* and bishop a *sniper* as he often just sits on the main diagonal and shoot pieces that wonder through. Also pronounce *en passant* as "en peasant". Nakamura just calls all pieces a *juicer*. ~drummyfish }
**Check**: If the player's king is attacked, i.e. it is immediately possible for an enemy man 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.
A player cannot make a move that would leave him in check!
**Castling**: If a player hasn't castled yet and his king hasn't been moved yet and his kingside (queenside) rook hasn't been moved yet and there are no men between the king and the kingside (queenside) and the king isn't and wouldn't be in check on his square or any square he will pass through or land on during castling, short (long) castling can be performed. In short (long) castling the king moves two squares towards the kingside (queenside) rook and the rook jumps over the king to the square immediately on the other side of the king.
**Promotion**: If a pawn reaches the 1st or 8th rank, it is promoted, i.e. it has to be switched for either queen, rook, bishop or knight of the same color.
**Checkmate**: If a player is in check but cannot make any move to get out of it, he is checkmated and lost.
**En passant** (aka "surprise motherfucker", pronounced as *en peasant*): If a pawn moves 2 squares forward (from the start position), in the immediate next move the opponent can take it with a pawn in the same way as if it only moved 1 square forward (the only case in which a man captures another man by landing on an empty square).
Threefold repetition is a rule allowing a player to claim a draw if the same position (men positions, player's turn, castling rights, en passant state) occurs three times (not necessarily consecutively). The 50 move rule allows a player to claim a draw if no pawn has moved and no man has been captured in last 50 moves (both players making their move counts as a single move here).
### Variants
Besides similar games such as [shogi](shogi.md) there are many variants of chess, i.e. slight modifications of rules, foremost worth mentioning is for example chess 960. The following is a list of some variants: