Author: Gerd Isenberg
Date: 09:07:32 10/30/02
Go up one level in this thread
On October 30, 2002 at 04:49:20, Russell Reagan wrote:
>Without using a squares array (ex. int squares[64]), is there any way to find
>out what piece is on a square more efficiently using bitboards?
>
>I'm experimenting with using only bitboards and no square array at all, and I'm
>wondering if the instructions saved in not having to do the upkeep on the
>squares array is enough to make up for this slower routine.
>
>For empty squares and pawns (which accounts for most of the board) it seems like
>it would be pretty fast (unless branch misprediction kills it). If you've
>experimented with this before I'd like to know your results.
>
>int PieceOnSquare (int square) {
> bitboard m = mask[square];
> if (whitePieces & m) {
> if (whitePawns & m) return WHITE_PAWN;
> if (whiteKnights & m) return WHITE_KNIGHT;
> if (whiteBishops & m) return WHITE_BISHOP;
> if (whiteRooks & m) return WHITE_ROOK;
> if (whiteQueens & m) return WHITE_QUEENS;
> if (whiteKing & m) return WHITE_KING;
> }
> if (blackPieces & m) {
> if (blackPawns & m) return BLACK_PAWN;
> if (blackKnights & m) return BLACK_KNIGHT;
> if (blackBishops & m) return BLACK_BISHOP;
> if (blackRooks & m) return BLACK_ROOK;
> if (blackQueens & m) return BLACK_QUEENS;
> if (blackKing & m) return BLACK_KING;
> }
> return EMPTY;
>}
>
>Of course if you're using a square array, this can be as simple as...
>
>#define PieceOnSquare(n) (squares[n])
>
>...just like in Crafty.
>
>Russell
Hi Russell,
I don't use the squares[64] array anymore in IsiChess and have a similar
routine, to get the piece-code. But i pack information about the moving piece
and the possible captured piece inside a 32-bit move-struct.
Therefore during incremental update of the piece bitboards I fetch the
piece-codes from the _move_ rather than from the (bit)board representation.
The drawback is some more effort during move generation by traversing up to five
capture target sets instead of one for each set of pieces of one kind, with
MVV/LVA-ordering in my infinite-state move generator, which tries to avoid move
generation at all.
I don't use the piece-code directly, but i enum all piece combinations of moves,
captures, promotions and promote-captures, so i use six bits for "kind of move"
and some mapping functions to get the piece-codes:
// quite moves
1.single_pawn_move
2.double_pawn_move
3.knight_move
4.bishop_move
5.rook_move
6.queen_move
7.king_moves
8.0-0
9.0-0-0
// captures
10. ep-capture
11. pawn_takes_pawn
12. pawn_takes_knight
13. pawn_takes_bishop
14. pawn_takes_rook
15. pawn_takes_queen
16. knight_takes_pawn
..
20. knight_takes_queen
21. bishop_takes_pawn
..
25. bishop_takes_queen
26. rook_takes_pawn
..
30. rook_takes_queen
31. queen_takes_pawn
..
35. queen_takes_queen
36. king_takes_pawn
..
40. king_takes_queen
// promotions
41. pawn_2_queen_promotion
42. pawn_2_knight_promotion
43. pawn_2_rook_promotion
44. pawn_2_bishop_promotion
// capture promotions
45. pawn_2_queen_takes_knight
46. pawn_2_queen_takes_bishop
47. pawn_2_queen_takes_rook
48. pawn_2_queen_takes_queen
49. pawn_2_knight_takes_knight
50. pawn_2_knight_takes_bishop
51. pawn_2_knight_takes_rook
52. pawn_2_knight_takes_queen
53. pawn_2_rook_takes_knight
54. pawn_2_rook_takes_bishop
55. pawn_2_rook_takes_rook
56. pawn_2_rook_takes_queen
57. pawn_2_bishop_takes_knight
58. pawn_2_bishop_takes_bishop
59. pawn_2_bishop_takes_rook
60. pawn_2_bishop_takes_queen
Regards,
Gerd
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.