summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bitwise_engine.rs30
-rw-r--r--src/engine/mod.rs35
-rw-r--r--src/engine/settings.rs44
-rw-r--r--src/engine/status.rs7
4 files changed, 26 insertions, 90 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
index 8a4ea91..6b9ccab 100644
--- a/src/engine/bitwise_engine.rs
+++ b/src/engine/bitwise_engine.rs
@@ -1,13 +1,19 @@
use engine::command::{Command, BuildingType};
use engine::geometry::Point;
-use engine::settings::{GameSettings};
use engine::constants::*;
-use engine::{GameStatus, Player, GameState};
+use engine::status::GameStatus;
const LEFT_COL_MASK: u64 = 0x0101010101010101;
const RIGHT_COL_MASK: u64 = 0x8080808080808080;
#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Player {
+ pub energy: u16,
+ pub health: u8,
+ pub energy_generated: u16,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BitwiseGameState {
pub status: GameStatus,
pub player: Player,
@@ -48,8 +54,8 @@ pub struct TeslaCooldown {
}
-impl GameState for BitwiseGameState {
- fn simulate(&mut self, _settings: &GameSettings, player_command: Command, opponent_command: Command) -> GameStatus {
+impl BitwiseGameState {
+ pub fn simulate(&mut self, player_command: Command, opponent_command: Command) -> GameStatus {
BitwiseGameState::perform_command(&mut self.player, &mut self.player_buildings, player_command);
BitwiseGameState::perform_command(&mut self.opponent, &mut self.opponent_buildings, opponent_command);
@@ -71,20 +77,20 @@ impl GameState for BitwiseGameState {
self.status
}
- fn player(&self) -> &Player { &self.player }
- fn opponent(&self) -> &Player { &self.opponent }
- fn player_has_max_teslas(&self) -> bool { self.player_buildings.count_teslas() >= TESLA_MAX }
- fn opponent_has_max_teslas(&self) -> bool { self.opponent_buildings.count_teslas() >= TESLA_MAX }
+ pub fn player(&self) -> &Player { &self.player }
+ pub fn opponent(&self) -> &Player { &self.opponent }
+ pub fn player_has_max_teslas(&self) -> bool { self.player_buildings.count_teslas() >= TESLA_MAX }
+ pub fn opponent_has_max_teslas(&self) -> bool { self.opponent_buildings.count_teslas() >= TESLA_MAX }
- fn unoccupied_player_cell_count(&self) -> usize { self.player_buildings.occupied.count_zeros() as usize }
- fn unoccupied_opponent_cell_count(&self) -> usize { self.opponent_buildings.occupied.count_zeros() as usize }
- fn location_of_unoccupied_player_cell(&self, i: usize) -> Point {
+ pub fn unoccupied_player_cell_count(&self) -> usize { self.player_buildings.occupied.count_zeros() as usize }
+ pub fn unoccupied_opponent_cell_count(&self) -> usize { self.opponent_buildings.occupied.count_zeros() as usize }
+ pub fn location_of_unoccupied_player_cell(&self, i: usize) -> Point {
let bit = find_bit_index_from_rank(self.player_buildings.occupied, i as u64);
let point = Point::new(bit%SINGLE_MAP_WIDTH, bit/SINGLE_MAP_WIDTH);
debug_assert!(point.to_either_bitfield() & self.player_buildings.occupied == 0);
point
}
- fn location_of_unoccupied_opponent_cell(&self, i: usize) -> Point {
+ pub fn location_of_unoccupied_opponent_cell(&self, i: usize) -> Point {
let bit = find_bit_index_from_rank(self.opponent_buildings.occupied, i as u64);
let point = Point::new(FULL_MAP_WIDTH - bit%SINGLE_MAP_WIDTH - 1, bit/SINGLE_MAP_WIDTH);
debug_assert!(point.to_either_bitfield() & self.opponent_buildings.occupied == 0);
diff --git a/src/engine/mod.rs b/src/engine/mod.rs
index c205d72..f98ef6b 100644
--- a/src/engine/mod.rs
+++ b/src/engine/mod.rs
@@ -1,38 +1,5 @@
pub mod command;
pub mod geometry;
-pub mod settings;
pub mod bitwise_engine;
pub mod constants;
-
-use self::command::{Command};
-use self::geometry::Point;
-use self::settings::{GameSettings};
-
-pub trait GameState: Clone + Sync {
- fn simulate(&mut self, settings: &GameSettings, player_command: Command, opponent_command: Command) -> GameStatus;
-
- fn player(&self) -> &Player;
- fn opponent(&self) -> &Player;
- fn player_has_max_teslas(&self) -> bool;
- fn opponent_has_max_teslas(&self) -> bool;
-
- fn unoccupied_player_cell_count(&self) -> usize;
- fn unoccupied_opponent_cell_count(&self) -> usize;
- fn location_of_unoccupied_player_cell(&self, i: usize) -> Point;
- fn location_of_unoccupied_opponent_cell(&self, i: usize) -> Point;
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum GameStatus {
- Continue,
- PlayerWon,
- OpponentWon,
- Draw
-}
-
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct Player {
- pub energy: u16,
- pub health: u8,
- pub energy_generated: u16,
-}
+pub mod status;
diff --git a/src/engine/settings.rs b/src/engine/settings.rs
deleted file mode 100644
index 18bdde0..0000000
--- a/src/engine/settings.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-use super::geometry::Point;
-use super::command::BuildingType;
-use std::cmp;
-
-#[derive(Debug)]
-pub struct GameSettings {
- pub size: Point,
- pub energy_income: u16,
- pub max_building_price: u16,
- pub energy: BuildingSettings,
- pub defence: BuildingSettings,
- pub attack: BuildingSettings,
- pub tesla: BuildingSettings,
-}
-
-#[derive(Debug)]
-pub struct BuildingSettings {
- pub price: u16,
- pub health: u8,
- pub construction_time: u8,
- pub weapon_damage: u8,
- pub weapon_speed: u8,
- pub weapon_cooldown_period: u8,
- pub energy_generated_per_turn: u16
-}
-
-impl GameSettings {
- pub fn new(size: Point, energy_income: u16, energy: BuildingSettings, defence: BuildingSettings, attack: BuildingSettings, tesla: BuildingSettings) -> GameSettings {
- let max_building_price = cmp::max(cmp::max(cmp::max(energy.price, defence.price), attack.price), tesla.price);
- GameSettings {
- size, energy_income, max_building_price,
- energy, defence, attack, tesla
- }
- }
- pub fn building_settings(&self, building: BuildingType) -> &BuildingSettings {
- match building {
- BuildingType::Defence => &self.defence,
- BuildingType::Attack => &self.attack,
- BuildingType::Energy => &self.energy,
- BuildingType::Tesla => &self.tesla,
- }
- }
-
-}
diff --git a/src/engine/status.rs b/src/engine/status.rs
new file mode 100644
index 0000000..1fa7ac0
--- /dev/null
+++ b/src/engine/status.rs
@@ -0,0 +1,7 @@
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum GameStatus {
+ Continue,
+ PlayerWon,
+ OpponentWon,
+ Draw
+}