equal
deleted
inserted
replaced
|
1 use std::collections::HashMap; |
|
2 use integral_geometry::Point; |
|
3 use crate::GameField; |
|
4 |
|
5 pub struct Target { |
|
6 point: Point, |
|
7 health: i32, |
|
8 radius: u32, |
|
9 density: f32, |
|
10 |
|
11 } |
|
12 |
|
13 pub struct Hedgehog { |
|
14 pub(crate) x: f32, |
|
15 pub(crate) y: f32, |
|
16 } |
|
17 |
|
18 pub struct AI<'a> { |
|
19 game_field: &'a GameField, |
|
20 targets: Vec<Target>, |
|
21 team: Vec<Hedgehog>, |
|
22 } |
|
23 |
|
24 #[derive(Clone)] |
|
25 enum Direction { |
|
26 Left, |
|
27 Right |
|
28 } |
|
29 #[derive(Clone)] |
|
30 enum Action { |
|
31 Walk(Direction), |
|
32 LongJump, |
|
33 HighJump(usize) |
|
34 } |
|
35 |
|
36 #[derive(Clone)] |
|
37 struct Waypoint { |
|
38 x: f32, |
|
39 y: f32, |
|
40 ticks: usize, |
|
41 damage: usize, |
|
42 previous_point: Option<(usize, Action)>, |
|
43 } |
|
44 |
|
45 #[derive(Default)] |
|
46 pub struct Waypoints { |
|
47 key_points: Vec<Waypoint>, |
|
48 points: HashMap<Point, Waypoint>, |
|
49 } |
|
50 |
|
51 impl Waypoints { |
|
52 fn add_keypoint(&mut self, waypoint: Waypoint) { |
|
53 let [x, y] = [waypoint.x, waypoint.y].map(|i| i as i32); |
|
54 let point = Point::new(x, y); |
|
55 self.key_points.push(waypoint.clone()); |
|
56 self.points.insert(point, waypoint); |
|
57 } |
|
58 } |
|
59 |
|
60 impl<'a> AI<'a> { |
|
61 pub fn new(game_field: &'a GameField) -> AI<'a> { |
|
62 Self { |
|
63 game_field, |
|
64 targets: vec![], |
|
65 team: vec![], |
|
66 } |
|
67 } |
|
68 |
|
69 pub fn get_team_mut(&mut self) -> &mut Vec<Hedgehog> { |
|
70 &mut self.team |
|
71 } |
|
72 |
|
73 pub fn walk(hedgehog: &Hedgehog) { |
|
74 let mut stack = Vec::<usize>::new(); |
|
75 let mut waypoints = Waypoints::default(); |
|
76 |
|
77 waypoints.add_keypoint(Waypoint{ |
|
78 x: hedgehog.x, |
|
79 y: hedgehog.y, |
|
80 ticks: 0, |
|
81 damage: 0, |
|
82 previous_point: None, |
|
83 }); |
|
84 |
|
85 while let Some(wp) = stack.pop() { |
|
86 |
|
87 } |
|
88 } |
|
89 } |