From 85f6501b2cbdc17eb660b17e2f2df4d5fc15fd4b Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Mon, 13 Apr 2020 18:01:42 +0100 Subject: [PATCH] tidy up game implementation --- src/game.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/game.rs b/src/game.rs index 0c209d0..1a8b367 100644 --- a/src/game.rs +++ b/src/game.rs @@ -163,24 +163,14 @@ impl ToString for Game { } } -pub trait TileIds { - fn tile_ids(&self) -> Vec; -} - -impl TileIds for Game { +impl Game { fn tile_ids(&self) -> Vec { self.tiles.iter().map(|tile| {tile.id}).collect() } -} -/// first available tile ID. -/// e.g. if current tile IDs are [0, 2, 3] the result will be `1` -/// if current tile IDs are [0, 1, 2] the result will be `3` -pub trait NewTileId { - fn new_tile_id(&self) -> u64; -} - -impl NewTileId for Game { + /// first available tile ID. + /// e.g. if current tile IDs are [0, 2, 3] the result will be `1` + /// if current tile IDs are [0, 1, 2] the result will be `3` fn new_tile_id(&self) -> u64 { let mut new_id = 0; @@ -197,9 +187,6 @@ impl NewTileId for Game { new_id + 1 } -} - -impl Game { /// adds a tile safely and returns the new tile ID fn add_tile(&mut self, mut tile: Tile) -> u64 { let new_id = self.new_tile_id();