I am trying to make a 2 player chess program with a GUI in wxPython that is able to validate moves and follow every chess rule.
Right now, I am at the beginning of my design and figuring out which board representation technique I should use. I recently thought the obvious, two dimensional array, but then I read about the 0x88 board representation that is supposedly faster in terms of lookups and logically checks if the square is inside the chessboard or not. But, if I make a program without AI, there is no need to check if someone has moved a move that is outside of the board.
Is there any other advantages with the 0x88 representation that I'm not aware of and which one would you recommend , the 8x8 approach or 0x88. Also, would it be easy to first use a 8x8 representation , and then later, maybe if I decide to add AI, use the 0x88 one ? Thank you very much for your thoughts.
I agree with you that if you're not doing AI, there's not a lot of reason to micro-optimize like that.
One suggestion that I would make is that if you're considering switching from 8x8 to 0x88 (and in general, for good code quality) is that you should abstract out as much of the board access logic as possible into functions. For example, write and use a
getPieceAtLocation(char file, int rank)
and call
Piece p = getPieceAtLocation('e', 2);
or something along those lines. That way, if you decide to change your mind, you just need to re-write the logic in getPieceAtLocation
rather than changing every place where you have to use it.