master
Miloslav Ciz 7 months ago
parent 99e8181bdc
commit 671c98ff3a

@ -0,0 +1,130 @@
# Bytecode
TODO
## Example
Let's consider a simple algorithm that tests the [Collatz conjecture](collatz_conjecture.md) (which says that applying a simple operation from any starting number over and over will always lead to number 1). The algorithm in [C](c.md) would look as follows:
```
// Collatz conjecture
#include <stdio.h>
int next(int n)
{
return n % 2 ? // is odd?
3 * n + 1 :
n / 2;
}
int main(void)
{
int n = getchar() - '0'; // read input ASCII digit
while (1)
{
printf("%d\n",n);
if (n == 1)
break;
n = next(n);
}
return 0;
}
```
The program reads a number (one digit for simplicity) and then prints the sequence until reaching the final number 1. Now let's rewrite the same algorithm in [comun](comun.md), a language which will allow us to produce bytecode:
```
# Collatz conjecture
next:
$0 2 % ? # is odd?
3 * 1 +
;
2 /
.
.
<- # read input ASCII digit
"0" - # convert it to number
@@
# print:
$0 10 / "0" + ->
$0 10 % "0" + ->
10 ->
$0 1 = ?
!@
.
next
.
```
The bytecode this compiles to is following:
```
000000: DES 00 0111 # func
000001: JMA 00 0100... # 20 (#14)
000002: COC 00 0001
000003: MGE 00 0000
000004: CON' 00 0010 # 2 (#2)
000005: MOX 00 0000
000006: DES 00 0001 # if
000007: JNA 00 0000... # 16 (#10)
000008: COC 00 0001
000009: CON' 00 0011 # 3 (#3)
00000a: MUX 00 0000
00000b: CON' 00 0001 # 1 (#1)
00000c: ADX 00 0000
00000d: DES 00 0010 # else
00000e: JMA 00 0011... # 19 (#13)
00000f: COC 00 0001
000010: CON' 00 0010 # 2 (#2)
000011: DIX 00 0000
000012: DES 00 0011 # end if
000013: RET 00 0000
000014: INI 00 0000
000015: INP 00 0000
000016: CON' 00 0000... # 48 (#30)
000017: COC 00 0011
000018: SUX 00 0000
000019: DES 00 0100 # loop
00001a: MGE 00 0000
00001b: CON' 00 1010 # 10 (#a)
00001c: DIX 00 0000
00001d: CON' 00 0000... # 48 (#30)
00001e: COC 00 0011
00001f: ADX 00 0000
000020: OUT 00 0000
000021: MGE 00 0000
000022: CON' 00 1010 # 10 (#a)
000023: MOX 00 0000
000024: CON' 00 0000... # 48 (#30)
000025: COC 00 0011
000026: ADX 00 0000
000027: OUT 00 0000
000028: CON' 00 1010 # 10 (#a)
000029: OUT 00 0000
00002a: MGE 00 0000
00002b: CON' 00 0001 # 1 (#1)
00002c: EQX 00 0000
00002d: DES 00 0001 # if
00002e: JNA 00 0100... # 52 (#34)
00002f: COC 00 0011
000030: DES 00 0101 # break
000031: JMA 00 1000... # 56 (#38)
000032: COC 00 0011
000033: DES 00 0011 # end if
000034: CAL 00 0011 # 3 (#3)
000035: DES 00 0110 # end loop
000036: JMA 00 1010... # 26 (#1a)
000037: COC 00 0001
000038: END 00 0000
```
TODO: analyze the above, show other bytecodes (python, java, ...)

@ -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.

@ -1,7 +1,12 @@
# Deep Blue
TODO
Deep Blue was a legendary [chess](chess.md) playing [IBM](ibm.md) [supercomputer](supercomputer.md), which in 1997 made [history](history.md) by being the first ever [computer](computer.md) to beat the human world chess champion at the time (Garry Kasparov), marking a moment which many consider that at which "computers finally outsmarted humans". Since then computers really did continue to surpass humans at chess by much greater margins; nowadays a mere cellphone running [stockfish](stockfish.md) can easily rape the world chess champion.
Fun fact: Deep Blue was firstly named Deep Thought, after the computer in [Hitchhiker's Guide to the Galaxy](hgttg.md), however it had to be renamed because the name too much resembled [deep throat](deep_throat.md).
History: it all started around 1985 as a program called ChipTest by some Taiwanese guy with unpronounceable name. It went on to win some computer chess tournaments and when multiple people were already working on it as a part of IBM research, it was renamed to Deep Thought after the computer in [Hitchhiker's Guide to the Galaxy](hgttg.md), however **it had to be later renamed to Deep Blue because the name too much resembled [deep throat](deep_throat.md)** :D By 1990 it has already played the world champion, Kasparov, but lost. In 1996 Deep Blue played him again, this time losing the match again but already having won a game, showing the potential was there. In May 1997, after upgrade both in hardware and software, it finally beat Kasparov with 3 wins, 2 losses and 1 draw.
{ Lol, according to Wikipedoa it trolled Kasparov in the first game by making a completely random move due to a bug once, it scared him because he thought it was some deeply calculated threat while it was just some completely dumb move. ~drummyfish }
It's important to see that Deep Blue wasn't really a general chess engine like [stockfish](stockfish.md), it was a single purpose supercomputer, a combination of [hardware](hw.md) and [software](sw.md) engineered from the ground up with the single purpose: win the match against Garry Kasparov. It was being fine tuned in between the games with assistance of grandmasters. A team of experts on computers and chess focused their efforts on this single opponent at the specific time controls and match set up, rather than trying to make a generally usable chess computer. They studied Kasparov's play and made Deep Blue ready for it; they even employed psychological tricks -- for example it had preprogrammed instant responses to some Kasparov's expected moves, so as to make him more nervous.
Technical details: Deep Blue was mainly relying on massively parallel [brute force](brute_force.md), i.e. looking many moves ahead and consulting stored databases of games; in 1997 it had some 11 [GFLOPS](flops.md). The base computer was IBM RS/6000 SP, using 32 [PowerPC](ppc.md) processors and 480 specialized "chess chips". It had evaluation function implemented in hardware. All in all the whole system could search hundreds of millions positions per second. Non-extended search was performed to a depth of about 12 plies, extended search went even over 40 plies deep. It had an opening book with about 4000 positions and endgame tablebases for up to 6 pieces. It was programmed in [C](c.md). { Sources seems to sometimes give different numbers and specs, so not exactly sure about this. ~drummyfish }
It wasn't really a general chess engine like [stockfish](stockfish.md), it was really programmed specifically for winning the match against Kasparov, it focused on his play and employed even psychological tricks -- for example it had preprogrammed instant responses to some Kasparov's expected moves, so as to make him more nervous.

@ -16,22 +16,23 @@ These are some **nice/interesting/benchmark articles** to look up in encyclopedi
## Notable/Nice Encyclopedias
Here is a list of notable encyclopedias, focused on general knowledge English language ones.
Here is a list of notable encyclopedias, focused on general knowledge English language ones. The most notable ones are in bold.
{ See also https://wikiindex.org/. ~drummyfish }
| name | year | legal status | format | ~articles | comment |
| ------------------------------ | ----- | ---------------- | ----------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| Britannica 11th edition | 1910 | PD (old) | 29 vol. | 40K | legendary enc., part of "Big Three", digitized (gutenberg, txt), uncensored facts on race etc. |
| Britannica 9th edition | 1889 | PD (old) | 25 vol. | |legendary enc., major edition, one of "Big Three", partly digitized (archive.org, wikisource, ...) |
| **Britannica 11th edition** | 1910 | PD (old) | 29 vol. | 40K |legendary enc., major edition, one of "Big Three", mostly digitized (both scan and txt), PC incorrect :) |
| Britannica Concise Encyclopedia| 2002 | proprietary | 1 vol. 2000p| 28K | nice, short descriptions, condensed from the main multivol. Brit., piratable pdf |
| Britannica online |...now | proprietary | online | 130K | bloated, high quality articles, unpaid is limited and with ads |
| **Britannica online** |...now | proprietary | online | 130K | bloated, high quality articles, unpaid is limited and with ads |
| [Citizendium](citizendium.md) |2006...|proprietary? (NC) | online | 18K | Wikipedia alternative, censored, faggots have unclear license |
| Collier's New Encyclopedia | 1921 | PD (old) | 10 vol. | | NOT TO BE CONFUSED with Collier's Encyclopedia (different one), digitized on Wikisource (txt) |
| Columbia Encyclopedia |1935...| proprietary | 1 vol. ~3Kp | ~50K | high quality, lots of information { Read the 1993 edition, it's super nice. ~drummyfish } |
|[Conservaedia](conservapedia.md)|2006...| proprietary | online | 52K | American fascist wiki, has basic factual errors |
| Larousse Desk Reference Enc. | 1995 | proprietary | 1 vol. 800p | 200K? | by James Hughes, nice, quality general overviews, topic-ordered { I bought this, it's nice. ~drummyfish } |
| Domestic Encyclopaedia | 1802 | PD (old) | 4 vol. | | shorter articles, partially digitized on Wikisource |
| Encyclopedia Americana |1820...| PD (old) | ~30 vol. | | longer articles, part of "Big Three", several editions (1906, 1920) partially digitized on Wikisource |
| Encyclopedia Americana |1820...| PD (old) | ~30 vol. | | longer articles, one of "Big Three", several editions (1906, 1920) partly digitized on wikisource |
| Encyclopedia Dramatica |2004...| PD (CC0) | online | 15K | informal/fun/"offensive" but valuable info (on society, tech, ...), basically no censorship, no propaganda |
| Everybodywiki |2017...| CC BY-SA | online | ~300K | alternative to Wikipedia allowing articles on non notable things and people |
| Google Knol | ~2010 | proprietary | online | | failed online enc. by Google, archived on archive.org |
@ -47,11 +48,11 @@ Here is a list of notable encyclopedias, focused on general knowledge English la
| The Nuttall Encyclopaedia | 1907 | PD (old) | 1 vol. | 16K | short articles, oldschool, digitized (gutenberg) |
| [Vikidia](vikidia.md) |2006...| CC BY-SA | online | 4K | "Wikipedia for kids", probably as censored as Wikipedia |
|Webster's Unabridged Dictionary |1864 | PD (old) | paper | 476K | short descriptions, digitized (gutenberg) |
| [Wikipedia](wikipedia.md) |2001...| CC BY-SA | online | 6M | largest and most famous, EXTREME PSEUDOLEFTIST CENSORSHIP AND POLITICAL PROPAGANDA, free culture |
| **[Wikipedia](wikipedia.md)** |2001...| CC BY-SA | online | 6M | largest and most famous, EXTREME PSEUDOLEFTIST CENSORSHIP AND POLITICAL PROPAGANDA, free culture |
| Old Wikipedia | 2001 | GFDL | online | 19K | archived old Wikipedia, less censorship, https://nostalgia.wikipedia.org |
| Pears' Cyclopedia | 1897 | PD (old) | 1 vol. 740p | | contains dictionary, general knowl. maps, reference etc., scanned on archive.org |
| World Almanac and Book of Facts|1868...| some PD (old) | 1 vol. | | interesting and useful information, data and facts from old to new age, US-centered |
| The World Book |1917...| proprietary | 22 vol. | 17K | best selling print enc., large, probably high quality |
| **The World Book** |1917...| proprietary | 22 vol. | 17K | best selling print enc., large, probably high quality |
| The World Book 1917 |1917 | PD (old) | 8 vol. | 3K | nicely readable |
| Uncyclopedia |2005...| proprietary (NC) | online | 37K | parody, [fun](fun.md) enc., "more normie friendly dramatica" |

@ -38,8 +38,7 @@ The following is a list of some "freedom friendly" hardware, i.e. hardware that
The following is a list of [firmware](firmware.md), [operating systems](os.md) and software tools that can be used to liberate freedom-friendly proprietary devices:
- **[coreboot](coreboot.md)**: "Open source" replacement for proprietary [BIOS](bios.md) in personal computers. For higher compatibility coreboot includes proprietary [binary blobs](binary_blob.md) for devices that require them, in a similar fashion to [Linux](linux.md), and so coreboot is not 100% free -- libreboot tries to fix this.
- **[libreboot](libreboot.md)**: Completely free version of coreboot, with proprietary blobs removed. However this very much limits the list of libreboot compatible devices.
- **[coreboot](coreboot.md), [libreboot](libreboot.md), [GNU boot](gnu_boot.md), [nonGeNUine Boot](nongenuine_boot.md) etc.**: More or less libre replacements for proprietary [BIOS](bios.md) in personal computers. Different projects here take different roads and tolerate different amounts of non-free binary blobs, just as different [Linux](linux.md) distros, so check out each one to pick whichever you like best.
- **[librerpi](librerpi.md)**: Libre boot firmware for [RPI](rpi.md).
- **[PostmarketOS](postmarketos.md)**: Mobile [GNU](gnu.md)/[Linux](linux.md) distribution that can be used to liberate smartphones.
- **[Replicant](replicant.md)**: Fork of [Android](android.md) mobile OS that replaces proprietary components with free software, can be used to liberate smartphones, though it is still [bloat](bloat.md).

Loading…
Cancel
Save