Piece Lists

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Piece Lists

Postby matrix101 » 10 Jan 2016, 15:34


I looked some of these pages https://chessprogramming.wikispaces.com/Piece-Lists and https://pure.uvt.nl/ws/files/1098572/Pr ... 170609.pdf to get a description of how piece lists works. Still, afterwards it seems that they are more than a bit vague to me...
Most of the text books I have read so far, discuss about linked lists, not so much about plain C arrays. So it seems there is plenty of room for experiments here! Anyway I would be grateful for some idea how to use these lists, one or two dimensional arrays. Possibly that could cause some inspiration. I have done some simple programming in c like printing the board to the screen...

Code: Select all
void printboard(int *b)

   int rank, file, sq, piece;
   char PceChar[] = ".PNBRQKpnbrqk";     
   for (rank = 7; rank >=0; rank--) {     
      for (file = 0; file <= 7; file++) {
         sq = 8*rank+file;
         piece = b[sq];
         printf("%3c", PceChar[piece]);
Posts: 53
Joined: 02 Feb 2014, 12:46

Re: Piece Lists

Postby H.G.Muller » 10 Jan 2016, 23:30

In its simplest form a 'piece list' is just a table that tells you for every piece on which square it is standing. This saves you from scanning through the board every time to locate your own pieces. It could be a simple array, indexed by the 'piece number'. You could then run through the part of that array containg your own pieces when you ned them. You might even organie the list such that different piece types are in different 'sections', so that when you are interested in a specific piece type (say Rooks, for giving Rook on open-file or Rook on 7th-rank bonuses) you have to loop through the Rook section only to find all your Rooks.

One problem is that in the process of searching pieces get captured, so you would have to think about how to add or remove pieces from the piece list. You could simply mark them as absent through some invalid square number when they are captured. Then the list would always stay equally long, but it would be at most 16 entries, and runnning through it to find all your pieces would still be 4 times less work than scanning through a board of 64 squares. If something is captured at game level, you could squeeze out the piece that is now gone, as it will never come back (in normal Chess; in Crazyhouse that is of course different).

You could try to save time on running through the array by making it a linked list, so that following the links would make you skip over (and thus not waste time on) captured pieces. You would have to update the links whenever something is captured though. An alternative is to use a one-word 'presence mask' that contains one bit for every piece to tell if it is captured or not, and use bit-extraction techniques to only loop over uncaptured pieces.

If you have organized the piece list by piece type, you would have to make sure on promotion that everything is still in the right section. This might involve assigning a new number to the promoted piece, because it must be elsewhere in the table as the Pawn it came from.
User avatar
Posts: 3080
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 2 guests