r/ProgrammerHumor • • Apr 10 '23

Meme god why is coding chess so hard

Post image
67.4k Upvotes

1.8k comments sorted by

View all comments

Show parent comments

680

u/powerman228 Apr 10 '23

Good luck storing and compiling all that…aren’t there more possible games of chess than stars in the universe or something?

586

u/FuerstAgus50 Apr 10 '23 edited Apr 10 '23

more than atoms in the universe

https://www.youtube.com/watch?v=Km024eldY1A

324

u/[deleted] Apr 10 '23

We clearly need a bigger universe!

314

u/forty3thirty3 Apr 10 '23

from universe import *

139

u/newton21989 Apr 10 '23

I read that as from universe import star and then thought which star?

110

u/SleepyHarry Apr 10 '23

/usr/local/star

sol is a valid alias

35

u/forty3thirty3 Apr 10 '23

It's a star import. It imports all the stars.

→ More replies (13)
→ More replies (1)

13

u/3ggu Apr 10 '23

cp -R ../universe2/* .

→ More replies (4)
→ More replies (8)

129

u/AndyWatt83 Apr 10 '23

This is a cool way to visualise why it's not possible to 'solve' chess by brute force.
Say you wanted to build a lookup table for the best move in any given position. Even if you could find a way to encode a position onto a single atom, there are insufficient atoms in the universe to store all the positions in chess.

Moore's law cant save you, because there's not enough matter in the universe to build a big enough hard drive.

183

u/HungerISanEmotion Apr 10 '23

Even if you could find a way to encode a position onto a single atom, there are insufficient atoms in the universe to store all the positions in chess.

You always quit on the first obstacle?

34

u/[deleted] Apr 10 '23

I envision it as more encoding 32 qbits via user input and outputting a wave interference that maps out the solution, instead of w.e horror show this will be.

46

u/HungerISanEmotion Apr 10 '23

I don't know what that means, but it sounds complicated so it doesn't exist.

15

u/[deleted] Apr 10 '23

Sensible reasoning indeed

10

u/RhynoD Apr 10 '23

Qbits aren't 1 or 0, they're a superposition of every possible state. So one qbit is [0,1]. Two qbits make four positions [0,0; 0,1; 1,0; 1:1]. The superposition states are 2n where n is the number of qbits.

Getting the solution involves setting up the inputs such that the output is essentially the most likely result. The qbits are allowed to fall out of the superposition and end up as either 0 or 1, in the order that gives you (probably) the correct result.

The comment suggests building a quantum computer with 32 entangled qbits for 232 possible states and the output is probably the best move.

→ More replies (11)
→ More replies (2)

42

u/hornyfuckingmf Apr 10 '23

There are ways to make it smaller, for example you can take out board positions that are horizontal mirror images of another position, which cuts our storage in half.

Also you could only store white positions, since there's an equivalent black position for each, which cuts it in half again

Hard to think of more ways, but you could cut out positions that would only occur if both players play ridiculously unoptimally (for example positions where each player promotes several pawns)

Edit: Its probably still too large, but these are some good techniques. They have actually used the first two to solve all endgame positions up to like 6 pieces

25

u/Trezzie Apr 10 '23

Just remove all moves involving bishop variations, those do nothing anyways.

→ More replies (4)
→ More replies (8)

9

u/KUKURU3 Apr 10 '23

just use a hashtable lmao

→ More replies (17)
→ More replies (9)

82

u/JaDasIstMeinName Apr 10 '23

I love how you thought stars in the universe was insane and its even worse...

58

u/ThatOneStoner Apr 10 '23

Can't be that much more insane. How many atoms per star? Like 6, 7? 11 tops.

29

u/Din182 Apr 10 '23

Depends on the star, I think. I've heard some stars can have more than 20 atoms!

9

u/Gangreless Apr 10 '23

Pfft I have more than 20 atoms, stars are losers

11

u/[deleted] Apr 10 '23

Are you sure YOU are not a star?

8

u/Gangreless Apr 10 '23

Bitch I might be

→ More replies (3)
→ More replies (1)

43

u/Schlaueule Apr 10 '23

Good luck indeed. To store the first 10 moves in that manner would reqire 35 petabyte of memory, the first fifteen moves would require 1 billion petabytes, much more than the combined storage capacity on earth :-)

Surce: https://en.wikipedia.org/wiki/Shannon_number

→ More replies (10)
→ More replies (23)