Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: quick bitboard question

Author: Harald Lüßen

Date: 02:58:03 08/27/05

Go up one level in this thread


On August 26, Robert Hyatt wrote:

>I have four choices for which square bit 0 represents (four logical choices,
>anyway, I guess one could number bits randomly should they choose).
>
>A1 = 0
>H1 = 0
>A8 = 0
>H8 = 0
>
>For those of you using bitboards, which did you use?

Elephant (below 2000 ELO and slow) uses bitboards with
A8=63, H8=56
A1= 7, H1= 0

>Since it doesn't matter to me at all, since I am having to
>rewrite a bunch of stuff to make this work, I
>thought I would try to match the most common layout which
>will make the programs more compatible if we share any ideas.
>
>I am leaning toward H1 = 0, H2 = 8, ..., H8 = 56 and A8 = 63,
>but I've not made any decision yet...  The reason for this is
>that it is easier to visualize if you think of the chess board
>as being composed of the 1 rank and the rightmost 8 bits of
>the bitboard, the 2nd rank is the next 8 bits, etc.

This was my reason, too. Look at the hex-code, translate it to
binary and see the board is easy for an old fashioned programmer. :-)

Feel free to use these tables:

/*
    directions and shifts
    +-----+-----+-----+
    |<<= 9|<<= 8|<<= 7|
    +-----+-----+-----+
    |<<= 1|     |>>= 1|
    +-----+-----+-----+
    |>>= 7|>>= 8|>>= 9|
    +-----+-----+-----+

    normal board square numbers
    63 62 61 60 59 58 57 56
    55 54 53 52 51 50 49 48
    47 46 45 44 43 42 41 40
    39 38 37 36 35 35 33 32
    31 30 29 28 27 26 25 24
    23 22 21 20 19 18 17 16
    15 14 13 12 11 10 09 08
    07 06 05 04 03 02 01 00

    normal board
    A8 B8 C8 D8 E8 F8 G8 H8
    A7 B7 C7 D7 E7 F7 G7 H7
    A6 B6 C6 D6 E6 F6 G6 H6
    A5 B5 C5 D5 E5 F5 G5 H5
    A4 B4 C4 D4 E4 F4 G4 H4
    A3 B3 C3 D3 E3 F3 G3 H3
    A2 B2 C2 D2 E2 F2 G2 H2
    A1 B1 C1 D1 E1 F1 G1 H1

    squares on the board rotated left 90 degrees
    H8 H7 H6 H5 H4 H3 H2 H1   |   |   |
    G8 G7 G6 G5 G4 G3 G2 G1   3.  2.  1.
    F8 F7 F6 F5 F4 F3 F2 F1   |   |   |
    E8 E7 E6 E5 E4 E3 E2 E1   v   v   v
    D8 D7 D6 D5 D4 D3 D2 D1
    C8 C7 C6 C5 C4 C3 C2 C1
    B8 B7 B6 B5 B4 B3 B2 B1
    A8 A7 A6 A5 A4 A3 A2 A1

    squares on the board rotated left 45 degrees
    H8 G8 H7 F8 G7 H6 E8 F7   \   \
    G6 H5 D8 E7 F6 G5 H4 C8     \   1.
    D7 E6 F5 G4 H3 B8 C7 D6   \  2.  \
    E5 F4 G3 H2 A8 B7 C6 D5    3.  \  v
    E4 F3 G2 H1 A7 B6 C5 D4      \   \
    E3 F2 G1 A6 B5 C4 D3 E2       v   v
    F1 A5 B4 C3 D2 E1 A4 B3
    C2 D1 A3 B2 C1 A2 B1 A1

    squares on the board rotated right 45 degrees
    A8 A7 B8 A6 B7 C8 A5 B6        >
    C7 D8 A4 B5 C6 D7 E8 A3      /   >
    B4 C5 D6 E7 F8 A2 B3 C4    1.  /   >
    D5 E6 F7 G8 A1 B2 C3 D4   /  2.  /
    E5 F6 G7 H8 B1 C2 D3 E4     /  3.
    F5 G6 H7 C1 D2 E3 F4 G5   /   /
    H6 D1 E2 F3 G4 H5 E1 F2
    G3 H4 F1 G2 H3 G1 H2 H1
*/

/**
Some basic calculations
*/
#define ROW( sq )           ( (sq) >> 3 )
#define BLACKS_ROW( sq )    ( 7 - ((sq) >> 3) )
#define LINE( sq )          ( (sq) & 7 )
#define SQUARE( row, line ) ( ((row) << 3) | (line) )

There are more related tables in my source. You can get it, if you ask.
(Hehe, Bob will find my errors, and I can understand Crafty more easily ;-)

Harald



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.