add: Agent, ProxyMethod, LoadingScene
This commit is contained in:
@@ -8,12 +8,12 @@
|
|||||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
<PackageId>Polonium</PackageId>
|
<PackageId>Polonium</PackageId>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Version>0.0.167-d</Version>
|
<Version>0.1.0</Version>
|
||||||
<Authors>Hangman</Authors>
|
<Authors>Hangman</Authors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="GodotSharp" Version="4.4.0-beta.3" />
|
<PackageReference Include="GodotSharp" Version="4.4.0-beta.3" />
|
||||||
<PackageReference Include="Polonium.Tasks" Version="0.0.92-d" />
|
<PackageReference Include="Polonium.Tasks" Version="0.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="GenerateProxyNodes" BeforeTargets="BeforeBuild">
|
<Target Name="GenerateProxyNodes" BeforeTargets="BeforeBuild">
|
||||||
<GenerateProxyNodesTask
|
<GenerateProxyNodesTask
|
||||||
|
|||||||
38
src/Agents/Agent.cs
Normal file
38
src/Agents/Agent.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
namespace Polonium.Agents;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class Agent
|
||||||
|
{
|
||||||
|
|
||||||
|
public string Name { get; init; }
|
||||||
|
|
||||||
|
public Agent(string name)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
PoloniumRegistry.Instance.Agents[name] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge> : Agent
|
||||||
|
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge>
|
||||||
|
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
|
||||||
|
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
|
||||||
|
{
|
||||||
|
|
||||||
|
private static int ComputerCount = 0;
|
||||||
|
public TAgentDecisionMaker DecisionMaker { get; init; }
|
||||||
|
public TAgentKnowledge Knowledge { get; init; }
|
||||||
|
|
||||||
|
|
||||||
|
public Agent() : base($"Computer {ComputerCount++}")
|
||||||
|
{
|
||||||
|
DecisionMaker = new TAgentDecisionMaker();
|
||||||
|
Knowledge = new TAgentKnowledge();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Agent(string name, TAgentDecisionMaker decisionMaker, TAgentKnowledge knowledge) : base(name)
|
||||||
|
{
|
||||||
|
DecisionMaker = decisionMaker;
|
||||||
|
Knowledge = knowledge;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/Agents/AgentDecisionMaker.cs
Normal file
28
src/Agents/AgentDecisionMaker.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace Polonium.Agents;
|
||||||
|
|
||||||
|
public abstract class AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>
|
||||||
|
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge>
|
||||||
|
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
|
||||||
|
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>, 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)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/Agents/AgentKnowledge.cs
Normal file
13
src/Agents/AgentKnowledge.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Polonium.Agents;
|
||||||
|
|
||||||
|
public abstract class AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>
|
||||||
|
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge>
|
||||||
|
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
|
||||||
|
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
|
||||||
|
{
|
||||||
|
public AgentKnowledge()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void Update(TAgentKnowledge newKnowledge);
|
||||||
|
}
|
||||||
6
src/Attributes/ProxyMethod.cs
Normal file
6
src/Attributes/ProxyMethod.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Polonium.Attributes;
|
||||||
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
|
public class ProxyMethod : Attribute
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Polonium.Agents;
|
||||||
using Polonium.Resources;
|
using Polonium.Resources;
|
||||||
using Polonium.Scenes;
|
using Polonium.Scenes;
|
||||||
|
|
||||||
@@ -16,4 +17,5 @@ public class PoloniumRegistry
|
|||||||
{
|
{
|
||||||
DirAccess.MakeDirAbsolute("user://saves");
|
DirAccess.MakeDirAbsolute("user://saves");
|
||||||
}
|
}
|
||||||
|
public Dictionary<string, Agent> Agents { get; set; } = new();
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using Godot;
|
|
||||||
using Polonium.DataStructures;
|
using Polonium.DataStructures;
|
||||||
using Polonium.Managers;
|
using Polonium.Managers;
|
||||||
|
|
||||||
namespace Polonium.Scenes;
|
namespace Polonium.Scenes;
|
||||||
|
|
||||||
public abstract partial class LoadingScene<T> : Scene
|
public abstract partial class LoadingScene<T> : Scene
|
||||||
where T : ProgressInfo
|
where T : ProgressInfo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,4 +20,15 @@ public partial class RootScene : Node2D
|
|||||||
PoloniumRegistry.Instance.RootScene = this;
|
PoloniumRegistry.Instance.RootScene = this;
|
||||||
base._Ready();
|
base._Ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ProxyMethod]
|
||||||
|
public virtual void Enter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _EnterTree()
|
||||||
|
{
|
||||||
|
Enter();
|
||||||
|
base._EnterTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Polonium.Attributes;
|
||||||
|
|
||||||
namespace Polonium.Scenes;
|
namespace Polonium.Scenes;
|
||||||
|
[ProxyNode]
|
||||||
public abstract partial class Scene : Node2D
|
public partial class Scene : Node2D
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user