Skip to content

Instantly share code, notes, and snippets.

@jdiez17
Last active August 6, 2017 12:14
Show Gist options
  • Select an option

  • Save jdiez17/b0d0bdecff8a386803fba3be68a59cd0 to your computer and use it in GitHub Desktop.

Select an option

Save jdiez17/b0d0bdecff8a386803fba3be68a59cd0 to your computer and use it in GitHub Desktop.
mod piece;
mod square;
mod sentence;
mod board;
mod coords;
use sentence::Sentence;
use board::Board;
use piece::Color;
fn main() {
let game = vec![
("e4", Color::White),
("d5", Color::Black),
("exd5", Color::White)
];
let mut board = Board::new();
println!("{}", board);
println!("---");
for (op_str, color) in game {
let sentence = Sentence::new(op_str);
println!("{:?} plays {} ({:?}):", color, op_str, &sentence);
println!();
board = board.apply(&sentence, &color).unwrap();
println!("{}", board);
println!("---");
}
}
[jdiez@NervousEnergy chess-rs]$ cargo run
Compiling chess-rs v0.1.0 (file:///home/jdiez/dev/chess-rs)
Finished dev [unoptimized + debuginfo] target(s) in 0.77 secs
Running `target/debug/chess-rs`
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
6                 6
5                 5
4                 4
3                 3
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
---
White plays e4 (Move(Move { piece: Pawn, dst: Coords { x: 4, y: 4 } })):
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
6                 6
5                 5
4         ♙       4
3                 3
2 ♙ ♙ ♙ ♙   ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
---
Black plays d5 (Move(Move { piece: Pawn, dst: Coords { x: 3, y: 3 } })):
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟   ♟ ♟ ♟ ♟ 7
6                 6
5       ♟         5
4         ♙       4
3                 3
2 ♙ ♙ ♙ ♙   ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
---
White plays exd5 (PawnCapture(PawnCapture { dst: Coords { x: 3, y: 3 }, src_x: 4 })):
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟   ♟ ♟ ♟ ♟ 7
6                 6
5       ♙         5
4                 4
3                 3
2 ♙ ♙ ♙ ♙   ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment