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

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.

32

u/newton21989 Apr 10 '23

big_bang.py

7

u/mjc4y Apr 10 '23

That code runs fine but man, that init() function is gonna spike your cpu. Do NOT look at the cpu temp while it runs. You’ll probably get a floating point overflow in the worst way.

And it runs for like 300,000 years before it produces visible results.

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

13

u/3ggu Apr 10 '23

cp -R ../universe2/* .

→ More replies (4)

4

u/Anomalous-Entity Apr 10 '23

It is!

There it is again!

→ More replies (7)

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.

4

u/MossyDrake Apr 10 '23

r/AnarchyChess found a good move involving bishops.

4

u/Trezzie Apr 10 '23

Look, yes the 2800 rated players who all frequent r/AnarchyChess can use bishops well, but handicapping yourself and playing suboptimal isn't something we want nor expect players to actually do.

If you want to know a better way to play when you don't handicap yourself using bishops, just Google en passant.

→ More replies (2)

4

u/Blacksmithkin Apr 10 '23

Pretty sure we've solved all up to 7, 8 is theoretically plausible, and 9 will likely never happen.

4

u/MartianInvasion Apr 10 '23

Nice! A few more optimizations like that, and you may be able to get the number of positions you need from a billion billion billion times the number of atoms in the universe, all the way down to a billion billion million times the number of atoms in the universe!

→ More replies (1)
→ More replies (5)

9

u/KUKURU3 Apr 10 '23

just use a hashtable lmao

6

u/[deleted] Apr 10 '23

Well, in theory there are likely enough atoms for that because there are a ton of "irrelevant" positions - of course, it's difficult to tell which positions are irrelevant or not before you've already solved it, but once it is solved there's no need to consider positions that would never occur because playing in a way that results in those positions would always be suboptimal play (even when you make no assumptions of what the opponent is doing), or one player is far enough ahead that they have many winning options and they can disregard the ones that create new board states because they'll win either way so they may as well reuse the one that's already solved instead of creating a new one.

→ More replies (16)

4

u/MindStalker Apr 10 '23

I had to listen multiple times, I kept thinking he was saying 10^18 atoms in the universe, which is obviously wrong. (He says 10 to the 80, which is correct)

→ More replies (8)