Commit working directory

This commit is contained in:
2024-04-06 16:11:09 +03:00
commit 69946f09be
6 changed files with 138 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/target
settings.json

7
Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ippos"
version = "0.1.0"

8
Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "ippos"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

97
src/board.rs Normal file
View File

@@ -0,0 +1,97 @@
use std::fmt;
use u64 as Bitboard;
pub struct Board {
white_pieces: [Piece; 6],
black_pieces: [Piece; 6],
}
impl Board {
pub fn new() -> Board {
Board {
white_pieces: [
Piece::new(0xff00, Kind::Pawn, Color::White),
Piece::new(0x81, Kind::Rook, Color::White),
Piece::new(0x42, Kind::Knight, Color::White),
Piece::new(0x24, Kind::Bishop, Color::White),
Piece::new(0x8, Kind::Queen, Color::White),
Piece::new(0x10, Kind::King, Color::White),
],
black_pieces: [
Piece::new(0xff000000000000, Kind::Pawn, Color::Black),
Piece::new(0x8100000000000000, Kind::Rook, Color::Black),
Piece::new(0x4200000000000000, Kind::Knight, Color::Black),
Piece::new(0x2400000000000000, Kind::Bishop, Color::Black),
Piece::new(0x1000000000000000, Kind::Queen, Color::Black),
Piece::new(0x800000000000000, Kind::King, Color::Black),
],
}
}
}
impl fmt::Display for Board {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for piece in &self.white_pieces {
writeln!(
f,
"Color: {:?}\nKind: {:?}\n{piece}",
piece.color, piece.kind
)?;
}
writeln!(f, "")?;
for piece in &self.black_pieces {
writeln!(
f,
"Color: {:?}\nKind: {:?}\n{piece}",
piece.color, piece.kind
)?;
}
write!(f, "")
}
}
pub struct Piece {
pub position: Bitboard,
pub kind: Kind,
pub color: Color,
}
impl Piece {
pub fn new(position: Bitboard, kind: Kind, color: Color) -> Piece {
Piece {
position,
kind,
color,
}
}
}
impl fmt::Display for Piece {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for rank in (0..8).rev() {
for file in 0..8 {
let square = 1 << (rank * 8 + file);
let position = if square & self.position != 0x0 { 1 } else { 0 };
write!(f, "{} ", position)?;
}
writeln!(f, "")?;
}
write!(f, "")
}
}
#[derive(Debug)]
pub enum Kind {
Pawn,
Rook,
Knight,
Bishop,
Queen,
King,
}
#[derive(Debug)]
pub enum Color {
White,
Black,
}

14
src/game.rs Normal file
View File

@@ -0,0 +1,14 @@
use crate::board::Board;
pub struct Game {}
impl Game {
pub fn new() -> Game {
Game {}
}
pub fn run(&self) {
let board = Board::new();
println!("{}", board)
}
}

9
src/main.rs Normal file
View File

@@ -0,0 +1,9 @@
pub mod board;
pub mod game;
use game::Game;
fn main() {
let game = Game::new();
game.run();
}