4

To store pieces inside an array of 64 squares (inside a one-dimensional chessboard), I would simply convert squares like:

  • 0 is a8
  • 1 is b8
  • 2 is c8

...

  • 63 is h1

This order would be natural for me, as we can then easily loop and display each square to represent the board on a document, having at the bottom the white perspective.

But looking at some documents on the computer chess, such as the 0x88 board representation, it seems that the standard way to order pieces in rather this:

  • 0 is a1
  • 1 is b1

...etc.

Do you think I should definitivly use this same ordering? Or would it make more sense to adopt the more natural order (0 is a8)?

1
  • I would definitely find it more natural to start at a1, for starters because it is the "smallest" square as in, smallest letter and smallest digit. However in my engine I actually go slightly differently and have 1 = a2 etc. This is definitely unusual, my idea there was that square number is letter * 8 + row. However if I wrote it now I'd definitely comply with the typical b1 = 1. (and probably will change it at some point)
    – koedem
    Dec 21 '20 at 12:23
8

They're both equally natural, they just start at a different square. But that choice is arbitrary anyway. Printing to a terminal is one of the least critical things a chess engine does with a board, and looping can go in the other direction just as easily.

If you want to be able to easily copy algorithms or code from examples or other engines (the license of which allows you to do that), it can be helpful to use the same conventions as most people do. But that's completely up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.