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

189

u/JonIsPatented Apr 10 '23

2 × 1046 possible board states, yes.

158

u/pappapirate Apr 10 '23

if you're coding it this way you would have to code every possible sequence of moves that result in each position, not just the positions.

76

u/ALiteralMermaid Apr 10 '23

Yeah you would literally have done the same amount of work as solving chess which is obviously not feasible

26

u/cloverasx Apr 10 '23

Yet.

19

u/[deleted] Apr 10 '23

It’s in the range of 10120 possible games which is larger than the number of atoms in the observable universe

12

u/GregTheMad Apr 10 '23

What if we use a binary tree? /s

4

u/cloverasx Apr 10 '23

10¹²⁰ ≠ ∞

7

u/barofa Apr 10 '23

Of course it is different than the laying eight

4

u/cloverasx Apr 10 '23

It just needs a nap; poor eight's all tuckered out.

4

u/[deleted] Apr 10 '23

I’m not saying it’s impossible but it would mean rethinking what we think it means to ‘solve’ a game. As it stands now chess is solved with 7 pieces on the board. It we are solving with the same method there literally isn’t enough matter in the universe to even come close to storing the information—you certainly can’t store a chess position with a single atom. The only way this works is with a breakthrough in quantum computing or something where we can access information without storing it in the traditional sense.

1

u/[deleted] Apr 11 '23

You're assuming we have to brute force it. What if we just find a smart way to deduce a strategy that guarantees white wins/black draws exists?

→ More replies (4)

2

u/meta-rdt Apr 10 '23

quite simply, there is no physical way for us to build a computer capable of storing the information required to compute something like that.

→ More replies (1)

0

u/[deleted] Apr 10 '23 edited Apr 10 '23

Also, I’m not sure you understand how big of a number this is

0

u/cloverasx Apr 11 '23

I'm quite certain I do.

0

u/[deleted] Apr 11 '23

And you think there are infinite atoms in the observable universe?

0

u/cloverasx Apr 11 '23

You're making some bad assumptions.

→ More replies (0)

3

u/aboinpallymusic Apr 10 '23

once OP finishes we'll do it

→ More replies (1)

6

u/l3rowncow Apr 10 '23

Well not with that attitude…

→ More replies (1)

1

u/palparepa Apr 10 '23

Yeah, using else/if branches is insane; lots of repeated paths. Should have used gotos instead.

1

u/Ferro_Giconi Apr 10 '23 edited Apr 10 '23

You can skip that by comparing the board state to every possible board state with if else if until you find the current board state instead of making new branches for every possible sequence of moves.

I mean, sure, the universe will probably end before the massive if else if finishes, but at least it's less code.

1

u/[deleted] Apr 10 '23

That's more half the amount of the protons in the observable universe

→ More replies (6)

1

u/Dye_Harder Apr 10 '23 edited Apr 10 '23

2 × 1046 possible board states, yes.

LEGAL board states? Or just ways pieces can be arranged on the board?

Is this a legal state?

https://imgur.com/a/5ZQou5w

also how many moves are allowed in these calculations? Most chess games have move limits, and many 'positions' will be impossible without huge move counts

2

u/JonIsPatented Apr 11 '23

2 × 1046 was the number calculated by people much smarter than me to be the number of board states that are theoretically reachable in a legal game.

1

u/Zut-Alors20 Apr 10 '23

Welp, best get started then

→ More replies (1)