Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Programing: List of Pieces

Author: Andreas Guettinger

Date: 01:58:58 07/10/02

Go up one level in this thread


On July 09, 2002 at 23:41:39, Russell Reagan wrote:

>On July 09, 2002 at 20:20:16, Benny Antonsson wrote:
>
>>Then there would be a "hole" at index 4 ? (no piece)
>
>No. Maybe I explained it wrong. If you have a piece list, and you want to get
>rid of the piece at index 4, then you swap what is in index 4 with what is in
>the last index. Then you decrement the size of the piece list. Maybe a simpler
>example would be more clear.
>
>Here is your piece list: KRBP
>The size of the list is 4
>
>Now you want to remove the rook because it got captured (or whatever the
>reason). Now you switch the rook with the last piece, which is a pawn. The new
>piece list looks like this: KPBR. Now you decrement the size of the piece list,
>so the rook is still there on the end of the piece list, but when you iterate
>over the piece list, you will iterate over one less piece (since you decremented
>the size of the list). So your loop over the piece list would only produce KPB
>now, and you have removed the rook from the list (or so it appears).
>
>The piece list still contains the rook in the index 3, so if you want to add the
>rook back, you just increment the size of the list and now when you loop over
>the list you will "see" the rook again.
>
>A side effect of this is that the list will now look like KPBR instead of KRBP.
>So if the order of the pieces matters to you, this approach will not work.
>
>Another approach that might work is to have a 3D array of pieces as is done in
>EXChess.
>
>Russell

I really like this linked list idea from Hyatt. I have to clean the dust from my
C book and look it up once. Has anybody a linked piece list in his engine?

Andreas



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.