Author: Bruce Moreland
Date: 16:39:10 07/07/98
Go up one level in this thread
On July 07, 1998 at 19:23:39, Tom Kerrigan wrote: >I want to write a very small chess program and I'm considering possible methods >to store a list of pieces. >Practically every time a chess program loops through a piece list, it's only >concerned with pieces or pawns of a particular color. Thus, I had this in mind: > >int piece_list[32]; >/* piece_list 0 to 7: white pieces > piece_list 8 to 15: white pawns > piece_list 16 to 23: black pieces > piece_list 24 to 31: black pawns >*/ >int white_pieces; >int white_pawns; >int black_pieces; >int black_pawns; > >I think this is reasonable until a piece needs to be removed. Then the computer >needs to figure out which list the piece belongs to, and this sounds >time-consuming. >Any comments or suggestions? This isn't going to be of any help. I heard about a program that, I presume, had one array for white and one for black, or maybe it was a two-dimensional array, and you could figure out where a piece was by indexing array[white][knight1] or array[white][pawn6] or whatever. So your pieces are all at constant locations in the array. This would work completely fantastically except for promotion. The problem in this case was that a piece couldn't be promoted unless another piece of that type had been captured. This would totally break in a modern program, I think you often end up with promotion cases while queens are on the board, and it would be hard to search if you had to simply stop there. And who knows what you'd do if you actually had to execute such a move in a real game. Your need for a piece list would, I guess, depend upon how wild you want to get about figuring out some stuff at run-time. It'd be a drag to go through the whole board to find pieces, and it would only get worse in relation to other methods as pieces came off. But if the only piece you really need to look up quickly is the king, in order to determine whether you are in check, you could keep track of that specially. I don't know how the old programs worked. bruce
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.