Use uint64 for BitBoard mask arrays

This commit is contained in:
Rico Tzschichholz 2022-12-08 16:10:50 +01:00
parent e62a0d8a48
commit 0b383a2ddc
2 changed files with 11 additions and 11 deletions

View file

@ -12,7 +12,7 @@
namespace BitBoard
{
/* Bitboard for each location */
public const int64 set_location_masks[] =
public const uint64 set_location_masks[] =
{
0x0000000000000001, 0x0000000000000002, 0x0000000000000004, 0x0000000000000008,
0x0000000000000010, 0x0000000000000020, 0x0000000000000040, 0x0000000000000080,
@ -33,7 +33,7 @@ namespace BitBoard
};
/* Mask to clear the given location */
public const int64 clear_location_masks[] =
public const uint64 clear_location_masks[] =
{
0xfffffffffffffffe, 0xfffffffffffffffd, 0xfffffffffffffffb, 0xfffffffffffffff7,
0xffffffffffffffef, 0xffffffffffffffdf, 0xffffffffffffffbf, 0xffffffffffffff7f,
@ -54,7 +54,7 @@ namespace BitBoard
};
/* Locations moved over for each move */
public const int64 over_masks[] =
public const uint64 over_masks[] =
{
0x0000000000000000, 0x0000000000000000, 0x0000000000000002, 0x0000000000000006,
0x000000000000000e, 0x000000000000001e, 0x000000000000003e, 0x000000000000007e,
@ -1083,7 +1083,7 @@ namespace BitBoard
};
/* Allowed moves for each piece */
public const int64 move_masks[] =
public const uint64 move_masks[] =
{
/* White Pawn */
0x0000000000000300, 0x0000000000000700, 0x0000000000000e00, 0x0000000000001c00,
@ -1291,7 +1291,7 @@ namespace BitBoard
0x6c38000000000000, 0x5070000000000000, 0xa0e0000000000000, 0x40c0000000000000
};
public string to_string (int64 mask)
public string to_string (uint64 mask)
{
var string = "+---+---+---+---+---+---+---+---+\n";
int rowCount = 0;

View file

@ -36,7 +36,7 @@ public class ChessState : Object
public ChessMove? last_move = null;
/* Bitmap of all the pieces */
private int64 piece_masks[2];
private uint64 piece_masks[2];
private ChessState.empty ()
{
@ -78,7 +78,7 @@ public class ChessState : Object
int index = get_index (rank, file);
ChessPiece piece = new ChessPiece (players[color], type);
board[index] = piece;
int64 mask = BitBoard.set_location_masks[index];
uint64 mask = BitBoard.set_location_masks[index];
piece_masks[color] |= mask;
file++;
}
@ -296,13 +296,13 @@ public class ChessState : Object
return false;
/* Check valid move */
int64 end_mask = BitBoard.set_location_masks[end];
int64 move_mask = BitBoard.move_masks[color * 64*6 + piece.type * 64 + start];
uint64 end_mask = BitBoard.set_location_masks[end];
uint64 move_mask = BitBoard.move_masks[color * 64*6 + piece.type * 64 + start];
if ((end_mask & move_mask) == 0)
return false;
/* Check no pieces in the way */
int64 over_mask = BitBoard.over_masks[start * 64 + end];
uint64 over_mask = BitBoard.over_masks[start * 64 + end];
if ((over_mask & (piece_masks[Color.WHITE] | piece_masks[Color.BLACK])) != 0)
return false;
@ -374,7 +374,7 @@ public class ChessState : Object
return false;
/* Check rook can move */
int64 rook_over_mask = BitBoard.over_masks[rook_start * 64 + rook_end];
uint64 rook_over_mask = BitBoard.over_masks[rook_start * 64 + rook_end];
if ((rook_over_mask & (piece_masks[Color.WHITE] | piece_masks[Color.BLACK])) != 0)
return false;