Add some progress on rust AI transitional_engine
authorunC0Rr
Fri, 22 Nov 2024 17:29:30 +0100
branchtransitional_engine
changeset 16040 6c5b3c576fc6
parent 16039 a236360669cc
child 16041 fc5258d7ecb2
Add some progress on rust AI
hedgewars/uAI2.pas
rust/lib-hwengine-future/src/ai/action.rs
rust/lib-hwengine-future/src/ai/mod.rs
rust/lib-hwengine-future/src/lib.rs
--- a/hedgewars/uAI2.pas	Sun Oct 27 17:00:17 2024 +0100
+++ b/hedgewars/uAI2.pas	Fri Nov 22 17:29:30 2024 +0100
@@ -14,6 +14,7 @@
 procedure ai_clear_team(ai: pointer); cdecl; external;
 procedure ai_add_team_hedgehog(ai: pointer; x, y: real); cdecl; external;
 procedure ai_think(ai: pointer); cdecl; external;
+function ai_have_plan(): boolean; cdecl; external;
 procedure dispose_ai(ai: pointer); cdecl; external;
 
 var ai: pointer;
@@ -38,7 +39,6 @@
             end;
         itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
     until (itHedgehog = currHedgehogIndex);
-
 end;
 
 procedure initModule;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/lib-hwengine-future/src/ai/action.rs	Fri Nov 22 17:29:30 2024 +0100
@@ -0,0 +1,31 @@
+#[derive(Clone)]
+pub enum Direction {
+    Left,
+    Right
+}
+#[derive(Clone)]
+pub enum Action {
+    Walk(Direction),
+    LongJump,
+    HighJump(usize)
+}
+
+pub struct Actions {
+    actions: Vec<Action>
+}
+
+impl Actions {
+    pub fn new() -> Self {
+        Self {
+            actions: vec![],
+        }
+    }
+
+    pub fn push(&mut self, action: Action) {
+        self.actions.push(action)
+    }
+
+    pub fn pop(&mut self) -> Option<Action> {
+        self.actions.pop()
+    }
+}
\ No newline at end of file
--- a/rust/lib-hwengine-future/src/ai/mod.rs	Sun Oct 27 17:00:17 2024 +0100
+++ b/rust/lib-hwengine-future/src/ai/mod.rs	Fri Nov 22 17:29:30 2024 +0100
@@ -1,6 +1,9 @@
+mod action;
+
 use std::collections::HashMap;
 use integral_geometry::Point;
 use crate::GameField;
+use action::*;
 
 pub struct Target {
     point: Point,
@@ -19,18 +22,7 @@
     game_field: &'a GameField,
     targets: Vec<Target>,
     team: Vec<Hedgehog>,
-}
-
-#[derive(Clone)]
-enum Direction {
-    Left,
-    Right
-}
-#[derive(Clone)]
-enum Action {
-    Walk(Direction),
-    LongJump,
-    HighJump(usize)
+    planned_actions: Option<Actions>,
 }
 
 #[derive(Clone)]
@@ -63,6 +55,7 @@
             game_field,
             targets: vec![],
             team: vec![],
+            planned_actions: None,
         }
     }
 
@@ -86,4 +79,8 @@
 
         }
     }
-}
\ No newline at end of file
+
+    pub fn have_plan(&self) -> bool {
+        self.planned_actions.is_some()
+    }
+}
--- a/rust/lib-hwengine-future/src/lib.rs	Sun Oct 27 17:00:17 2024 +0100
+++ b/rust/lib-hwengine-future/src/lib.rs	Fri Nov 22 17:29:30 2024 +0100
@@ -269,6 +269,16 @@
 }
 
 #[no_mangle]
+pub extern "C" fn ai_have_plan(ai: &AI) -> bool {
+    ai.have_plan()
+}
+
+#[no_mangle]
+pub extern "C" fn ai_get(ai: &AI) -> bool {
+    ai.have_plan()
+}
+
+#[no_mangle]
 pub extern "C" fn dispose_ai(ai: *mut AI) {
     unsafe { drop(Box::from_raw(ai)) };
-}
\ No newline at end of file
+}