# HG changeset patch # User unC0Rr # Date 1732292970 -3600 # Node ID 6c5b3c576fc627c5f371b64a0e5edec0795e51e9 # Parent a236360669cc895b96255efe4f60c4653ea1f118 Add some progress on rust AI diff -r a236360669cc -r 6c5b3c576fc6 hedgewars/uAI2.pas --- 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; diff -r a236360669cc -r 6c5b3c576fc6 rust/lib-hwengine-future/src/ai/action.rs --- /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 +} + +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 { + self.actions.pop() + } +} \ No newline at end of file diff -r a236360669cc -r 6c5b3c576fc6 rust/lib-hwengine-future/src/ai/mod.rs --- 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, team: Vec, -} - -#[derive(Clone)] -enum Direction { - Left, - Right -} -#[derive(Clone)] -enum Action { - Walk(Direction), - LongJump, - HighJump(usize) + planned_actions: Option, } #[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() + } +} diff -r a236360669cc -r 6c5b3c576fc6 rust/lib-hwengine-future/src/lib.rs --- 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 +}