Aha. stolen from Cray to appease the crypto-guys.Gerd Isenberg wrote:The question whether a1, h1, a8 or h8 is least significant square is independent on how you count or scan bits from 0 to 63 in a 64-bit word. Since K10 and future intel (SSE5 something) will have leading zero count (even faster direct path instruction on K10), you may switch back again to save the xor 63bob wrote:that question I can answer for me...
A1 = bit 0 (LSB), B1 = bit 1, ..., H1 = bit 7, ..., H8 = bit 63.
I chose this to make the bits line up with the BSF/BSR way of counting where LSB = 0, MSB = 63. For the rest, the property File(sq) = 0 for A1-A8 and File(sq) is defined simply as sq >> 3. Ditto for rank where Rank(A1) = 0, Rank(A8) = 7, where Rank(sq) is defined is sq & 7.
Any mapping can be made to work however as mine used to be backward because of the way the Cray does big scanning in the opposite way of Intel.
lzc even leaves deterministic 64 for empty sets.
BitBoard representations of the board
Moderators: hgm, Rebel, chrisw
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: BitBoard representations of the board
-
- Posts: 892
- Joined: Sun Nov 19, 2006 9:16 pm
- Location: Russia
Re: BitBoard representations of the board
Wrong. Your RANK_1 constant maps to A8...H8 rank.Chan Rasjid wrote:My bitboard basics are these. If anyone sees anything silly, please let me know.Code: Select all
#define RANK_1 (u64)0xff //bitboard.h ... enum { 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 }; #define Rank1 (RANK_1) #define Rank2 (RANK_1 << 8) #define Rank3 (RANK_1 << 16) #define Rank4 (RANK_1 << 24) #define Rank5 (RANK_1 << 32) #define Rank6 (RANK_1 << 40) #define Rank7 (RANK_1 << 48) #define Rank8 (RANK_1 << 56)
-
- Posts: 588
- Joined: Thu Mar 09, 2006 4:47 pm
- Location: Singapore
Re: BitBoard representations of the board
Should be correct. I use RANK1, RANK2 ... RANK8 and not 0 - 7.Chan Rasjid wrote:
My bitboard basics are these. If anyone sees anything silly, please let me know.
Code:
#define RANK_1 (u64)0xff
//bitboard.h ...
enum {
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
};
#define Rank1 (RANK_1)
#define Rank2 (RANK_1 << 8)
#define Rank3 (RANK_1 << 16)
#define Rank4 (RANK_1 << 24)
#define Rank5 (RANK_1 << 32)
#define Rank6 (RANK_1 << 40)
#define Rank7 (RANK_1 << 48)
#define Rank8 (RANK_1 << 56)
Wrong. Your RANK_1 constant maps to A8...H8 rank.
#define RANK(sq) ((sq) >> 3)
#define FILE(sq) ((sq) & 3)
Rasjid
-
- Posts: 892
- Joined: Sun Nov 19, 2006 9:16 pm
- Location: Russia
Re: BitBoard representations of the board
There are no RANK(sq) or RANK1 definitions in the posted above code. Your macros RANK_1, Rank1 is a source of bug.
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: BitBoard representations of the board
Yes, usually 1.Rank covers squares from A1 to H1 but not A8 to H8.Aleks Peshkov wrote:There are no RANK(sq) or RANK1 definitions in the posted above code. Your macros RANK_1, Rank1 is a source of bug.
For internal representation it don't cares - but it would confuse me as well.
-
- Posts: 588
- Joined: Thu Mar 09, 2006 4:47 pm
- Location: Singapore
Re: BitBoard representations of the board
Code: Select all
Quote:
Chan Rasjid wrote:
My bitboard basics are these. If anyone sees anything silly, please let me know.
Code:
#define RANK_1 (u64)0xff
//bitboard.h ...
enum {
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
};
#define Rank1 (RANK_1)
#define Rank2 (RANK_1 << 8)
#define Rank3 (RANK_1 << 16)
#define Rank4 (RANK_1 << 24)
#define Rank5 (RANK_1 << 32)
#define Rank6 (RANK_1 << 40)
#define Rank7 (RANK_1 << 48)
#define Rank8 (RANK_1 << 56)
Wrong. Your RANK_1 constant maps to A8...H8 rank.
Should be correct. I use RANK1, RANK2 ... RANK8 and not 0 - 7.
#define RANK(sq) ((sq) >> 3)
#define FILE(sq) ((sq) & 3)
Everything in C is a likely source of bugs to me as I simply don't understand C concepts well. Macros can be source of bugs but it seems using #define for constants should be very safe - they just are transformed to C constant expressions on preprocessing. But I may miss something. I needThere are no RANK(sq) or RANK1 definitions in the posted above code. Your macros RANK_1, Rank1 is a source of bug.
#define RANK_1 (u64)0xff
because MSVC++ does not accept the suffix ULL which is needed by GCC.
There is a way to introduce bugs. We use conditional compilation to switch evaluation factors on/off :-
in ev.h :-
#define ENABLE_KING_SAFETY 1
in ev.c:-
#if ENABLE_KING_SAFETY
etc...
#endif
and if we have plenty of these in evaluation codes which are changed often, we are in trouble. So I now do this with cut_and_paste:-
#if defined(ENABLE_KING_SAFETY)
#if ENABLE_KING_SAFETY
etc...
#endif
#else
printf("Warning...")
#endif
Rasjid
-
- Posts: 588
- Joined: Thu Mar 09, 2006 4:47 pm
- Location: Singapore
Re: BitBoard representations of the board
Hello,
#define RANK_1 0xffULL
and it is used to define all ranks with
#define Rank1 (RANK_1)
#define Rank2 (RANK_1 << 8)
#define Rank3 (RANK_1 << 16)
RANK_2, RANK_3, ... don't exist.
My program plays a complete game of chess!
Rasjid
I don't understand. I haveYes, usually 1.Rank covers squares from A1 to H1 but not A8 to H8.
For internal representation it don't cares - but it would confuse me as well.
#define RANK_1 0xffULL
and it is used to define all ranks with
#define Rank1 (RANK_1)
#define Rank2 (RANK_1 << 8)
#define Rank3 (RANK_1 << 16)
RANK_2, RANK_3, ... don't exist.
My program plays a complete game of chess!
Rasjid
-
- Posts: 10309
- Joined: Thu Mar 09, 2006 12:37 am
- Location: Tel-Aviv Israel
Re: BitBoard representations of the board
I do not understand what you do not understand.Chan Rasjid wrote:Hello,
I don't understand. I haveYes, usually 1.Rank covers squares from A1 to H1 but not A8 to H8.
For internal representation it don't cares - but it would confuse me as well.
#define RANK_1 0xffULL
and it is used to define all ranks with
#define Rank1 (RANK_1)
#define Rank2 (RANK_1 << 8)
#define Rank3 (RANK_1 << 16)
RANK_2, RANK_3, ... don't exist.
My program plays a complete game of chess!
Rasjid
The meaning of Rank1 in your program is squares A8-H8
Of course it is possible to write in that way but people usually think about Rank1 in chess as the squares A1-H1.
If you already started with A8-H8 as Rank1 and you have a working program then you probably got the habit of thinking of Rank1 as A8-H8 and I do not suggest changing it because it may be more confusing for you.
Uri
-
- Posts: 588
- Joined: Thu Mar 09, 2006 4:47 pm
- Location: Singapore
Re: BitBoard representations of the board
Ok, I now understand.I do not understand what you do not understand.
The meaning of Rank1 in your program is squares A8-H8
Of course it is possible to write in that way but people usually think about Rank1 in chess as the squares A1-H1.
If you already started with A8-H8 as Rank1 and you have a working program then you probably got the habit of thinking of Rank1 as A8-H8 and I do not suggest changing it because it may be more confusing for you.
Uri
! That's the problem of shorthand script. Calling getline() has :-Yes, usually 1.Rank covers squares from A1 to H1 but not A8 to H8.
"Yes, usually 1."
"Rank covers squares from A1 to H1 but not A8 to H8."
Chess programming has 1.rank when RANK(sq) == 0
or 0xffULL. I also have ROW(sq) ranks from the starting rank for a side.
Rasjid