Fenex Chess Library
Fenex is a Rust library for handling chess game logic. It provides support for parsing Forsyth-Edwards Notation (FEN) strings, handling chess moves in algebraic notation, and more.
Features
Fen Module
The Fen module provides the Fen struct for representing a chess position in Forsyth-Edwards Notation (FEN).
Fen Struct
-
Constructor:
Fen::new(board: &str) -> Fen- Creates a new
Fenstruct from a given board position string.
- Creates a new
-
Parser:
Fen::parse_fen(fen_str: &str) -> Result<Fen, &'static str>- Parses a FEN string into a
Fenstruct.
- Parses a FEN string into a
-
Debug Printing:
Fen::debug()- Prints the values inside the
Fenstruct for debugging purposes.
- Prints the values inside the
-
Board Printing:
Fen::print_to_board()- Prints the chess board to the console.
-
Board Conversion:
Fen::boardify() -> String- Converts the
Fenstruct into a string representation of a chess board.
- Converts the
Coordinates Module
The Coordinates module provides the Coordinates struct for representing a position on the chess board.
Coordinates Struct
-
Constructor:
Coordinates { x: i8, y: i8 }- Creates a new
Coordinatesstruct with given x and y values.
- Creates a new
-
From Notation:
Coordinates::from_notation(notation: Notation) -> Result<Coordinates, &'static str>- Converts a
Notationstruct into aCoordinatesstruct.
- Converts a
-
To Notation:
Coordinates::to_notation(&self) -> Result<Notation, &'static str>- Converts the
Coordinatesstruct into aNotationstruct.
- Converts the
Notation Module
The Notation module provides the Notation struct for representing a chess move in algebraic notation.
Notation Struct
-
Constructor:
Notation::new(file: char, rank: char) -> Option<Notation>- Creates a new
Notationstruct with given file and rank values.
- Creates a new
-
From Coordinates:
Notation::from_coordinates(coordinates: Coordinates) -> Result<Notation, &'static str>- Converts a
Coordinatesstruct into aNotationstruct.
- Converts a
-
To Coordinates:
Notation::to_coordinates(&self) -> Result<Coordinates, &'static str>- Converts the
Notationstruct into aCoordinatesstruct.
- Converts the
ChessPieceEnum Module
The ChessPieceEnum module defines the ChessPieceEnum enum, representing different types of chess pieces, and provides methods for updating both color and coordinates.
BoardType Module
The BoardType module defines the BoardType enum, representing different types of chess boards (1D and 2D).
Board Module
The Board module provides the Board struct for handling chess boards in both 1D and 2D representations.
Board Struct
-
Constructor:
Board::new_one_dimensional() -> BoardandBoard::new_two_dimensional() -> Board- Creates a new
1Dor2Dboard with all squares empty.
- Creates a new
-
Starting Position:
Board::new_one_dimensional_starting_position() -> BoardandBoard::new_two_dimensional_starting_position() -> Board- Creates a new
1Dor2Dboard with pieces in the starting position.
- Creates a new
-
Set Piece:
Board::set_piece(&mut self, coordinates: Coordinates, piece: ChessPieceEnum)- Sets a piece at the given coordinates.
-
Get Piece:
Board::get_piece(&self, coordinates: Coordinates) -> Option<&ChessPieceEnum>- Gets the piece at the given coordinates.
How To Install
Just run the cargo add fenexin your project directory.
Or add fenex = "0.1.2" in your Cargo.toml, Under dependencies.
Sample Uses
Coordinates and Notations
Boards
Contribution
Contributions to Fenex are welcome! Please ensure your code is formatted with cargo fmt before creating a pull request.