Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 30, 2018 00:42
Show Gist options
  • Save rust-play/ed91e42c85f9614968519d483694dc93 to your computer and use it in GitHub Desktop.
Save rust-play/ed91e42c85f9614968519d483694dc93 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
#[derive(Clone, Copy, Debug, PartialEq)]
enum Piece {
Pawn(Color),
Rook(Color),
Knight(Color),
Queen(Color),
King(Color),
Bishop(Color),
}
#[derive(Debug, Clone, Copy, PartialEq)]
enum Color {
White,
Black,
}
let mut chessboard: [Option<Piece>; 64] = [None; 64];
for i in 0..64 {
let (row, col) = (i%8, i/8);
chessboard[i] = match (row, col) {
(_, 2) => Some(Piece::Pawn(Color::Black)),
(_, 6) => Some(Piece::Pawn(Color::White)),
_ => None,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment