Skip to content

Commit

Permalink
chore: some semblence of a movegen
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Sep 14, 2024
1 parent c08c120 commit 6af74c7
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 7 deletions.
12 changes: 12 additions & 0 deletions games/src/ataxx/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ impl PositionType for Position {
self.bitboards[piece as usize]
}

fn side_to_move(&self) -> interface::Color<Self> {
self.side_to_move
}

fn half_move_clock(&self) -> usize {
self.half_move_clock as usize
}

fn ply_count(&self) -> usize {
self.ply_count as usize
}

fn hash(&self) -> Hash {
self.checksum
}
Expand Down
22 changes: 20 additions & 2 deletions games/src/chess/bitboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use crate::interface::{bitboard_type, BitBoardType, RepresentableType};

use super::Square;
use super::{Direction, Square};

bitboard_type! {
/// A set of Squares implemented as a bitset where the `1 << sq.into()` bit
Expand All @@ -28,14 +28,27 @@ bitboard_type! {

// BitBoards containing the squares of the first file and the first rank.
FirstFile = Self(0x0101010101010101);
FirstRank = Self(0xff00000000000000);
FirstRank = Self(0x00000000000000ff);
}
}

impl BitBoard {
pub fn new(raw: u64) -> BitBoard {
BitBoard(raw)
}

pub fn shift(&self, dir: Direction) -> BitBoard {
match dir {
Direction::North => self.north(),
Direction::South => self.south(),
Direction::East => self.east(),
Direction::West => self.west(),
Direction::NorthEast => self.north().east(),
Direction::NorthWest => self.north().west(),
Direction::SouthEast => self.south().east(),
Direction::SouthWest => self.south().west(),
}
}
}

impl BitBoard {
Expand Down Expand Up @@ -87,6 +100,11 @@ impl BitBoard {
BitBoard(BitBoard::BETWEEN[sq_1 as usize][sq_2 as usize])
}

pub fn between2(sq_1: Square, sq_2: Square) -> BitBoard {
BitBoard(BitBoard::BETWEEN[sq_1 as usize][sq_2 as usize])
| BitBoard::from(sq_2)
}

#[rustfmt::skip]
const BETWEEN: [[u64; Square::N]; Square::N] = [
[ 0x0101010101010100, 0x0000000000000000, 0x0000000000000002, 0x0000000000000006, 0x000000000000000e, 0x000000000000001e, 0x000000000000003e, 0x000000000000007e, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000100, 0x0000000000000000, 0x0000000000000200, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000010100, 0x0000000000000000, 0x0000000000000000, 0x0000000000040200, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000001010100, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000008040200, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000101010100, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000001008040200, 0x0000000000000000, 0x0000000000000000, 0x0000010101010100, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000201008040200, 0x0000000000000000, 0x0001010101010100, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0040201008040200 ],
Expand Down
2 changes: 2 additions & 0 deletions games/src/chess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub mod castling;
pub mod moves;
pub mod zobrist;

mod movegen;

// Non-namespaced modules.
mod bitboard;
mod color;
Expand Down
Loading

0 comments on commit 6af74c7

Please sign in to comment.