diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-08-07 14:37:36 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-08-07 14:37:36 +0200 |
commit | d4539771bca817add851ef484de4773cbbe43f79 (patch) | |
tree | 371556db78894f666425d8d28a67b23f89aed196 /src/game.rs | |
parent | 096091af6a3a4d16da133037321c81a51e1bb4b2 (diff) |
Assertions to test that my lava logic is right
Diffstat (limited to 'src/game.rs')
-rw-r--r-- | src/game.rs | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/src/game.rs b/src/game.rs index c47d4b8..5f6ab33 100644 --- a/src/game.rs +++ b/src/game.rs @@ -178,8 +178,53 @@ impl GameBoard { .collect(); for cell in json.map.iter().flatten() { + let point = Point2d::new(cell.x, cell.y); + + if cfg!(debug_assertions) { + // This checks if my lava map is the same as the game + // engine's lava map. It's off by one because the game + // engine will update its one at the beginning of + // processing the round. + let lava = LAVA_MAP[self.round as usize]; + + let lava_at = lava.at(point); + // NB: Map hasn't been updated yet, so it can be used to tell previous state. + match (&cell.cell_type, self.map.at(point)) { + (json::CellType::Air, Some(false)) => assert!( + lava_at == Some(false), + "Lava at {:?} expected Some(false), but found {:?}", + point, + lava_at + ), + (json::CellType::Air, _) => assert!( + lava_at.is_some(), + "Lava at {:?} expected Some(_), but found {:?}", + point, + lava_at + ), + (json::CellType::Lava, _) => assert!( + lava_at == Some(true), + "Lava at {:?} expected Some(true), but found {:?}", + point, + lava_at + ), + (json::CellType::DeepSpace, _) => assert!( + lava_at == None, + "Lava at {:?} expected None, but found {:?}", + point, + lava_at + ), + (json::CellType::Dirt, _) => assert!( + lava_at.is_some(), + "Lava at {:?} expected Some(_), but found {:?}", + point, + lava_at + ), + }; + } + if cell.cell_type == json::CellType::Air { - self.map.clear(Point2d::new(cell.x, cell.y)) + self.map.clear(point) } } @@ -198,23 +243,6 @@ impl GameBoard { .flat_map(|p| p.worms.iter()) .map(|w| w.position) .collect(); - - if cfg!(debug_assertions) { - // This checks if my lava map is the same as the game - // engine's lava map. It's off by one because the game - // engine will update its one at the beginning of - // processing the round. - let lava = LAVA_MAP[self.round as usize - 1]; - for cell in json.map.iter().flatten() { - let lava_at = lava.at(Point2d::new(cell.x, cell.y)); - match cell.cell_type { - json::CellType::Air => assert!(lava_at == Some(false)), - json::CellType::Lava => assert!(lava_at == Some(true)), - json::CellType::DeepSpace => assert!(lava_at == None), - json::CellType::Dirt => assert!(lava_at.is_some()), - }; - } - } } pub fn simulate(&mut self, moves: [Command; 2]) { |