Compare commits
40 Commits
v117
...
Engine/mov
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f39c113ef9 | ||
|
|
f417a7e47c | ||
|
|
547b0e51cb | ||
|
|
5340744abe | ||
|
|
f64ebfa47f | ||
|
|
4e7ac2a195 | ||
|
|
dc176c103b | ||
|
|
85a7fa37ef | ||
|
|
a60658763d | ||
|
|
b76a009e4e | ||
|
|
db333a693f | ||
|
|
fd0d26486b | ||
|
|
e1f4ae717e | ||
|
|
7b9c1edbab | ||
|
|
05294a7736 | ||
|
|
d8da808580 | ||
|
|
c420d8b3dd | ||
|
|
57af3aaae3 | ||
|
|
887b9abed8 | ||
|
|
3ebfc61ac7 | ||
|
|
a8970053f9 | ||
|
|
fa0a93172d | ||
|
|
bb74a486d8 | ||
|
|
d1932762f9 | ||
|
|
9181b6c4ca | ||
|
|
b703d8b9a1 | ||
|
|
acaa7d078a | ||
|
|
30448b5f3d | ||
|
|
ff38c5c475 | ||
|
|
42daeb9971 | ||
|
|
c8b6bc35d5 | ||
|
|
5f2a4e1721 | ||
|
|
5c42b6e52a | ||
|
|
f7364e7939 | ||
|
|
b4a1f0820f | ||
|
|
6d9d5c49ae | ||
|
|
1ca44b472b | ||
|
|
79aabeac8c | ||
|
|
5eb85dab89 | ||
|
|
291b7e71a2 |
@@ -3,5 +3,7 @@ mod utils;
|
|||||||
mod legality;
|
mod legality;
|
||||||
mod checkinfo;
|
mod checkinfo;
|
||||||
mod attacks;
|
mod attacks;
|
||||||
|
mod bitmove;
|
||||||
|
mod movebuffer;
|
||||||
|
|
||||||
pub mod board;
|
pub mod board;
|
||||||
77
engine/src/bitboard/bitmove.rs
Normal file
77
engine/src/bitboard/bitmove.rs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
use super::utils::*;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub struct BitMove {
|
||||||
|
|
||||||
|
move_type: BitMoveType,
|
||||||
|
from_square: u8,
|
||||||
|
to_square: u8,
|
||||||
|
promotion_piece: Option<u8>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitMove {
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn quiet(from: u8, to: u8, promotion_piece: Option<u8>) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: BitMoveType::Quiet,
|
||||||
|
from_square: from,
|
||||||
|
to_square: to,
|
||||||
|
promotion_piece: promotion_piece
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn capture(from: u8, to: u8, promotion_piece: Option<u8>) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: BitMoveType::Capture,
|
||||||
|
from_square: from,
|
||||||
|
to_square: to,
|
||||||
|
promotion_piece: promotion_piece
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn castle(from: u8, to: u8) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: BitMoveType::Castle,
|
||||||
|
from_square: from,
|
||||||
|
to_square: to,
|
||||||
|
promotion_piece: None
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn move_type(&self) -> BitMoveType {
|
||||||
|
return self.move_type;
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_square(&self) -> u8 {
|
||||||
|
return self.from_square;
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn to_square(&self) -> u8 {
|
||||||
|
return self.to_square;
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn promotion_piece(&self) -> Option<u8> {
|
||||||
|
return self.promotion_piece;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uci_notation(&self) -> String {
|
||||||
|
let mut notation = notation_from_square_number(self.from_square());
|
||||||
|
notation.push_str(¬ation_from_square_number(self.to_square()));
|
||||||
|
|
||||||
|
if let Some(promotion_piece) = self.promotion_piece {
|
||||||
|
notation.push(get_character_by_piece_id(promotion_piece).to_ascii_lowercase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return notation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub enum BitMoveType {
|
||||||
|
Quiet,
|
||||||
|
Capture,
|
||||||
|
Castle,
|
||||||
|
EnPassant
|
||||||
|
}
|
||||||
44
engine/src/bitboard/movebuffer.rs
Normal file
44
engine/src/bitboard/movebuffer.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use super::bitmove::BitMove;
|
||||||
|
|
||||||
|
pub struct MoveBuffer {
|
||||||
|
|
||||||
|
buffer: [BitMove; 256],
|
||||||
|
count: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MoveBuffer {
|
||||||
|
|
||||||
|
pub fn new() -> Self {
|
||||||
|
return Self {
|
||||||
|
buffer: [BitMove::quiet(0, 0, None); 256],
|
||||||
|
count: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn add(&mut self, bitmove: BitMove) {
|
||||||
|
self.buffer[self.count] = bitmove;
|
||||||
|
self.count += 1;
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn append(&mut self, other: &MoveBuffer) {
|
||||||
|
self.buffer[self.count..self.count + other.count()].copy_from_slice(other.contents());
|
||||||
|
self.count += other.count();
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn clear(&mut self) {
|
||||||
|
self.count = 0;
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn count(&self) -> usize{
|
||||||
|
return self.count;
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn get(&self, idx: usize) -> &BitMove {
|
||||||
|
return &self.buffer[idx];
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn contents(&self) -> &[BitMove] {
|
||||||
|
return &self.buffer[0..self.count];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,11 @@ pub fn try_get_square_number_from_notation(notation: &str) -> Result<u8, ()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PIECE_CHARACTERS: [char; 12] = ['P', 'N', 'B', 'R', 'Q', 'K', 'p', 'n', 'b', 'r', 'q', 'k'];
|
||||||
|
pub fn get_character_by_piece_id(id: u8) -> char {
|
||||||
|
return PIECE_CHARACTERS[id as usize];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// <----- TESTS ----->
|
// <----- TESTS ----->
|
||||||
|
|
||||||
|
|||||||
32
engine/src/boardsquare.rs
Normal file
32
engine/src/boardsquare.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
pub struct BoardSquare {
|
||||||
|
pub x: usize,
|
||||||
|
pub y: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BoardSquare {
|
||||||
|
|
||||||
|
pub fn new() -> Self {
|
||||||
|
return Self{
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_coord(x: usize, y: usize) -> Self {
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
if x > 7 {
|
||||||
|
println!("Warning: x coordinate of square is bigger than 7, it might not be on the board!");
|
||||||
|
}
|
||||||
|
if y > 7 {
|
||||||
|
println!("Warning: y coordinate of square is bigger than 7, it might not be on the board!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Self {
|
||||||
|
x: x,
|
||||||
|
y: y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
71
engine/src/chessmove.rs
Normal file
71
engine/src/chessmove.rs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
use crate::piecetype;
|
||||||
|
|
||||||
|
use super::boardsquare::BoardSquare;
|
||||||
|
use super::piecetype::PieceType;
|
||||||
|
use super::movetype::MoveType;
|
||||||
|
|
||||||
|
|
||||||
|
pub struct ChessMove {
|
||||||
|
pub move_type: MoveType,
|
||||||
|
pub piece_type: PieceType,
|
||||||
|
pub from_square: BoardSquare,
|
||||||
|
pub to_square: BoardSquare,
|
||||||
|
pub rook_from: BoardSquare,
|
||||||
|
pub rook_to: BoardSquare,
|
||||||
|
pub promotion_piece: Option<PieceType>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChessMove {
|
||||||
|
|
||||||
|
pub fn quiet(
|
||||||
|
piece_type: PieceType,
|
||||||
|
from_square: BoardSquare,
|
||||||
|
to_square: BoardSquare,
|
||||||
|
promotion_piece: Option<PieceType>
|
||||||
|
) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: MoveType::Quiet,
|
||||||
|
piece_type: piece_type,
|
||||||
|
from_square: from_square,
|
||||||
|
to_square: to_square,
|
||||||
|
rook_from: BoardSquare::new(),
|
||||||
|
rook_to: BoardSquare::new(),
|
||||||
|
promotion_piece: promotion_piece
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn capture(
|
||||||
|
piece_type: PieceType,
|
||||||
|
from_square: BoardSquare,
|
||||||
|
to_square: BoardSquare,
|
||||||
|
promotion_piece: Option<PieceType>
|
||||||
|
) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: MoveType::Capture,
|
||||||
|
piece_type: piece_type,
|
||||||
|
from_square: from_square,
|
||||||
|
to_square: to_square,
|
||||||
|
rook_from: BoardSquare::new(),
|
||||||
|
rook_to: BoardSquare::new(),
|
||||||
|
promotion_piece: promotion_piece
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn castle(
|
||||||
|
piece_type: PieceType,
|
||||||
|
from_square: BoardSquare,
|
||||||
|
to_square: BoardSquare,
|
||||||
|
rook_from: BoardSquare,
|
||||||
|
rook_to: BoardSquare
|
||||||
|
) -> Self {
|
||||||
|
return Self {
|
||||||
|
move_type: MoveType::Quiet,
|
||||||
|
piece_type: piece_type,
|
||||||
|
from_square: from_square,
|
||||||
|
to_square: to_square,
|
||||||
|
rook_from: rook_from,
|
||||||
|
rook_to: rook_to,
|
||||||
|
promotion_piece: None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
engine/src/gameend.rs
Normal file
6
engine/src/gameend.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
pub enum GameEnd {
|
||||||
|
WhiteWon(String),
|
||||||
|
BlackWon(String),
|
||||||
|
Draw(String)
|
||||||
|
}
|
||||||
24
engine/src/lib.rs
Normal file
24
engine/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
mod bitboard;
|
||||||
|
pub mod chessmove;
|
||||||
|
pub mod piecetype;
|
||||||
|
pub mod boardsquare;
|
||||||
|
pub mod movetype;
|
||||||
|
pub mod gameend;
|
||||||
|
|
||||||
|
use chessmove::ChessMove;
|
||||||
|
use gameend::GameEnd;
|
||||||
|
|
||||||
|
pub fn get_available_moves(fen: &str) -> Vec<ChessMove> {
|
||||||
|
println!("get_available_moves answered");
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_game_over(fen: &str) -> Option<GameEnd> {
|
||||||
|
println!("is_game_over answered");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_board_after_move(fen: &str, chess_move: &ChessMove) -> String {
|
||||||
|
println!("get_board_after_move answered");
|
||||||
|
return String::from("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
|
}
|
||||||
7
engine/src/movetype.rs
Normal file
7
engine/src/movetype.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
pub enum MoveType {
|
||||||
|
Quiet,
|
||||||
|
Capture,
|
||||||
|
Castle,
|
||||||
|
EnPassant
|
||||||
|
}
|
||||||
15
engine/src/piecetype.rs
Normal file
15
engine/src/piecetype.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
pub enum PieceType {
|
||||||
|
WhitePawn,
|
||||||
|
WhiteKnight,
|
||||||
|
WhiteBishop,
|
||||||
|
WhiteRook,
|
||||||
|
WhiteQueen,
|
||||||
|
WhiteKing,
|
||||||
|
BlackPawn,
|
||||||
|
BlackKnight,
|
||||||
|
BlackBishop,
|
||||||
|
BlackRook,
|
||||||
|
BlackQueen,
|
||||||
|
BlackKing
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user