Crates.io | arday11ChessLibrary |
lib.rs | arday11ChessLibrary |
version | 0.5.0 |
source | src |
created_at | 2024-09-19 18:50:22.74649 |
updated_at | 2024-09-24 06:56:21.850582 |
description | test |
homepage | |
repository | |
max_upload_size | |
id | 1380595 |
size | 37,343 |
This is a chess library that does the management of chess games. It calculates all legal moves for any given position, and handles all events that might happen during a chess game
This starts a new game session and returns a game struct
const game = ChessLibrary::Start();
This struct holds all important information about the current game
struct Game {
board: Board,
status: Status,
current_move: Move,
white_castle_short: bool,
white_castle_long: bool,
black_castle_short: bool,
black_castle_long: bool,
}
This struct contain all important information about the current game status
pub enum Status {
WHITE_TO_MOVE,
BLACK_TO_MOVE,
DRAW,
WHITE_HAS_CHECKMATE,
BLACK_HAS_CHECKMATE,
}
The first function gets all the legal moves for all pieces and maps all legal moves for each piece to its corresponding position on the board
The second function gets all legal moves for any given position (rank, file)
use std::collections::HashMap;
const all_legal_moves: HashMap<Position, Vec<Position>> = ChessLibrary::get_all_legal_moves(game);
const legal_moves = Vec<Position> = ChessLibrary::get_legal_moves_for_piece(position);
This function makes a move and modifies the game struct and returns a boolean on whether the operation was successful or not
let mut game = Game::new();
match make_move(&mut game, &Position::create(startRow, startFile), &Position::create(endRow, endFile)) {
Ok(v) => println!("Success"),
Err(e) => println!("{}", e)
}
}