New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I create a New AI Bot? #14693

Open
MS07112 opened this Issue Jan 8, 2018 · 12 comments

Comments

Projects
None yet
5 participants
@MS07112

MS07112 commented Jan 8, 2018

I have looked through the HackyAI and DummyAI files and the Wiki pages, but I don't know how to go about creating my own Custom AI (and I'm NOT referring to tweaking the AI.yaml file). As I want to design and work with my own AI 'Bot'. I have already worked with C++ bots for the Starcraft BWAPI, but my heart has always been with C&C :) .

Can someone tell me how HackyAI actually gets loaded into OpenRA as a type of player, as I want to try and see if I can route my code into the Game's Player/AI selector screen that way.

Thank you.

@MS07112 MS07112 changed the title from How can I create a New AI Engine? to How can I create a New AI Bot? Jan 8, 2018

@pchote

This comment has been minimized.

Show comment
Hide comment
@pchote

pchote Jan 8, 2018

Member

Almost all game logic in OpenRA is implemented using "traits" defined on an actor.

The AI is just a trait on a player actor that implements the IBot interface (with a corresponding TraitInfo class that inherits IBotInfo). These interfaces are what exposes the AI to the lobby and what allows the game engine to enable the bot on appropriate players.

Member

pchote commented Jan 8, 2018

Almost all game logic in OpenRA is implemented using "traits" defined on an actor.

The AI is just a trait on a player actor that implements the IBot interface (with a corresponding TraitInfo class that inherits IBotInfo). These interfaces are what exposes the AI to the lobby and what allows the game engine to enable the bot on appropriate players.

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Thank you very much for the help!! I absolutely appreciate it!

MS07112 commented Jan 8, 2018

Thank you very much for the help!! I absolutely appreciate it!

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Also, if I am writing the bot in a project folder that is separate from the OpenRA.Mods.Common project (although still within the OpenRA.sln solution file): would I need to add or do anything for it to be inside the game's search path in order for it to be located?

MS07112 commented Jan 8, 2018

Also, if I am writing the bot in a project folder that is separate from the OpenRA.Mods.Common project (although still within the OpenRA.sln solution file): would I need to add or do anything for it to be inside the game's search path in order for it to be located?

@Phrohdoh

This comment has been minimized.

Show comment
Hide comment
@Phrohdoh

Phrohdoh Jan 8, 2018

Member

Your assembly needs to be added to the Assemblies list in the mod.yaml.

See RA's manifest as an example:

OpenRA/mods/ra/mod.yaml

Lines 77 to 79 in d4f7d66

Assemblies:
common|OpenRA.Mods.Common.dll
common|OpenRA.Mods.Cnc.dll

If your assembly were named OpenRA.Mods.MS07112 you would have the following

Assemblies:
	common|OpenRA.Mods.Common.dll
	common|OpenRA.Mods.Cnc.dll
	common|OpenRA.Mods.MS07112.dll

assuming your assembly is being written (or copied) out to the mods/common/ directory.

See this wiki page for more information.

Member

Phrohdoh commented Jan 8, 2018

Your assembly needs to be added to the Assemblies list in the mod.yaml.

See RA's manifest as an example:

OpenRA/mods/ra/mod.yaml

Lines 77 to 79 in d4f7d66

Assemblies:
common|OpenRA.Mods.Common.dll
common|OpenRA.Mods.Cnc.dll

If your assembly were named OpenRA.Mods.MS07112 you would have the following

Assemblies:
	common|OpenRA.Mods.Common.dll
	common|OpenRA.Mods.Cnc.dll
	common|OpenRA.Mods.MS07112.dll

assuming your assembly is being written (or copied) out to the mods/common/ directory.

See this wiki page for more information.

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Alright, I just added the project (being compiled as a Library) to the mods.yaml file, but I keep getting this error message when I try to run OpenRA:

System.IO.FileNotFoundException: Could not load file or assembly '/home/mike/OpenRA/OpenRA.Platforms.Default.dll' or one of its dependencies
File name: '/home/mike/OpenRA/OpenRA.Platforms.Default.dll'
  at (wrapper managed-to-native) System.Reflection.Assembly:LoadFrom (string,bool)
  at System.Reflection.Assembly.LoadFrom (System.String assemblyFile, System.Security.Policy.Evidence securityEvidence) [0x00000] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:551 
  at System.Reflection.Assembly.LoadFile (System.String path, System.Security.Policy.Evidence securityEvidence) [0x00031] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:588 
  at System.Reflection.Assembly.LoadFile (System.String path) [0x00000] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:593 
  at OpenRA.Game.Initialize (OpenRA.Arguments args) [0x0019d] in /home/mike/OpenRA/OpenRA.Game/Game.cs:294 

The whole Solution builds without issue, but it keeps saying that the OpenRA.Platforms.Default.dll or one of its dependencies couldn't be found.

MS07112 commented Jan 8, 2018

Alright, I just added the project (being compiled as a Library) to the mods.yaml file, but I keep getting this error message when I try to run OpenRA:

System.IO.FileNotFoundException: Could not load file or assembly '/home/mike/OpenRA/OpenRA.Platforms.Default.dll' or one of its dependencies
File name: '/home/mike/OpenRA/OpenRA.Platforms.Default.dll'
  at (wrapper managed-to-native) System.Reflection.Assembly:LoadFrom (string,bool)
  at System.Reflection.Assembly.LoadFrom (System.String assemblyFile, System.Security.Policy.Evidence securityEvidence) [0x00000] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:551 
  at System.Reflection.Assembly.LoadFile (System.String path, System.Security.Policy.Evidence securityEvidence) [0x00031] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:588 
  at System.Reflection.Assembly.LoadFile (System.String path) [0x00000] in /build/mono-4.6.2.7+dfsg/mcs/class/corlib/System.Reflection/Assembly.cs:593 
  at OpenRA.Game.Initialize (OpenRA.Arguments args) [0x0019d] in /home/mike/OpenRA/OpenRA.Game/Game.cs:294 

The whole Solution builds without issue, but it keeps saying that the OpenRA.Platforms.Default.dll or one of its dependencies couldn't be found.

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Just revised the output path for the new AI's library to be the mods/common/ directory. The game now starts and runs, but the name of the AI, 'TestAI', doesn't show as a type of AI in the skirmish interface.

I copied the DummyAI.cs file to the project folder and renamed the DummyAI and DummyAIInfo titles to TestAI and TestAIInfo respectively:

using OpenRA.Traits;

namespace OpenRA.Mods.Common.AI
{
	public sealed class TestAIInfo : ITraitInfo, IBotInfo
	{
		[Desc("Human-readable name this bot uses.")]
		public readonly string Name = "TestAI";

		[FieldLoader.Require]
		[Desc("Internal id for this bot.")]
		public readonly string Type = "TestAI";

		string IBotInfo.Type { get { return Type; } }

		string IBotInfo.Name { get { return Name; } }

		public object Create(ActorInitializer init) { return new TestAI(this); }
	}

	public sealed class TestAI : IBot
	{
		readonly TestAIInfo info;
		public bool Enabled { get; private set; }

		public TestAI(TestAIInfo info)
		{
			this.info = info;
		}

		void IBot.Activate(Player p)
		{
			Enabled = true;
		}

		IBotInfo IBot.Info { get { return info; } }
	}
}

I'm a bit stumped on what to do now, as I'm currently running the RA mod.

MS07112 commented Jan 8, 2018

Just revised the output path for the new AI's library to be the mods/common/ directory. The game now starts and runs, but the name of the AI, 'TestAI', doesn't show as a type of AI in the skirmish interface.

I copied the DummyAI.cs file to the project folder and renamed the DummyAI and DummyAIInfo titles to TestAI and TestAIInfo respectively:

using OpenRA.Traits;

namespace OpenRA.Mods.Common.AI
{
	public sealed class TestAIInfo : ITraitInfo, IBotInfo
	{
		[Desc("Human-readable name this bot uses.")]
		public readonly string Name = "TestAI";

		[FieldLoader.Require]
		[Desc("Internal id for this bot.")]
		public readonly string Type = "TestAI";

		string IBotInfo.Type { get { return Type; } }

		string IBotInfo.Name { get { return Name; } }

		public object Create(ActorInitializer init) { return new TestAI(this); }
	}

	public sealed class TestAI : IBot
	{
		readonly TestAIInfo info;
		public bool Enabled { get; private set; }

		public TestAI(TestAIInfo info)
		{
			this.info = info;
		}

		void IBot.Activate(Player p)
		{
			Enabled = true;
		}

		IBotInfo IBot.Info { get { return info; } }
	}
}

I'm a bit stumped on what to do now, as I'm currently running the RA mod.

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Here's a screenshot of what I'm seeing right now:

openra_test_2018-01-08_16-04-27

MS07112 commented Jan 8, 2018

Here's a screenshot of what I'm seeing right now:

openra_test_2018-01-08_16-04-27

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Seeing as both the DummyAI and HackyAI files have null as their default Type values: would I need to specify the name of the TestAI file in another .yaml file?

MS07112 commented Jan 8, 2018

Seeing as both the DummyAI and HackyAI files have null as their default Type values: would I need to specify the name of the TestAI file in another .yaml file?

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

YEEEEEEEESSSSSSS!!!!!!! I succeeded in getting the 'TestAI' title to show up in the selection interface, and was able to successfully run the skirmish session without anything going crazy.

What I did was edit the ai.yaml file under the mods/ra/rules/ directory by copying the RushAI's contents, but changed HackyAI@RushAI to TestAI@RushAI as well as the Name and Type fields:

testai_yaml_2018-01-08_16-19-56

Currently the AI is doing what it should be doing: nothing. As the MCV just sits where it does (beautiful <3 ).

This information should definitely be turned into a Wiki page for anyone wanting to drop in their own AI Bot.

Thanks again!!

MS07112 commented Jan 8, 2018

YEEEEEEEESSSSSSS!!!!!!! I succeeded in getting the 'TestAI' title to show up in the selection interface, and was able to successfully run the skirmish session without anything going crazy.

What I did was edit the ai.yaml file under the mods/ra/rules/ directory by copying the RushAI's contents, but changed HackyAI@RushAI to TestAI@RushAI as well as the Name and Type fields:

testai_yaml_2018-01-08_16-19-56

Currently the AI is doing what it should be doing: nothing. As the MCV just sits where it does (beautiful <3 ).

This information should definitely be turned into a Wiki page for anyone wanting to drop in their own AI Bot.

Thanks again!!

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Here's a screenshot of the TestAI as shown in the Skirmish Lobby:

testai_selection_2018-01-08_16-28-25

MS07112 commented Jan 8, 2018

Here's a screenshot of the TestAI as shown in the Skirmish Lobby:

testai_selection_2018-01-08_16-28-25

@MS07112

This comment has been minimized.

Show comment
Hide comment
@MS07112

MS07112 Jan 8, 2018

Also: here's a UML Diagram to help others in visualizing what needs to be done to replicate this task (labels have been changed to 'TestAI' for the .cs and .dll files):

image

MS07112 commented Jan 8, 2018

Also: here's a UML Diagram to help others in visualizing what needs to be done to replicate this task (labels have been changed to 'TestAI' for the .cs and .dll files):

image

@StormWingDelta

This comment has been minimized.

Show comment
Hide comment
@StormWingDelta

StormWingDelta Jan 15, 2018

Also make a mental note the HackAI has a few useful functions so you don't have to build completely from scratch. :)

StormWingDelta commented Jan 15, 2018

Also make a mental note the HackAI has a few useful functions so you don't have to build completely from scratch. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment