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

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.

2

u/SuperJetShoes Apr 10 '23

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.

It's at this point that my brain clangs out. Surely "setting the inputs up such that the output is essentially the most likely result" means that you already had to solve the problem of which is the best next chess move, then set up the inputs such that it falls out as the most likely output.

I don't get where all the rules of chess which govern the legality of each successive move are encoded in that system.

→ More replies (10)

3

u/[deleted] Apr 11 '23

quantum?

2

u/IAmKermitR Apr 11 '23

Just encode it in quarks

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 (1)

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!

3

u/WatersLethe Apr 10 '23

"Further optimization is left as an exercise for the reader"

2

u/EgoPoweredDreams Apr 10 '23 edited Apr 10 '23

You can also remove a ton of illegal positions that would’ve required Black to move first.

Edit: Never mind, I’m thinking of a different game theory paper.

3

u/hornyfuckingmf Apr 10 '23 edited Apr 10 '23

Maybe some, but there is a lot of ways to do no-ops by moving pieces and then move them back,

For example consider the following set of moves:

White moves either knight out

Black pushes king pawn forward 1

White moves their knight back to the starting square

Black pushes their king pawn forward 1 more

Final Position: identical to the position if white moved king pawn forward 2, but from black. (Technically en passant isn't available, but that's irrelevant if it's not a possible move)

→ More replies (1)

2

u/Subspeakers Apr 10 '23

This breaks client's requirements.

→ More replies (1)

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.

2

u/Eckish Apr 10 '23

That's why you have to compress the data so that each atom has the potential to carry more than one bit of information.

2

u/birbBadguy Apr 10 '23
from multiverse import matter

1

u/magicmulder Apr 10 '23

You can optimize a lot though. Weed out all illegal positions and most of those that are either super improbable or totally lost anyway (anything where you’re down more than a piece) and you may be closer. Also you could compress a lot by only storing certain positions fully and then all the others by only storing the difference to the reference positions.

The real impractical part is generating all the positions to begin with. Even if you had the storage, you couldn’t write that much data in billions of years.

→ More replies (13)