Author: Roberto Waldteufel
Date: 22:35:26 11/02/98
Go up one level in this thread
On November 02, 1998 at 21:45:05, Robert Hyatt wrote: >On November 02, 1998 at 17:58:06, John Stoneham wrote: > >>In my program GrimReaper, I use a simple function consisting of a pre-calculated >>mask value and a pre-calculated shift value (more pertinent to diagonal >>rotations, but still usefull to the 90 degree rotation) to extract the 8-bit >>code necessary for accessing the (again) pre-calculated attacked squares for the >>given rotation (Queen/Rook or Queen/Bishop). Obviously, for unrotated >>orientations, or 90 degree rotations, the masks and shifts are simple. But >>diagonals are more complicated, and the use of an array of precalulated shifts >>and masks for the given orentation seems necessary. Since these are calculated >>before the engine is started, it seems simple to calculate the 90 degree shifts >>and masks as well. Then all you need is a ((Bitboard & mask) << shift) type of >>routine to get the 8-bit has value, regarless of the rotation. (More information >>on my routines is available in my GrimReaper journal at >>www.geocities.com/SiliconValley/Lab/4714/index.html). Does any handle this >>calculation differently? > >a couple of tricks... > >1. you can use square&56 as the shift amount for the 90 degree rotated bit map, >since that will get you exactly the right shift count for any rank... > >2. you may use a bishop shift value, but you can get away by always using 8 >bits from the rotated diagonal bitmaps, if you simply set up the array so that >the "unused bits" still produce the right answer. This avoids having a >different mask for each diagonal length... Hi Bob You can in fact get away with only 6 bits. Since the key produced after you shift the bits is only to be used as an index for the table lookup, you only need to know the status (occupied or vacant) of squares *that could affect the attack map*. Now squares on the edge of the board can never affect the attack maps, so when you first AND the rotated bitboard with the diagonal mask key for a given square, you can blank out the edge-bits of that diagonal. There are in fact only 36 squares on the chess-board whose occupancy you need to know in order to generate the diagonal attack maps for all 64 squares. This means that the number of relavent squares on any diagonal is two less that the number of squares in that diagonal. Using this trick I only used 6 bits to make my index, so my look-up table was reduced in size by a factor of 4. You can do the same with the ranks and files of course - just blank out the first and last bit of each rank-mask and file-mask, and you get a 6-bit index that contains all the necessary information. Best wishes, Roberto
This page took 0.01 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.