Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Position representation

Author: Sune Fischer

Date: 15:57:45 01/22/02

Go up one level in this thread


On January 22, 2002 at 18:45:40, Sean Mintz wrote:

Erhh yeah, I was expecting something like that;)

Seems 0x88 is really fast, except for detecting checks :(
Bitboards can really do the checks quickly, but then extracting the moves with
FirstBit(bb) is relative slow.
I wish I knew what to implement....

-S.


>Test checking is a ripoff of the move generator. I'm working on a program with a
>friend from FICS and making it so it passes positions around as opposed to
>having a global board. This is slower but a lot nicer to work with. This isn't
>exactly pointless rambling, it's just that the function was almost free before
>this --- so it can make life pretty easy.
>
>The 'piece_array_*[*]' are just arrays of offsets for movement.
>
>Here are the functions:
>
>int is_checked(Position * board, int side) {
>        if (side == WHITE) {
>                return is_attacked(board, board->wk_loc, BLACK);
>        } else if (side == BLACK) {
>                return is_attacked(board, board->bk_loc, WHITE);
>        }
>
>        return 1;
>}
>
>int is_attacked(Position * board, int sq, int side) {
>        int i,
>            j;
>
>        for (i=0; i<4; i++) {
>                j = sq;
>
>                while (!(j & 0x88)) {
>                        j += piece_array_rook[i];
>
>                        if (board->color[j] == EMPTY) {
>                                continue;
>                        } else if (board->color[j] != side) {
>                                break;
>                        } else if ((board->piece[j] == QUEEN) ||
>(board->piece[j] == ROOK)) {
>                                return 1;
>                        } else {
>                                break;
>                        }
>                }
>
>                j = sq;
>
>                while (!(j & 0x88)) {
>                        j += piece_array_bishop[i];
>
>                        if (board->color[j] == EMPTY) {
>                                continue;
>                        } else if (board->color[j] != side) {
>                                break;
>                        } else if ((board->piece[j] == QUEEN) ||
>(board->piece[j] == BISHOP)) {
>                                return 1;
>                        } else {
>                                break;
>                        }
>                }
>        }
>
>        for (i=0; i<8; i++) {
>                j = sq + piece_array_knight[i];
>
>                if ((board->color[j] == side) && (board->piece[j] == KNIGHT)) {
>                        return 1;
>                }
>
>                j = sq + piece_array_king[i];
>
>                if ((board->color[j] == side) && (board->piece[j] == KING)) {
>                        return 1;
>                }
>        }
>
>        if (side == WHITE) {
>                if ((board->color[sq + 15] == WHITE) && (board->piece[sq + 15]
>== PAWN)) {
>                        return 1;
>                }
>                if ((board->color[sq + 17] == WHITE) && (board->piece[sq + 17]
>== PAWN)) {
>                        return 1;
>                }
>        } else if (side == BLACK) {
>                if ((board->color[sq - 15] == BLACK) && (board->piece[sq - 15]
>== PAWN)) {
>                        return 1;
>                }
>                if ((board->color[sq - 17] == BLACK) && (board->piece[sq - 17]
>== PAWN)) {
>                        return 1;
>                }
>        }
>
>        return 0;
>}



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.