cleanup, fix crashes for some board-edge interactions
This commit is contained in:
parent
682dff48f9
commit
0738e658db
3 changed files with 109 additions and 106 deletions
|
@ -108,15 +108,14 @@ impl Board {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_mut_unchecked(&mut self, p: Pos) -> &mut Tile {
|
||||
pub fn get_blank_mut(&mut self, p: Pos) -> Option<&mut Tile> {
|
||||
if self.in_bounds(p) {
|
||||
&mut self.rows[p.y as usize][p.x as usize]
|
||||
} else {
|
||||
panic!(
|
||||
"position {p:?} out of bounds, size is {}x{}",
|
||||
self.width, self.height
|
||||
);
|
||||
let tile = &mut self.rows[p.y as usize][p.x as usize];
|
||||
if tile == &Tile::Blank {
|
||||
return Some(tile);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn set(&mut self, p: Pos, tile: Tile) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue