summaryrefslogtreecommitdiff
path: root/src/knowledge.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-14 21:49:48 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-14 21:49:48 +0200
commit10c8ceb168e86a58e38086691ddd519bac63ff03 (patch)
treea40b433e7cfad492a60b37c5a337758ffe7d1786 /src/knowledge.rs
parent25a551316e27f4cc52c160d099db9cc3673b3421 (diff)
Added model for knowledge of the game's state
Will be useful to track deductions that have already been made.
Diffstat (limited to 'src/knowledge.rs')
-rw-r--r--src/knowledge.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/knowledge.rs b/src/knowledge.rs
new file mode 100644
index 0000000..3b0c61a
--- /dev/null
+++ b/src/knowledge.rs
@@ -0,0 +1,54 @@
+use actions::*;
+use ships::*;
+use std::collections::HashMap;
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct Knowledge {
+ pub last_action: Option<Action>,
+ pub opponent_map: OpponentMapKnowledge
+}
+
+impl Knowledge {
+ pub fn new() -> Knowledge {
+ Knowledge {
+ last_action: None,
+ opponent_map: OpponentMapKnowledge::new()
+ }
+ }
+
+ pub fn with_action(&self, action: Action) -> Knowledge {
+ Knowledge {
+ last_action: Some(action),
+ opponent_map: self.opponent_map.clone()
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct OpponentMapKnowledge {
+ pub ships: HashMap<Ship, OpponentShipKnowledge>,
+ pub cells: Vec<Vec<KnowledgeCell>>
+}
+
+impl OpponentMapKnowledge {
+ pub fn new() -> OpponentMapKnowledge {
+ OpponentMapKnowledge {
+ ships: HashMap::new(),
+ cells: Vec::new()
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct OpponentShipKnowledge {
+ pub destroyed: bool
+}
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct KnowledgeCell {
+ pub shot_attempted: bool,
+ pub possible_ship_uses: HashMap<Ship, u16>,
+ pub known_ship: Option<Ship>
+}
+
+