|
@@ -1,6 +1,7 @@
|
|
use bitboard::*;
|
|
use bitboard::*;
|
|
use movegen::*;
|
|
use movegen::*;
|
|
|
|
|
|
|
|
+#[derive(Clone)]
|
|
pub struct Game
|
|
pub struct Game
|
|
{
|
|
{
|
|
pub pieces: [Bitboard; 12],
|
|
pub pieces: [Bitboard; 12],
|
|
@@ -53,7 +54,7 @@ impl Game {
|
|
return None;
|
|
return None;
|
|
}
|
|
}
|
|
|
|
|
|
- let bit_to_set = single_bit_board(col_index, row_index);
|
|
|
|
|
|
+ let bit_to_set = from_indices(col_index, row_index);
|
|
match c {
|
|
match c {
|
|
'p' => { *game.pawns_mut(BLACK) |= bit_to_set },
|
|
'p' => { *game.pawns_mut(BLACK) |= bit_to_set },
|
|
'n' => { *game.knights_mut(BLACK) |= bit_to_set },
|
|
'n' => { *game.knights_mut(BLACK) |= bit_to_set },
|
|
@@ -182,6 +183,27 @@ impl Game {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ pub fn get_piece(&self, piece_type: PieceType, side: Side) -> Bitboard {
|
|
|
|
+ match side {
|
|
|
|
+ WHITE => self.pieces[piece_type as usize],
|
|
|
|
+ BLACK => self.pieces[piece_type as usize + 6],
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn set_piece(&mut self, piece_type: PieceType, side: Side, bitboard: Bitboard) {
|
|
|
|
+ match side {
|
|
|
|
+ WHITE => self.pieces[piece_type as usize] = bitboard,
|
|
|
|
+ BLACK => self.pieces[piece_type as usize + 6] = bitboard,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn get_piece_mut(&mut self, piece_type: PieceType, side: Side) -> &mut Bitboard {
|
|
|
|
+ match side {
|
|
|
|
+ WHITE => &mut self.pieces[piece_type as usize],
|
|
|
|
+ BLACK => &mut self.pieces[piece_type as usize + 6],
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
pub fn get_all_side(&self, side: Side) -> Bitboard {
|
|
pub fn get_all_side(&self, side: Side) -> Bitboard {
|
|
match side {
|
|
match side {
|
|
WHITE => self.pieces[0] | self.pieces[1] | self.pieces[2] | self.pieces[3] |
|
|
WHITE => self.pieces[0] | self.pieces[1] | self.pieces[2] | self.pieces[3] |
|
|
@@ -197,6 +219,8 @@ impl Game {
|
|
if self.pieces[i] & square_mask != 0 {
|
|
if self.pieces[i] & square_mask != 0 {
|
|
return (i as PieceType, WHITE);
|
|
return (i as PieceType, WHITE);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ for i in 0..6 {
|
|
if self.pieces[i + 6] & square_mask != 0 {
|
|
if self.pieces[i + 6] & square_mask != 0 {
|
|
return (i as PieceType, BLACK);
|
|
return (i as PieceType, BLACK);
|
|
}
|
|
}
|
|
@@ -205,6 +229,15 @@ impl Game {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @brief masks all bitboards.
|
|
|
|
+ */
|
|
|
|
+ pub fn apply_mask(&mut self, mask: Bitboard) {
|
|
|
|
+ for board in &mut self.pieces {
|
|
|
|
+ *board &= mask;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* @brief creates a unicode string containing the board
|
|
* @brief creates a unicode string containing the board
|
|
*
|
|
*
|
|
* Example:
|
|
* Example:
|
|
@@ -266,10 +299,10 @@ impl Game {
|
|
if pt == NO_PIECE {
|
|
if pt == NO_PIECE {
|
|
line.push(' ');
|
|
line.push(' ');
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- let fig_index = pt as usize + if side == BLACK { 6 } else { 0 };
|
|
|
|
- line.push(figures[fig_index]);
|
|
|
|
- }
|
|
|
|
|
|
+ else {
|
|
|
|
+ let fig_index = pt as usize + if side == BLACK { 6 } else { 0 };
|
|
|
|
+ line.push(figures[fig_index]);
|
|
|
|
+ }
|
|
line.push(' '); line.push(chars[1]); line.push(' ');
|
|
line.push(' '); line.push(chars[1]); line.push(' ');
|
|
}
|
|
}
|
|
return line;
|
|
return line;
|