Answers.Body: <p>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.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-21T11:07:19.780Z
Answers.LastActivityDate: 2020-12-21T11:07:19.780Z
Answers.UserDisplayName: RemcoGerlich
Body: <p>To store pieces inside an array of 64 squares (inside a one-dimensional chessboard), I would simply convert squares like:</p>
  <ul>
  <li><code>0</code> is a8</li>
  <li><code>1</code> is b8</li>
  <li><code>2</code> is c8</li>
  </ul>
  <p>...</p>
  <ul>
  <li><code>63</code> is h1</li>
  </ul>
  <p>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.</p>
  <p>But looking at some documents on the computer chess, such as <a href="https://en.wikipedia.org/wiki/0x88" rel="nofollow noreferrer">the 0x88 board representation</a>, it seems that the standard way to order pieces in rather this:</p>
  <ul>
  <li><code>0</code> is a1</li>
  <li><code>1</code> is b1</li>
  </ul>
  <p>...etc.</p>
  <p>Do you think I should definitivly use this same ordering?
  Or would it make more sense to adopt the more natural order (<code>0</code> is a8)?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-21T12:23:13.460Z
Comments.Text: 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)
Comments.UserDisplayName: koedem
Tags: <programming><chessboards>
Title: Order of pieces in one-dimensional array
ThreadText: # Order of pieces in one-dimensional array
  
  (Asked by: username_0 on 2020-12-21)
  
  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](https://en.wikipedia.org/wiki/0x88), 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)?
  
  **Tags:** programming, chessboards
  
  > **Comments:**
  > **username_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)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-12-21. Score: 7 | Accepted answer
  
  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.
  
  
  ---
  
  