diff --git a/src/Agents/Agent.cs b/src/Agents/Agent.cs index 8138848..dca77e7 100644 --- a/src/Agents/Agent.cs +++ b/src/Agents/Agent.cs @@ -3,6 +3,7 @@ namespace Polonium.Agents; public abstract class Agent { + protected static int ComputerCount = 0; public string Name { get; init; } @@ -11,15 +12,27 @@ public abstract class Agent Name = name; PoloniumRegistry.Instance.Agents[name] = this; } + + public int Level { get; private set; } + public abstract int MaxLevel { get; } + + public virtual void LevelUp() + { + if(Level < MaxLevel) + Level++; + } + } -public abstract class Agent : Agent - where TAgent : Agent - where TAgentDecisionMaker : AgentDecisionMaker, new() - where TAgentKnowledge : AgentKnowledge, new() +public abstract class Agent : Agent + where TAgent : Agent, new() + where TAgentDecisionMaker : AgentDecisionMaker, new() + where TAgentKnowledge : AgentKnowledge, new() + where TAgentAction : AgentAction, new() { - private static int ComputerCount = 0; + public Dictionary Actions { get; } = new(); + public TAgentDecisionMaker DecisionMaker { get; init; } public TAgentKnowledge Knowledge { get; init; } diff --git a/src/Agents/AgentAction.cs b/src/Agents/AgentAction.cs new file mode 100644 index 0000000..328832e --- /dev/null +++ b/src/Agents/AgentAction.cs @@ -0,0 +1,60 @@ +using Polonium.Interfaces; + +namespace Polonium.Agents; + +public abstract class AgentAction +{ +} + +public abstract class AgentAction : AgentAction, ITimeConsumer + where TAgent : Agent, new() + where TAgentDecisionMaker : AgentDecisionMaker, new() + where TAgentKnowledge : AgentKnowledge, new() + where TAgentAction : AgentAction, new() +{ + + public int Level { get; private set; } + + public abstract int MaxLevel { get; } + + public virtual void LevelUp() + { + if(Level < MaxLevel) + Level++; + } + + public AgentAction(double coolDown) + { + CoolDown = coolDown; + PoloniumRegistry.Instance.TimeConsumers.Add(this); + } + + public abstract class ActionParameter + { + } + + public virtual bool Execute(ActionParameter parameter) + { + if (Disabled || CoolDown > 0) + return false; + CoolDownTime = CoolDown; + return true; + } + + + private double CoolDownTime { get; set; } + public bool Disabled { get; set; } + + private double CoolDown { get; } + + public void Process(double delta) + { + + if (Disabled || CoolDownTime <= 0) + return; + CoolDownTime -= delta; + if (CoolDownTime <= 0) + CoolDownTime = 0; + + } +} diff --git a/src/Agents/AgentDecisionMaker.cs b/src/Agents/AgentDecisionMaker.cs index c5d28bd..4c20980 100644 --- a/src/Agents/AgentDecisionMaker.cs +++ b/src/Agents/AgentDecisionMaker.cs @@ -1,28 +1,17 @@ namespace Polonium.Agents; -public abstract class AgentDecisionMaker - where TAgent : Agent - where TAgentDecisionMaker : AgentDecisionMaker, new() - where TAgentKnowledge : AgentKnowledge, new() +public abstract class AgentDecisionMaker(DecisionMakerType type) + where TAgent : Agent, new() + where TAgentDecisionMaker : AgentDecisionMaker, new() + where TAgentKnowledge : AgentKnowledge, new() + where TAgentAction : AgentAction, new() { - public enum DecisionMakerType - { - None = 0, - Player = 1, - Computer = 2, - Global = 3, - } - - public DecisionMakerType Type { get; init; } - - public AgentDecisionMaker() - { - Type = DecisionMakerType.Computer; - } - public AgentDecisionMaker(DecisionMakerType type) + + public DecisionMakerType Type { get; init; } = type; + + public AgentDecisionMaker() : this(DecisionMakerType.Computer) { - Type = type; } } \ No newline at end of file diff --git a/src/Agents/AgentKnowledge.cs b/src/Agents/AgentKnowledge.cs index 8f986b1..4b07676 100644 --- a/src/Agents/AgentKnowledge.cs +++ b/src/Agents/AgentKnowledge.cs @@ -1,9 +1,14 @@ namespace Polonium.Agents; -public abstract class AgentKnowledge - where TAgent : Agent - where TAgentDecisionMaker : AgentDecisionMaker, new() - where TAgentKnowledge : AgentKnowledge, new() +public abstract class AgentKnowledge +{ +} + +public abstract class AgentKnowledge : AgentKnowledge + where TAgent : Agent, new() + where TAgentDecisionMaker : AgentDecisionMaker, new() + where TAgentKnowledge : AgentKnowledge, new() + where TAgentAction : AgentAction, new() { public AgentKnowledge() { diff --git a/src/Agents/DecisionMakerType.cs b/src/Agents/DecisionMakerType.cs new file mode 100644 index 0000000..f721983 --- /dev/null +++ b/src/Agents/DecisionMakerType.cs @@ -0,0 +1,9 @@ +namespace Polonium.Agents; + +public enum DecisionMakerType +{ + None = 0, + Player = 1, + Computer = 2, + Global = 3, +} \ No newline at end of file diff --git a/src/Interfaces/ITimeConsumer.cs b/src/Interfaces/ITimeConsumer.cs new file mode 100644 index 0000000..4c5a3c9 --- /dev/null +++ b/src/Interfaces/ITimeConsumer.cs @@ -0,0 +1,6 @@ +namespace Polonium.Interfaces; + +public interface ITimeConsumer +{ + public void Process(double time); +} \ No newline at end of file diff --git a/src/PoloniumRegistry.cs b/src/PoloniumRegistry.cs index 5b775dc..9cfa8d2 100644 --- a/src/PoloniumRegistry.cs +++ b/src/PoloniumRegistry.cs @@ -1,5 +1,6 @@ using Godot; using Polonium.Agents; +using Polonium.Interfaces; using Polonium.Resources; using Polonium.Scenes; @@ -18,4 +19,8 @@ public class PoloniumRegistry DirAccess.MakeDirAbsolute("user://saves"); } public Dictionary Agents { get; set; } = new(); + + public HashSet TimeConsumers { get; set; } = new(); + public bool Paused { get; set; } + } \ No newline at end of file diff --git a/src/Scenes/RootScene.cs b/src/Scenes/RootScene.cs index 58f8f94..947ba8f 100644 --- a/src/Scenes/RootScene.cs +++ b/src/Scenes/RootScene.cs @@ -1,5 +1,6 @@ using Godot; using Polonium.Attributes; +using Polonium.Interfaces; namespace Polonium.Scenes; [ProxyNode] @@ -31,4 +32,13 @@ public partial class RootScene : Node2D Enter(); base._EnterTree(); } -} \ No newline at end of file + + public override void _Process(double delta) + { + if(!PoloniumRegistry.Instance.Paused) + foreach (ITimeConsumer tc in PoloniumRegistry.Instance.TimeConsumers) + tc.Process(delta); + base._Process(delta); + } +} +