Engine/library functions #15

Merged
vargadavidlajos merged 20 commits from Engine/library-functions into master 2025-11-17 15:04:29 +01:00
6 changed files with 155 additions and 0 deletions

32
engine/src/boardsquare.rs Normal file
View 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
View 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
View File

@@ -0,0 +1,6 @@
pub enum GameEnd {
WhiteWon(String),
BlackWon(String),
Draw(String)
}

24
engine/src/lib.rs Normal file
View 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
View File

@@ -0,0 +1,7 @@
pub enum MoveType {
Quiet,
Capture,
Castle,
EnPassant
}

15
engine/src/piecetype.rs Normal file
View File

@@ -0,0 +1,15 @@
pub enum PieceType {
WhitePawn,
WhiteKnight,
WhiteBishop,
WhiteRook,
WhiteQueen,
WhiteKing,
BlackPawn,
BlackKnight,
BlackBishop,
BlackRook,
BlackQueen,
BlackKing
}