summaryrefslogtreecommitdiff
path: root/src/placement.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-13 21:01:14 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-13 21:01:14 +0200
commit872529bc9a13b1923047a7f9308abaa40eb63d3c (patch)
tree9da73efa835896ee206daeb262fde550aaa99907 /src/placement.rs
parent36b72bfef7b7b8dea94546d11704ec529091bce1 (diff)
Random placement
Diffstat (limited to 'src/placement.rs')
-rw-r--r--src/placement.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/placement.rs b/src/placement.rs
new file mode 100644
index 0000000..faa340e
--- /dev/null
+++ b/src/placement.rs
@@ -0,0 +1,24 @@
+use actions::*;
+use math::*;
+use ships::*;
+
+pub fn place_ships_randomly(map_size: u16) -> Action {
+ let mut current_placement: Vec<ShipPlacement>;
+
+ while {
+ current_placement = create_random_placement(map_size);
+ !ShipPlacement::valid_placements(&current_placement, map_size)
+ } {}
+
+ Action::PlaceShips(current_placement)
+}
+
+fn create_random_placement(map_size: u16) -> Vec<ShipPlacement> {
+ vec!(
+ ShipPlacement::new(Ship::Battleship, Point::random(map_size), Direction::random()),
+ ShipPlacement::new(Ship::Carrier, Point::random(map_size), Direction::random()),
+ ShipPlacement::new(Ship::Cruiser, Point::random(map_size), Direction::random()),
+ ShipPlacement::new(Ship::Destroyer, Point::random(map_size), Direction::random()),
+ ShipPlacement::new(Ship::Submarine, Point::random(map_size), Direction::random())
+ )
+}