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

9

u/[deleted] Apr 10 '23

The square colors are wrong

3

u/ElpredePrime Apr 10 '23

square

Yeah this is terrible code...

The lighter square should be on the bottom right.

3

u/realmuffinman Apr 10 '23

Not to mention the input syntax doesn't take into account which piece you are moving. With this as written, an input "C3" could refer to the white queen-side bishop's pawn advancing one square (pc3) or the queen-side knight moving forward and right (nc3). This would get more complicated as the game continues, where you could feasibly have 4+ pieces able to move to a given space.

3

u/GreatArtificeAion Apr 10 '23

Debatable

3

u/realmuffinman Apr 10 '23 edited Apr 10 '23

Not really, the standard is to have a white square in the bottom right and top left corners of the board, and this would have white in top right and bottom left.

Edit: on closer inspection, since the unfilled pieces move first, the board is set up such that unfilled=white and filled=black, so the board is correctly oriented with respect to square color. This leaves the only issue being that the black king and queen are switched.

1

u/GreatArtificeAion Apr 10 '23

The clause between commas is true. However, what counts as a black square and what counts as a white square in the code snippet? Is the empty square black because it looks black on a dark theme? Or is it white because it isn't filled? It's ambiguous, that's why the original statement is debatable

1

u/realmuffinman Apr 10 '23

As I was trying to respond to this, I looked closer and realized that since white moves first, the empty squares are white because they match the empty-colored pieces that move first. Assuming the programmer was consistent with the rules for who moves first, this board is in fact set up correctly.