Author: Russell Reagan
Date: 12:10:11 03/03/03
Go up one level in this thread
On March 03, 2003 at 14:01:58, Andreas Guettinger wrote: >But then, when I have to scan to the piecelist, I have to scan through 12 lists. >I don't like that. > >regards >Andy Think about what you're doing. You are creating a list of piece indexes, or pointers, or whatever, so that you will only have to loop through the pieces once, instead of looping through the entire board. To update this piece list when you make or undo a move, you will need to know which entry to update, so why not add another lookup table to determine which entry in the piece list a particular square corresponds to? You could have something like this: int board[120]; // The board int occupied[2][16]; // Two lists of indexes of occupied squares int reverse[120]; // Contains indexes into the occupied array for the piece // on each square, "reverse lookup" int piece_count[2]; // Two values containing the number of pieces for each side Then you could have a function to add a piece to the board: void AddPiece (int square, int piece) { board[square] = piece; reverse[square] = piece_count[Color(piece)]; occupied[Color(piece)][piece_count[Color(piece)]++] = square; } Or you could manually add a piece like this: board[E1] = WHITE_KING; reverse[E1] = piece_count[WHITE]; occupied[WHITE][piece_count[WHITE]++] = E1; So then if you are making a move from (say) E1, you can find which piece list entry to update by using the reverse[] array. int entry = reverse[E1]; occupied[color][entry] = new_square; That's just one way to handle it, and I'm not sure how this affects sorting the piece list. But this is one way to easily update the piece list entry when you make or undo a move. One other method is to use pointers. This is done in Gerbil if you want to see some code.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.