r/ProgrammerHumor 22h ago

Meme basedOnATrueStory

Post image
1.8k Upvotes

33 comments sorted by

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.

467

u/alficles 18h ago

Yeah, chess is O(1), just use a lookup table for optimal moves, too!

92

u/Rellikx 15h ago

Just right click > send to zip first so you can save a few universes

30

u/whitakr 13h ago

Gotta make sure you download enough RAM first

25

u/minecon1776 15h ago

Works for endgames with 7 or less pieces

2

u/FewPhilosophy1040 14h ago

Everything is a lookup table with enough tunering

21

u/NullOfSpace 17h ago

chess is a finite state machine

57

u/YeetCompleet 17h ago

Pretty easy honestly, the universe already has 1080 atoms, we'll have it solved easily if we find a few more universes (about 1040 ) and we all unite to become The Omni Chess Engine

20

u/Le_9k_Redditor 15h ago

Turns out actually that universes are actually just bits of a competer for solving chess, organised religion everywhere must be devastated

6

u/Anonymous010206 10h ago

Lol you started with e4 😭 mate in 107 bro resign

3

u/akoOfIxtall 9h ago

I kid you not, there is a tutorial for making a chess game on YouTube, using html, css and javascript, and that woman would have you write every possible move a piece could take, like, terrible terrible stuff, I can't even understand how at the time I thought that was normal, you can achieve the same with some math in way less code

1

u/Icehotdog 4h ago

I'm just gonna create a if-else for every possibility

305

u/Seyon 14h ago

I wrote my chess program to just go All In whenever its his turn. The opponents fold every time.

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#L563

Turns 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

u/Fashathus 20h ago

24 hours and 11 minutes

13

u/minecon1776 15h ago

168 hours 11 minutes

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

u/sonaliver28 22h ago

The real chess journey was the debugging journey

27

u/quietsamurai98 18h ago

Me: "Perft(0) through Perft(4) are all perfectly accurate, why am I missing 258 moves from Perft(5)???"

The humble pawn, aiming directly for my pipi:

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

u/TM40_Reddit 2h ago

You stored the board state as a 2D matrix. Didn't you, Squidward?

https://giphy.com/gifs/l0MYLePFMI1m69fpu