From 25a6a902d1f7375d7381a50413b3c8cdef9f632d Mon Sep 17 00:00:00 2001 From: fabolous005 Date: Tue, 16 Apr 2024 10:39:31 +0200 Subject: [PATCH] add outdated message --- README.md | 3 +++ src/lines.rs | 16 +++++++++++++++- src/main.rs | 15 ++++++++++++--- src/pieces/pawn.rs | 4 +++- src/position.rs | 6 +++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bc90e4c..f86d40b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # chesster + a simple and blazingly fast chess engine + +programm switched to [Saltfish](https://github.com/fabolous005/saltfish) diff --git a/src/lines.rs b/src/lines.rs index b8090b5..681b22c 100644 --- a/src/lines.rs +++ b/src/lines.rs @@ -6,6 +6,7 @@ use crate::position::{Position}; pub struct Line { move_: Move, value: i32, + abondened: bool, line: Option>> } @@ -21,6 +22,7 @@ impl Line { Line { move_, value: 0, + abondened: false, line: None } ] @@ -43,10 +45,22 @@ impl Line { for move_ in moves { let new_position: &mut Position = &mut position.clone(); new_position.make_move(&move_); - lines.push(Line { move_, value: 0, line: None }) + lines.push(Line { move_, value: 0, abondened: false, line: None }) } lines } + + pub fn get_line(position: &Position) -> Vec { + let mut lines = Vec::new(); + let moves = position.get_moves(); + for move_ in moves { + let new_position: &mut Position = &mut position.clone(); + new_position.make_move(&move_); + lines.push(Line { move_, value: 0, abondened: false, line: None }) + } + lines + } + } diff --git a/src/main.rs b/src/main.rs index 2401d20..d5de9fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,10 +55,19 @@ fn main() { println!("{:#?}", best_move); let result = thread::spawn(move || { + let mut position_before = None; + let mut new_position: Position; + let mut lines; loop{ - let position: Position = receiver_sub.recv().unwrap(); - let result: Vec = Line::get_lines(&position, 0); - sender_main.send(result).unwrap(); + new_position = receiver_sub.recv().unwrap(); + if position_before.is_some() && position_before != Some(new_position) { + new_position = position_before.unwrap(); + } + + // TODO: get latest unsolved position + lines = Line::get_line(&new_position); + sender_main.send(lines).unwrap(); + position_before = Some(position); } }); diff --git a/src/pieces/pawn.rs b/src/pieces/pawn.rs index dd23db5..058ec2d 100644 --- a/src/pieces/pawn.rs +++ b/src/pieces/pawn.rs @@ -17,6 +17,7 @@ impl PawnMoveOptionsBlack { moves.push(PawnMoveOptionsBlack::CaptureR(Change { x: 1, y: 1 })); moves.push(PawnMoveOptionsBlack::CaptureL(Change { x: -1, y: 1 })); moves.push(PawnMoveOptionsBlack::EnPassant(Change { x: 1, y: 1 })); + moves.push(PawnMoveOptionsBlack::EnPassant(Change { x: -1, y: 1 })); moves } } @@ -39,7 +40,8 @@ impl PawnMoveOptionsWhite { moves.push(PawnMoveOptionsWhite::CaptureR(Change { x: 1, y: -1 })); moves.push(PawnMoveOptionsWhite::CaptureL(Change { x: -1, y: -1 })); moves.push(PawnMoveOptionsWhite::EnPassant(Change { x: 1, y: -1 })); + moves.push(PawnMoveOptionsWhite::EnPassant(Change { x: -1, y: -1 })); moves } -} \ No newline at end of file +} diff --git a/src/position.rs b/src/position.rs index 4a2e1a1..9864977 100644 --- a/src/position.rs +++ b/src/position.rs @@ -8,19 +8,19 @@ use crate::moves::get_moves_black; -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum Color { White, Black, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Castling { king_side: bool, queen_side: bool } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Eq, PartialEq)] pub struct Position { pub rows: [[char; 8]; 8], pub to_move: Color,