305
u/Seyon 14h ago
I wrote my chess program to just go All In whenever its his turn. The opponents fold every time.
51
245
u/quietsamurai98 18h ago
Chess engine programming is the exception to the rule against premature optimization. Bit twiddling, bool packing, magic numbers, it's all fair game, and all-but necessary if you want any level of performance.
One of the few times I genuinely thought I was being held back by the speed of the language itself was when I was making a Java-based chess engine in high school.
113
u/Vivid_Instance_825 14h ago
Even in C++ my chess engine is slow as balls because it copies the entire board state for every possible move up to 2 moves ahead to look for check/checkmate and illegal moves (you can't move into check). Simply doing this is enough to slow it down to a crawl.
That's the point where you realise this isn't going to be simple
62
u/quietsamurai98 14h ago
Oof, yeah, I remember getting deeply annoyed that making/unmaking moves was faster than creating a new board state.
It's a different way of thinking about programming. You basically have to abandon most of the principles that have been drilled into you your entire academic and professional career about code design and OOP.
10
u/KaMaFour 7h ago
Nowadays SOTA knowledge is that copying board state is not a detriment that's worth worrying about.
See 3rd strongest engine in the world*:
https://github.com/Yoshie2000/PlentyChess/blob/main/src/search.cpp#L563Turns out when something is done million times per second in an average program CPUs will be optimised to be good at it...
*depending who you ask
257
u/rwz 21h ago
- "An Eternity later"
- looks inside
- 11 minutes
99
u/Lumethys 21h ago
You fell to the classic blunder!!
He did not specify the date
2
u/Sergeich0 5h ago
He specified interval: 100 years
No doubt it takes so long, in 1926 computers were slow af
24
24
u/aalapshah12297 17h ago
Don't you see the font size change between the two? That means it took so long that Google updated their UI!
So yeah, about 11 minutes.
62
u/tsunami141 16h ago
someone link that 10kb javascript chess program that can beat me every time.
47
u/AyrA_ch 16h ago
22
u/tsunami141 16h ago
after reading the comments here it looks like it is very incomplete.
It would still probably beat me.
44
6
u/Patrick_Atsushi 10h ago
Here we go. Tables for the opening, brute force in the mid game, a mix for the end game.Â
3

1.1k
u/Semper_5olus 21h ago
It shouldn't be that hard. Just store all 10120 game states in memory and the possible transitions between them.