theoretical end: Breakthrough
This commit is contained in:
1 parent
651c4713c2
commit
bda716da90
3 files changed
+77
-4
No files matched your search
@@ -12,6 +12,9 @@ pub struct Board<const N: usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Board<N> {
|
impl<const N: usize> Board<N> {
|
||||||
|
pub const fn from_layers(layers: [[u64; 2]; N]) -> Self {
|
||||||
|
Self { layers }
|
||||||
|
}
|
||||||
pub fn apply_patch(&mut self, patch: &MaskPatch) {
|
pub fn apply_patch(&mut self, patch: &MaskPatch) {
|
||||||
for layer in self.layers.iter_mut() {
|
for layer in self.layers.iter_mut() {
|
||||||
layer[0] &= !patch.clear_mask;
|
layer[0] &= !patch.clear_mask;
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ use super::*;
|
|||||||
pub const WHITE_WON_ZONE: u64 = 0xff << 56;
|
pub const WHITE_WON_ZONE: u64 = 0xff << 56;
|
||||||
pub const BLACK_WON_ZONE: u64 = 0xff;
|
pub const BLACK_WON_ZONE: u64 = 0xff;
|
||||||
|
|
||||||
|
pub const START_BOARD: Board<1> = Board::from_layers([
|
||||||
|
[0xffff << 48, 0xffff],
|
||||||
|
]);
|
||||||
|
|
||||||
struct Breakthrough{
|
struct Breakthrough{
|
||||||
board: Board<1>,
|
board: Board<1>,
|
||||||
side: Color,
|
side: Color,
|
||||||
@@ -11,14 +15,80 @@ struct Breakthrough{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Breakthrough {
|
impl Breakthrough {
|
||||||
fn generate_legal(&self) -> HashMap<Move, MaskPatch>{
|
pub fn new() -> Self {
|
||||||
todo!();
|
let mut p = Breakthrough{
|
||||||
HashMap::new()
|
board: START_BOARD,
|
||||||
|
side: Color::White,
|
||||||
|
legal_moves: None
|
||||||
|
};
|
||||||
|
p.refresh_legal_moves();
|
||||||
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh_legal_moves(&mut self) {
|
pub fn refresh_legal_moves(&mut self) {
|
||||||
self.legal_moves = Some(self.generate_legal());
|
self.legal_moves = Some(self.generate_legal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_legal(&self) -> HashMap<Move, MaskPatch>{
|
||||||
|
let mut legal: HashMap<Move, MaskPatch> = HashMap::new();
|
||||||
|
|
||||||
|
let white = self.board.get_mask(Color::White, 0);
|
||||||
|
let black = self.board.get_mask(Color::Black, 0);
|
||||||
|
|
||||||
|
let own = match self.side {
|
||||||
|
Color::White => white,
|
||||||
|
Color::Black => black,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut bits = own;
|
||||||
|
while bits != 0 {
|
||||||
|
let from = bits.trailing_zeros() as u8;
|
||||||
|
let from_bit = 1u64 << from;
|
||||||
|
bits &= bits - 1;
|
||||||
|
|
||||||
|
let mut t = self.mov_pattern(from_bit);
|
||||||
|
while t != 0 {
|
||||||
|
let to = t.trailing_zeros() as u8;
|
||||||
|
let to_bit = 1u64 << to;
|
||||||
|
t &= t - 1;
|
||||||
|
|
||||||
|
let mv = Move { from, to, p: Promotion::NoPromotion };
|
||||||
|
|
||||||
|
let mut patch = MaskPatch::new(from_bit | to_bit);
|
||||||
|
patch.push(self.side, 0, to_bit);
|
||||||
|
|
||||||
|
legal.insert(mv, patch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mov_pattern(&self, pos: u64) -> u64 {
|
||||||
|
let white = self.board.get_mask(Color::White, 0);
|
||||||
|
let black = self.board.get_mask(Color::Black, 0);
|
||||||
|
|
||||||
|
let (own, enemy, mvc, mvl, mvr) = match self.side {
|
||||||
|
Color::White => (
|
||||||
|
white, black,
|
||||||
|
(8i8, mov_mask(0)),
|
||||||
|
(7i8, mov_mask(-1)),
|
||||||
|
(9i8, mov_mask(1)),
|
||||||
|
),
|
||||||
|
Color::Black => (
|
||||||
|
black, white,
|
||||||
|
(-8i8, mov_mask(0)),
|
||||||
|
(-7i8, mov_mask(1)),
|
||||||
|
(-9i8, mov_mask(-1)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mmvc = trajectory(pos, mvc.1, own | enemy, 0, mvc.0, Some(1));
|
||||||
|
let mmvl = trajectory(pos, mvl.1, own, enemy, mvl.0, Some(1));
|
||||||
|
let mmvr = trajectory(pos, mvr.1, own, enemy, mvr.0, Some(1));
|
||||||
|
|
||||||
|
mmvc | mmvr | mmvl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChessEngine for Breakthrough {
|
impl ChessEngine for Breakthrough {
|
||||||
|
|||||||
+1
-1
@@ -28,5 +28,5 @@ fn main() {
|
|||||||
|
|
||||||
print!("\n");
|
print!("\n");
|
||||||
|
|
||||||
render_board(BoardColor::Solid('`'), vec![(0xffff, 'W'), (0xff << 56, 'B')]);
|
render_board(BoardColor::Solid('`'), vec![(0xffff, 'W'), (0xffff << 48, 'B')]);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user