summaryrefslogtreecommitdiff
path: root/src/lib.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/lib.rs
parent36b72bfef7b7b8dea94546d11704ec529091bce1 (diff)
Random placement
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5ea9ecc..f3c1a00 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,11 +5,14 @@ mod actions;
mod math;
mod files;
mod ships;
+mod placement;
+mod shooting;
-use actions::*;
use math::*;
use files::*;
use ships::*;
+use placement::*;
+use shooting::*;
use std::path::PathBuf;
@@ -17,15 +20,15 @@ pub fn write_move(working_dir: PathBuf) -> Result<(), String> {
let state = read_file(&working_dir)?;
let is_place_phase = state["Phase"] == 1;
- let map_dimension = state["MapDimension"]
+ let map_size = state["MapDimension"]
.as_u16()
.ok_or("Did not find the map dimension in the state json file")?;
let action = if is_place_phase {
- place_ships()
+ place_ships_randomly(map_size)
}
else {
- shoot_randomly(map_dimension)
+ shoot_randomly(map_size)
};
write_action(&working_dir, is_place_phase, action)
@@ -34,22 +37,3 @@ pub fn write_move(working_dir: PathBuf) -> Result<(), String> {
Ok(())
}
-
-fn place_ships() -> Action {
- let ships = vec!(
- (Ship::Battleship, Point::new(1, 0), Orientation::North),
- (Ship::Carrier, Point::new(3, 1), Orientation::East),
- (Ship::Cruiser, Point::new(4, 2), Orientation::North),
- (Ship::Destroyer, Point::new(7, 3), Orientation::North),
- (Ship::Submarine, Point::new(1, 8), Orientation::East)
- );
-
- Action::PlaceShips(ships)
-}
-
-fn shoot_randomly(map_dimension: u16) -> Action {
- Action::Shoot(random_point(map_dimension))
-}
-
-
-