From db09fe8cce2861bec71a15630f957c0a63fdde94 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Mon, 20 May 2024 21:20:42 -0700 Subject: [PATCH] AI is almost fully working! --- assets/martian.tweak.toml | 5 +- src/ai.rs | 166 ++++++++++++++++++++++++++++++++------ src/display3d.rs | 16 +++- src/menu.rs | 65 +++++++++++++++ 4 files changed, 224 insertions(+), 28 deletions(-) diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index 1eef376..444ab95 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -288,4 +288,7 @@ fast_light_speed = 1.0 # 0: Disabled # -1: No limit # N: Some value in-between -undo_limit = -1 \ No newline at end of file +undo_limit = -1 + +[ai] +lag_secs = 2.0 \ No newline at end of file diff --git a/src/ai.rs b/src/ai.rs index 9a66638..3970824 100644 --- a/src/ai.rs +++ b/src/ai.rs @@ -5,46 +5,164 @@ pub(crate) struct AiPlugin; impl Plugin for AiPlugin { fn build(&self, app: &mut App) { app.init_state::() + .init_resource::() + .init_state::() // Bogo AI Systems - .add_systems(Update, - bogo_ai.run_if(in_state(PlayState::AiBogo)) + .add_systems( + Update, + ( + bogo_ai_thinking + .run_if(in_state(AiDrama::Thinking)), + bogo_ai_holding + .run_if(in_state(AiDrama::Holding)), + ) + .run_if(in_state(PlayState::AiBogo)) + .run_if(in_state(GameState::Play)) + .run_if(in_state(TurnState(Side::A))) ); } } -#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone)] -enum PlayState { - #[default] +#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)] +pub(crate) enum PlayState { Human, + #[default] AiBogo, } +#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone)] +enum AiDrama { + // Before AI picks up a piece + #[default] + Thinking, + // When AI picks up piece + Holding, +} + +/// The move the AI will commit +#[derive(Debug, Resource, Default)] +struct AiMove(Move); + // Bogo AI logic -fn bogo_ai( +fn bogo_ai_thinking( + board: Res, + query: Query<(Entity, &BoardIndex), With>, + time: Res