Skip to content

Commit 02a3bf5

Browse files
committed
feat: add all notes files
1 parent 967944e commit 02a3bf5

60 files changed

Lines changed: 2769 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
+++
2+
title = "Chess Engine"
3+
date = 2026-01-05
4+
updated= 2026-05-31
5+
[taxonomies]
6+
tags = ["index"]
7+
+++
8+
9+
## References {#references}
10+
11+
<https://www.chessprogramming.org/Main_Page>
12+
<https://www.chessprogramming.org/Stockfish>
13+
14+
Notes on chess engine implementations and optimizations.
15+
16+
17+
## Engine Backend {#engine-backend}
18+
19+
This forms the foundation of the engine.
20+
21+
22+
### [Chess Engine Board Representation](@/notes/20260110011115-chess_engine_board_representation.md) {#chess-engine-board-representation--20260110011115-chess-engine-board-representation-dot-md}
23+
24+
25+
### [Chess Engine Move Generations](@/notes/20260110020247-chess_engine_move_generations.md) {#chess-engine-move-generations--20260110020247-chess-engine-move-generations-dot-md}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
+++
2+
title = "Chess Engine Board Representation"
3+
date = 2026-01-10
4+
updated= 2026-05-31
5+
+++
6+
7+
## Basics {#basics}
8+
9+
The board representation is simply how the board is represented. This is split
10+
into two main types
11+
12+
13+
### Piece Centric {#piece-centric}
14+
15+
This representation answers the following question: for a given piece, what
16+
square is it at?
17+
18+
[Chess Engine Bitboards](@/notes/20260110013017-chess_engine_bitboards.md) are the preferred choice.
19+
20+
Piecelists and Piecesets are alternative implementations using a list or set
21+
to hold the pieces
22+
23+
- piecelists: array or list with 32 pieces, holding their square information
24+
- piecesets: uses bits in 32 bit word to point to index in piecelist
25+
26+
References
27+
28+
- <https://www.chessprogramming.org/Piece-Lists>
29+
- <https://www.chessprogramming.org/Piece-Sets>
30+
31+
32+
### Square Centric {#square-centric}
33+
34+
This representations answers the following question: for a given square, what
35+
piece is on it?
36+
37+
Mailbox is main way to do this, and simply means a memory location holds
38+
some information about the square. The main way is to simply use a large
39+
array
40+
41+
- 8x8 board: [Chess Engine 8x8](@/notes/20260110015928-chess_engine_8x8.md)
42+
- 10x12 board: the extra rows and columns serve as sentinels to notify when a
43+
piece goes off the board as the result of an attack
44+
- vector attacks: encodes into a table how a piece may move using vectors
45+
- 0x88 (16x8 board): uses the upper bit to determine out of board pieces,
46+
compliments vector attacks
47+
48+
References:
49+
50+
- <https://www.chessprogramming.org/10x12_Board>
51+
- <https://www.chessprogramming.org/Vector_Attacks>
52+
- <https://www.chessprogramming.org/0x88>
53+
54+
55+
### Hybrid {#hybrid}
56+
57+
While an engine can focus on one representation, it will also use the other
58+
representation as well. For example
59+
60+
- bitboard-based might also use 8x8 board
61+
- 8x8 might also use piece-lists
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
+++
2+
title = "Chess Engine Bitboards"
3+
date = 2026-01-10
4+
updated= 2026-05-31
5+
+++
6+
7+
Uses a 64 bit to hold information. In general, you would have two bitboards (one
8+
for white and one for black) for each piece type. On the bitboard, if a square
9+
is occupied than it is marked with a 1.
10+
11+
Bitboards have the advantage of using bit-twiddling to generate moves which
12+
takes very few instructions and is also very fast.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
+++
2+
title = "Chess Engine 8x8"
3+
date = 2026-01-10
4+
updated= 2026-03-07
5+
+++
6+
7+
## Implementation {#implementation}
8+
9+
Very simple implementation, see below
10+
11+
```c
12+
int piece[64] = {
13+
BROOK, BKNIGHT,BBISHOP,BQUEEN, BKING, BBISHOP,BKNIGHT,BROOK,
14+
BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN,
15+
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
16+
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
17+
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
18+
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
19+
WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN,
20+
WROOK, WKNIGHT,WBISHOP,WQUEEN, WKING, WBISHOP,WKNIGHT,WROOK
21+
};
22+
```
23+
24+
Using a square-centric representation is easy and intuitive, but when using
25+
these for chess engine move generation, long and nested loops are often required.
26+
27+
While you can pair this with a vector attack (see [Chess Engine Board Representation](@/notes/20260110011115-chess_engine_board_representation.md)),
28+
for efficiency and less loops, it is much more common to use a bitboard
29+
for move generation and then use this for square lookups.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
+++
2+
title = "Chess Engine Move Generations"
3+
date = 2026-01-10
4+
updated= 2026-03-07
5+
+++
6+
7+
## Types of Moves {#types-of-moves}
8+
9+
Moves can divided into two categories
10+
11+
- pseudo-legal: obeys chess movement rules, but does not account for the king being in check
12+
- legal: like pseudo-legal, but checks if the king is in check
13+
14+
Move generation can verified using **pertf**, which is program which generates all moves from
15+
a given position to a given depth. This is then compared with an existing engine to verify
16+
move generation correctness.
17+
18+
19+
## Bitboard Move Generation {#bitboard-move-generation}
20+
21+
Since bitboards are the preferred representation, this
22+
part will only show move generation for bitboards.
23+
24+
- [Chess Engine Pawns](@/notes/20260110021336-chess_engine_pawns.md)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
+++
2+
title = "Chess Engine Pawns"
3+
date = 2026-01-10
4+
updated= 2026-05-31
5+
+++
6+
7+
Pawn move generation using bitboards. For pawn pushes (moving pawn forward), we
8+
can implement this by shifting the bitboard up (for white pawns), and then
9+
taking the intersection of the empty board (to ensure no piece is blocking the
10+
push). Note that pawns in their starting position can move up two squares.
11+
12+
```c
13+
U64 wSinglePushTargets(U64 wpawns, U64 empty) {
14+
return nortOne(wpawns) & empty;
15+
}
16+
17+
U64 wDblPushTargets(U64 wpawns, U64 empty) {
18+
const U64 rank4 = C64(0x00000000FF000000);
19+
U64 singlePushs = wSinglePushTargets(wpawns, empty);
20+
// if a pawn is not in the fourth rank after double pushing,
21+
// then it is not in its starting position and therefore
22+
// not allowed to move two squares
23+
return nortOne(singlePushs) & empty & rank4;
24+
}
25+
26+
U64 bSinglePushTargets(U64 bpawns, U64 empty) {
27+
return soutOne(bpawns) & empty;
28+
}
29+
30+
U64 bDoublePushTargets(U64 bpawns, U64 empty) {
31+
const U64 rank5 = C64(0x000000FF00000000);
32+
U64 singlePushs = bSinglePushTargets(bpawns, empty);
33+
return soutOne(singlePushs) & empty & rank5;
34+
}
35+
```
36+
37+
We use separate implementations for optimization. To check beforehand if a pawn
38+
is allowed to push, shift the empty board in the reverse direction, and if the
39+
pawn is there, that means it can push
40+
41+
```c
42+
U64 wPawnsAble2Push(U64 wpawns, U64 empty) {
43+
return soutOne(empty) & wpawns;
44+
}
45+
46+
U64 wPawnsAble2DblPush(U64 wpawns, U64 empty) {
47+
const U64 rank4 = C64(0x00000000FF000000);
48+
U64 emptyRank3 = soutOne(empty & rank4) & empty;
49+
return wPawnsAble2Push(wpawns, emptyRank3);
50+
}
51+
```
52+
53+
For attacks, since pawns attack diagonally we can shift the bitboards of the
54+
pawns diagonally one square
55+
56+
```c
57+
U64 wPawnEastAttacks(U64 wpawns) {return noEaOne(wpawns);}
58+
U64 wPawnWestAttacks(U64 wpawns) {return noWeOne(wpawns);}
59+
60+
U64 bPawnEastAttacks(U64 bpawns) {return soEaOne(bpawns);}
61+
U64 bPawnWestAttacks(U64 bpawns) {return soWeOne(bpawns);}
62+
63+
U64 wPawnAnyAttacks(U64 wpawns) {
64+
return wPawnEastAttacks(wpawns) | wPawnWestAttacks(wpawns);
65+
}
66+
67+
U64 wPawnDblAttacks(U64 wpawns) {
68+
return wPawnEastAttacks(wpawns) & wPawnWestAttacks(wpawns);
69+
}
70+
71+
U64 wPawnSingleAttacks(U64 wpawns) {
72+
return wPawnEastAttacks(wpawns) ^ wPawnWestAttacks(wpawns);
73+
}
74+
```
75+
76+
For efficiency, we precomputed attacks from a given position into an array, and
77+
then by intersecting that with the bitboard of black pieces we can determine if
78+
a capture is possible, like the following
79+
80+
```c
81+
whitePawnAttacks = arrPawnAttacks[white][sqOfWhitePawn];
82+
if (whitePawnAttacks & pieceBB[black]) -> pseudo legal captures possible
83+
```
84+
85+
En passant is kind of difficult to implement. Note that a pawn can only be captured
86+
via en passant if if double-moved, and if there are enemy pawns next to it.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
+++
2+
title = "Learning"
3+
date = 2026-01-12
4+
updated= 2026-05-31
5+
[taxonomies]
6+
tags = ["index"]
7+
+++
8+
9+
## Learning is Hard {#learning-is-hard}
10+
11+
Yes, learning is kind of hard. Like really hard. Here is a small primer
12+
regarding [10 Things Software Developers Should Learn about Learning](@/notes/20260112015951-10_things_software_developers_should_learn_about_learning.md).
13+
14+
15+
## Learning How to Learn {#learning-how-to-learn}
16+
17+
Here is[ How to read a paper](@/notes/20260112020552-how_to_read_a_paper.md). For reading something other than a paper,
18+
the[ SQ3R](@/notes/20260112021933-sq3r.md) method for textbooks and other texts. For lectures there is
19+
[Cornell Notes](@/notes/20260112023127-cornell_notes.md).
20+
21+
22+
## Review these Later {#review-these-later}
23+
24+
<https://www.youtube.com/watch?v=CjVQJdIrDJ0&t=1224s>
25+
<https://en.wikipedia.org/wiki/Moonwalking_with_Einstein>
26+
27+
28+
## Teaching? {#teaching}
29+
30+
<https://en.wikipedia.org/wiki/Instructional_design>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
+++
2+
title = "10 Things Software Developers Should Learn about Learning"
3+
date = 2026-01-12
4+
updated= 2026-05-30
5+
+++
6+
7+
## The Facts {#the-facts}
8+
9+
While it said it is for software developers, I think this is generally
10+
extensible for anyone, as the information provided is not limited to
11+
software engineers.
12+
13+
14+
### Not Made of Bits! {#not-made-of-bits}
15+
16+
Our brain updates as it recalls information, so called "spreading activation".
17+
So when we try to remember something
18+
19+
1. a pathway of neurons is activated
20+
2. this activation occurs on multiple pathways
21+
3. the activation leaves the pathways primed for hours
22+
23+
This read and update process is called ****reconsolidation**** which is very different
24+
from a computer, as when you perform a read on some bits, it does not modify it.
25+
26+
These primed pathways can sometimes cause unrelated topics to become related
27+
(bad for memory) but the primed pathways are great for problem solving! This
28+
is why spending time away from a problem can help you come up with an interesting
29+
solution (different pathways are being explored).
30+
31+
32+
## Reference {#reference}
33+
34+
<https://cacm.acm.org/research/10-things-software-developers-should-learn-about-learning/>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
+++
2+
title = "How to read a paper"
3+
date = 2026-01-12
4+
updated= 2026-05-31
5+
+++
6+
7+
## Three Pass Approach {#three-pass-approach}
8+
9+
Basically, when reading a paper, you should do three passes through it.
10+
11+
12+
### First Pass {#first-pass}
13+
14+
Should take five to ten minutes: read title, abstract and introduction, read
15+
section and subsection headings, read conclusion. As you read, ask
16+
17+
- category: what type of paper is this (what is it about)?
18+
- contrast: which other papers is this related to (what does it build off, does
19+
it lead to another paper)?
20+
- correctness: are the assumptions correct?
21+
- contributions: what are the paper's main contributions (main idea / thurst)?
22+
- clarity: is the paper well written
23+
24+
If answering these questions puts the paper in a bad light, you probably should
25+
not continue reading it.
26+
27+
28+
### Second Pass {#second-pass}
29+
30+
Should take about an hour: read everything but proofs, read figures, diagrams,
31+
and illustions, mark unread references to read later, write key points and
32+
comments as you read.
33+
34+
If the figures and diagrams are of low quality, then that is a bad indication
35+
for the paper.
36+
37+
After this, you should understand the main idea of the paper and should be able
38+
to summarize it along with supporting evidence.
39+
40+
41+
### Third Pass {#third-pass}
42+
43+
Try to recreate the paper and comparing your recreation with the papers, that is
44+
as you read through the paper in greater detail and doing the following:
45+
46+
- make the same assumptions as the authors
47+
- identify and challenge the assumptions made by the authors
48+
- think of how you would present the idea
49+
50+
This should take about five hours, but at the end you should be able to recreate
51+
the entire paper from memory and identify its strong and weak points, this
52+
means pointing out implicit assumptions, missing citations, and issues with the
53+
experimentation or analysis.
54+
55+
56+
## Reference {#reference}
57+
58+
<https://web.stanford.edu/class/cs114/reading-keshav.pdf>.

0 commit comments

Comments
 (0)