Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: 40%

Author: Dann Corbit

Date: 14:28:39 10/22/04

Go up one level in this thread


On October 22, 2004 at 17:12:07, Stuart Cracraft wrote:

>My program spends 40% of its total time in the routines
>determining if a given square is attacked.
>
>Surely there must be a better way.

If you use bitmaps, you can calculate all the attacks (and even the pins and
half-pins) in a single table lookup for any ray of attacks.

For any position on the board, there are at most 7 squares attacked along a ray
(since you never attack the square you sit on).  Now, of those 7 squares there
are exactly 128 different bit occupation patterns.  So you precompute a table of
those patterns.  It does not matter if your precomputation is efficient or not,
since you are just creating a table and you will use the precomputation program
to write out a table (or you can compute it at program startup).

consider the white rook in this diagram and the rank 5 attacks:
[D]8/8/p1P5/Pn1R1b1k/8/6n1/8/2K5 w - -
The moves bitmap is:
01100100
The attacks bitmap is:
01000100
The kingpins bitmap is (you may also want to calculate queen pins, etc.):
00000100
The shadows bitmap is (shadows are squares effected if the nearest piece on the
ray was moved or captured):
10000011

For every one of the 128 possible bit patterns, precompute these (and any other
bitmaps you may find useful).
Then, when you want to know about a board position, you just call the lookup to
get the list of precomputed masks.



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.