diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-04-25 21:37:53 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-04-25 21:37:53 +0200 |
commit | 3e4f70ff90471120818cfb38a6dbde4952c11b8f (patch) | |
tree | acb2102273f902115d50f6d9a533919d7bc49a20 /src/game.rs | |
parent | ec9041a9526b52910aafac1f7c0acfc8215ac107 (diff) |
Strategy that starts building exhaustive game state tree
This falls over (and takes the host machine with it) because its
memory usage grows catastrophically.
The main use of time, reported by perf, was cloning the map vector.
Diffstat (limited to 'src/game.rs')
-rw-r--r-- | src/game.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/game.rs b/src/game.rs index 434828a..8fd9153 100644 --- a/src/game.rs +++ b/src/game.rs @@ -4,20 +4,20 @@ use crate::json; use arrayvec::ArrayVec; -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct GameBoard { pub players: [Player; 2], pub powerups: ArrayVec<[Powerup; 2]>, pub map: Map, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct Player { pub active_worm: usize, pub worms: ArrayVec<[Worm; 3]> } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct Worm { pub id: i32, pub health: i32, @@ -31,7 +31,7 @@ pub enum Powerup { Health(Point2d<i8>, i32) } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct Map { pub size: u8, /// This is 2d, each row is size long @@ -223,7 +223,7 @@ impl Player { .find(|w| w.id == id) } - fn active_worm(&self) -> &Worm { + pub fn active_worm(&self) -> &Worm { &self.worms[self.active_worm] } @@ -233,7 +233,7 @@ impl Player { } impl Map { - fn at(&self, p: Point2d<i8>) -> Option<CellType> { + pub fn at(&self, p: Point2d<i8>) -> Option<CellType> { if p.y < 0 || p.x < 0 || p.y as u8 >= self.size || p.x as u8 >= self.size { None } else { |