From 5b416e0d94831bd0758e6478affd7fdb57d6f6c1 Mon Sep 17 00:00:00 2001 From: Ryan Khetlyr Date: Thu, 5 Dec 2024 10:38:33 -0800 Subject: [PATCH] fixed board indexes --- src/components/board.rs | 4 +++- src/components/game_board.rs | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/board.rs b/src/components/board.rs index 0cd4902..e6ed306 100644 --- a/src/components/board.rs +++ b/src/components/board.rs @@ -12,6 +12,7 @@ pub enum CellContent { Empty, Player, Trap, + Final, } #[derive(Clone, Serialize, Deserialize, PartialEq)] @@ -90,7 +91,7 @@ pub fn BoardCreator( // Modified this condition to allow final move after placing trap if row == usize::MAX || is_adjacent(player_row, player_col, row, col) { if row == usize::MAX { // Final move logic - current_board.sequence.push((0, player_col, CellContent::Player)); + current_board.sequence.push((0, player_col, CellContent::Final)); current_board.grid[player_row][player_col] = CellContent::Empty; board.set(current_board.clone()); // Clone here before it's moved @@ -202,6 +203,7 @@ pub fn BoardCreator( >"Trap" }.into_any(), + CellContent::Final => view! { " " }.into_any(), CellContent::Empty => view! { " " }.into_any(), CellContent::Player => view! { "○" }.into_any(), CellContent::Trap => view! { "×" }.into_any(), diff --git a/src/components/game_board.rs b/src/components/game_board.rs index cc250ba..8187b29 100644 --- a/src/components/game_board.rs +++ b/src/components/game_board.rs @@ -148,8 +148,8 @@ impl GameBoard { svg, r#"{} {}"#, - center_x - radius/2.0, center_y, *player_step, - center_x + radius/2.0, center_y, *opponent_step + center_x - radius/2.0, center_y, *player_step + 1, + center_x + radius/2.0, center_y, *opponent_step + 1 ); } else { // Draw single player circle if only player visited @@ -159,7 +159,7 @@ impl GameBoard { svg, r#" {}"#, - x + 20.0, y + 20.0, x + 20.0, y + 20.0, *step + x + 20.0, y + 20.0, x + 20.0, y + 20.0, *step + 1 ); } @@ -170,7 +170,7 @@ impl GameBoard { svg, r#" {}"#, - x + 20.0, y + 20.0, x + 20.0, y + 20.0, *step + x + 20.0, y + 20.0, x + 20.0, y + 20.0, *step + 1 ); } } @@ -355,6 +355,7 @@ impl GameBoard { CellContent::Player => "Player", CellContent::Trap => "Trap", CellContent::Empty => "Empty", + CellContent::Final => "Final", }; console::log_1(&format!("Step {}: ({}, {}) - {}", i + 1, row, col, content_str).into()); @@ -376,6 +377,7 @@ impl GameBoard { CellContent::Player => "Player", CellContent::Trap => "Trap", CellContent::Empty => "Empty", + CellContent::Final => "Final", }; console::log_1(&format!("Step {}: ({}, {}) - {}", i + 1, row, col, content_str).into());