commit 24c686c52da90d832bce9158f997de94049a0249 Author: Timothy Warren Date: Wed Jul 13 15:29:52 2022 -0400 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6651130 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "chess" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e68d50d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "chess" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..80d2c6c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,80 @@ +mod piece; + +enum MoveType { + VerticalOne, + VerticalTwo, + VerticalMany, + HorizontalMany, +} + +#[derive(Debug, Copy, Clone, PartialEq)] +enum BoardPosition { + A1, + A2, + A3, + A4, + A5, + A6, + A7, + A8, + B1, + B2, + B3, + B4, + B5, + B6, + B7, + B8, + C1, + C2, + C3, + C4, + C5, + C6, + C7, + C8, + D1, + D2, + D3, + D4, + D5, + D6, + D7, + D8, + E1, + E2, + E3, + E4, + E5, + E6, + E7, + E8, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + G1, + G2, + G3, + G4, + G5, + G6, + G7, + G8, + H1, + H2, + H3, + H4, + H5, + H6, + H7, + H8, +} + +fn main() { + println!("Hello, world!"); +} diff --git a/src/piece.rs b/src/piece.rs new file mode 100644 index 0000000..f838e11 --- /dev/null +++ b/src/piece.rs @@ -0,0 +1,75 @@ +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum PieceColor { + Black, + White, +} + +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum BishopType { + Dark, + Light, +} + +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum PieceType { + Pawn { promoted: bool }, + Rook, + Knight, + King, + Queen, + Bishop { kind: BishopType }, +} + +#[derive(Debug, PartialEq)] +pub struct Piece { + kind: PieceType, + color: PieceColor, + symbol: char, +} + +impl Piece { + pub fn new(color: PieceColor, kind: PieceType) -> Self { + Self { + kind, + color, + symbol: Self::get_symbol(color, kind), + } + } + + fn get_symbol(color: PieceColor, kind: PieceType) -> char { + use PieceColor::*; + use PieceType::*; + + match (color, kind) { + (White, Pawn { promoted: _ }) => '♙', + (White, Knight) => '♘', + (White, Bishop { kind: _ }) => '♗', + (White, Rook) => '♖', + (White, Queen) => '♕', + (White, King) => '♔', + (Black, Pawn { promoted: _ }) => '♟', + (Black, Knight) => '♞', + (Black, Bishop { kind: _ }) => '♝', + (Black, Rook) => '♜', + (Black, Queen) => '♛', + (Black, King) => '♚', + } + } +} + +mod test { + use super::*; + + #[test] + fn test_make_black_rook() { + let piece = Piece::new(PieceColor::Black, PieceType::Rook); + assert_eq!(piece.symbol, '♜'); + assert_eq!(piece.kind, PieceType::Rook); + assert_eq!(piece.color, PieceColor::Black); + } + + #[test] + fn test_get_white_knight() { + assert_eq!(Piece::get_symbol(PieceColor::White, PieceType::Knight), '♘'); + } +} \ No newline at end of file