From 2c3b3510c3bb8aa0d963d622d6bfb00f7a0f2e44 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Thu, 30 Dec 2021 23:54:47 -0600 Subject: [PATCH] Make illegal moves --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9e88211..014a2f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,7 @@ impl GameId { } } -#[derive(Clone, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] struct Piece { kind: PieceKind, color: Color, @@ -284,7 +284,7 @@ impl File { } } -#[derive(Clone, Default)] +#[derive(Clone, Debug, Default)] struct BoardState { inner: HashMap, } @@ -361,9 +361,10 @@ async fn start(start: Json, game_state: Data) -> HttpResponse let (tx, mut rx) = tokio::sync::mpsc::channel(1); - let initial_board_state = BoardState::starting_positions(); + let mut board_state = BoardState::starting_positions(); + + let serializable = board_state.to_serializable(); - let board_state = initial_board_state.clone(); let game_dropper = GameDropper((**game_state).clone(), game_id.clone()); let game_data = GameData { sender: tx }; @@ -379,6 +380,9 @@ async fn start(start: Json, game_state: Data) -> HttpResponse actix_web::rt::time::timeout(Duration::from_secs(60 * 5), rx.recv()).await { /* do stuff */ + if let Some(piece) = board_state.inner.remove(&msg.action.from) { + board_state.inner.insert(msg.action.to, piece); + } let _ = msg.reply.send(Reply { board_state: board_state.clone(), @@ -389,7 +393,7 @@ async fn start(start: Json, game_state: Data) -> HttpResponse }); HttpResponse::Ok().json(GameStart { - board: initial_board_state.to_serializable(), + board: serializable, game_id, }) }