1mod decision;
5mod enemy;
6mod perception;
7mod scheduler;
8mod squad;
9pub use decision::*;
10pub use enemy::*;
11pub use perception::*;
12pub use scheduler::*;
13pub use squad::*;
14
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16pub enum AiError {
17 InvalidConfiguration,
18 InvalidInput,
19 Capacity,
20 InvalidState,
21}
22
23#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
26pub struct WorkCounts {
27 pub candidates: u32,
28 pub queries: u32,
29 pub path_steps: u32,
30 pub deferred_candidates: u32,
31 pub deferred_queries: u32,
32}
33#[derive(Clone, Copy, Debug)]
34pub struct WorkBudget {
35 candidates: u32,
36 queries: u32,
37 paths: u32,
38 counts: WorkCounts,
39}
40impl WorkBudget {
41 pub fn new(candidates: u32, queries: u32, path_steps: u32) -> Self {
42 Self {
43 candidates,
44 queries,
45 paths: path_steps,
46 counts: WorkCounts::default(),
47 }
48 }
49 pub fn counts(&self) -> WorkCounts {
50 self.counts
51 }
52 pub fn remaining_path_steps(&self) -> u32 {
53 self.paths
54 }
55 pub fn spend_path_steps(&mut self, steps: u32) -> bool {
56 if steps > self.paths {
57 return false;
58 }
59 self.paths -= steps;
60 self.counts.path_steps += steps;
61 true
62 }
63 pub fn candidate(&mut self) -> bool {
64 if self.candidates == 0 {
65 self.counts.deferred_candidates = self.counts.deferred_candidates.saturating_add(1);
66 false
67 } else {
68 self.candidates -= 1;
69 self.counts.candidates += 1;
70 true
71 }
72 }
73 pub fn query(&mut self) -> bool {
74 if self.queries == 0 {
75 self.counts.deferred_queries = self.counts.deferred_queries.saturating_add(1);
76 false
77 } else {
78 self.queries -= 1;
79 self.counts.queries += 1;
80 true
81 }
82 }
83}