Last active
January 16, 2022 07:35
-
-
Save FermiDirak/a7b7abf2b04b649e74fa3bb1854a01f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde::{Serialize, Deserialize}; | |
#[derive(Serialize, Deserialize)] | |
pub enum PlayerSide { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Move { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Board { /* ... */ } | |
#[derive(Serialize, Deserialize)] | |
pub struct Chess { board: Board, turn: PlayerSide } | |
impl Chess { | |
pub fn apply_move(&mut self, player_move: &PlayerMove) -> bool; | |
pub fn starting_state() -> Self; | |
pub fn list_valid_moves(&self) -> &[PlayerMove]; | |
} | |
// usage | |
let moves_data: String = read_input("input.txt")?; | |
let player_moves: Moves[] = serde_json::from_str(&moves_data)?; | |
let mut chess_game = Chess::starting_state(); | |
display(&chess_game); | |
for player_move in &player_moves { | |
chess_game.apply_move(player_move); | |
display(&chess_game); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment