Computer Chess Club Archives


Search

Terms

Messages

Subject: Sorry, sloppy code...

Author: h.g.muller

Date: 23:42:31 02/22/06

Go up one level in this thread


The thing I posted yesterday was not entirey correct: although xor'íng with k
swaps the colors on pieces, it does not have the desired effect on empty
squares. So the correct solution to achieve the intended goal would be:

/* piece encodings in board array */
#define WHITE 0x10
#define BLACK 0x20
#define PIECE 0x08
#define EMPTY 0x40
#define GUARD 0x30

/* encodings in mask array */
#define FRIEND 0x10
#define FOE    0x20

/* side-to-move codes */
#define WTM 0x00
#define BTM 0x30

To tell which moves are forbidded for a given dirction d, mask[d] would set the
PIECE or EMPTY bit (on pawn moves as appropriate), and the FRIEND bit always.
The latter would prevent capture of own pieces or guards. The proper test for
ray termination would then be

if(board[y]&(side_to_move^mask[d]))break;

i.e. we would xor the mask, rather than the piece, with stm, to turn the FRIEND
bit into an actual color code.

In the example of the 'entirely' branchless move generator, there is no need
whatsoever to involve the side to move, since each ray knows to which piece it
belongs, and thus is also aware of the color of that piece. In mask[ray] one
simply sets the bits for the colors that you can't capture along this ray, i.e.
always your own color, and for straight pawn rays also that of the opponent. The
0x80 bit is available to flag non-sliding rays (that this can be selected per
ray is a nice feature for some fairy pieces!). To see if the ray should be
terminated by stepping to the next ray, one tests

if((mask[ray]|WHITE|BLACK)&board[y])

assuming that any board square has the NONSLIDING bit set. The PIECE bit is not
used in this case (because the board array contains piece numbers that run 0-15,
rather than piece types that ran from 0-7 in the first example).



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.