Skip to content

Commit

Permalink
fixed board indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
randallard committed Dec 5, 2024
1 parent 2052684 commit 5b416e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum CellContent {
Empty,
Player,
Trap,
Final,
}

#[derive(Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -202,6 +203,7 @@ pub fn BoardCreator(
>"Trap"</button>
</div>
}.into_any(),
CellContent::Final => view! { <span>" "</span> }.into_any(),
CellContent::Empty => view! { <span>" "</span> }.into_any(),
CellContent::Player => view! { <span>"○"</span> }.into_any(),
CellContent::Trap => view! { <span>"×"</span> }.into_any(),
Expand Down
10 changes: 6 additions & 4 deletions src/components/game_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ impl GameBoard {
svg,
r#"<text x="{}" y="{}" font-size="16" fill="white" text-anchor="middle" dy=".3em">{}</text>
<text x="{}" y="{}" font-size="16" fill="white" text-anchor="middle" dy=".3em">{}</text>"#,
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
Expand All @@ -159,7 +159,7 @@ impl GameBoard {
svg,
r#"<circle cx="{:.0}" cy="{:.0}" r="15" fill="rgb(37, 99, 235)"/>
<text x="{:.0}" y="{:.0}" font-size="16" fill="white" text-anchor="middle" dy=".3em">{}</text>"#,
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
);
}

Expand All @@ -170,7 +170,7 @@ impl GameBoard {
svg,
r#"<circle cx="{:.0}" cy="{:.0}" r="15" fill="rgb(147, 51, 234)"/>
<text x="{:.0}" y="{:.0}" font-size="16" fill="white" text-anchor="middle" dy=".3em">{}</text>"#,
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
);
}
}
Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand Down

0 comments on commit 5b416e0

Please sign in to comment.