Search code examples
.netalgorithmchess

what would you do in a chessboard? (piece position)


would you create 3 list(of coordinate) for

  • empty position
  • black position
  • white position

or just looping though the array when needed and play with the result every time?

what would be best? (speed wise)


Solution

  • Your two main choices are between speed and code clarity.

    If speed is your priority then you must use a 64 bit data type for each set of pieces on the board (e.g. white pawns, black queens, en passant pawns). You can then take advantage of native bitwise operations when generating moves and testing move legality.

    If clarity of code is priority then forget bit shuffling and go for nicely abstracted data types like others have already suggested. Just remember that if you go this way you will probably hit a performance ceiling.

    To start you off, look at the code for Crafty (C) and SharpChess (C#).

    (Originally posted here)