From 096091af6a3a4d16da133037321c81a51e1bb4b2 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 7 Aug 2019 13:58:16 +0200 Subject: Lava assertions --- src/game.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index 6b7897d..c47d4b8 100644 --- a/src/game.rs +++ b/src/game.rs @@ -199,7 +199,22 @@ impl GameBoard { .map(|w| w.position) .collect(); - // TODO: Do some asssertions about the state of lava + 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]) { -- cgit v1.2.3