Logo Platform
logo amplifiers simplified
Endless Space 2
Universe banner wording

ENDLESS™ Space 2 is turn-based 4X space-strategy that launches players into the space colonization age of different civilizations within the ENDLESS™ Universe. Your Vision. Their Future.

01 - How to create an AI mod

Reply
Copied to clipboard!
7 years ago
Jul 19, 2017, 3:04:05 PM


Tichau wrote:

When you activate the modding tools you will have access to special development tools in the game but it will decrease the game performance.

Will  --enablemoddingtools enable any additional features other than E.N.F.E.R (Such as the Shift+F1 Menu) ?


That menu in particular would be very useful to create particular circumstances to test how the AI reacts which are otherwise very hard to test. 


While it is currently possible to enable the menu editing the program memory, I think that it should be enabled in the AI Modding dedicated game build if not already so that all AI Modders can use it.


Looking forward to when the build arrives, I will be looking at the skeleton mod project in the meantime.

0Send private message
7 years ago
Jul 27, 2017, 7:51:55 AM
Stilgar wrote:

Thanks for the answers. I will create new topics next time.


For the build issue, it was using vscode, the change to do was in .vscode/task.json so its vscode specific.

We will fix this for the next release !


For the heuristic view, I get the same things as you but I through that we would usually get more information that just a base value (a list of component which modify the base value to get the final motivation). I tried to view the deetails of many motivation, some with lots of decimal so clearly been a computed value and not base values and this only got this base value = 0.15602373 (or something like that). In fact in the stream this is clearly shown. I am missing something?

No it's seem there is a problem in the build i will investigate !


0Send private message
7 years ago
Jul 26, 2017, 12:20:20 PM

Thanks for the answers. I will create new topics next time.


For the build issue, it was using vscode, the change to do was in .vscode/task.json so its vscode specific.


For the heuristic view, I get the same things as you but I through that we would usually get more information that just a base value (a list of component which modify the base value to get the final motivation). I tried to view the deetails of many motivation, some with lots of decimal so clearly been a computed value and not base values and this only got this base value = 0.15602373 (or something like that). In fact in the stream this is clearly shown. I am missing something?

0Send private message
7 years ago
Jul 26, 2017, 8:12:35 AM
Stilgar wrote:

After playing a little with the modding version, I have a few questions (Not sure if posting everything here is the best way, should I create specific topics?):

Maybe a topic by question is more simple to close discution when finish, and help other to search if the same problem occur.



* I am not able to get the heuristic information on the decision. I started a new game and imediatly checked the enable heuristic checkbox and still nothing. even after several turns, on decision which appeared after I checked the box I don't have the details. the box state is saved since if I reopen the page, it stay checked. What I am missing?

i do a test with the current build and after i check the box, when i clicked it's work





* with the debug menu, is there a way to reveal the whole galaxy without giving this information to the currently active empire? I found the empire switch so its ok, but this could still be useful.

The reaveal galaxy is by empire, and give the the vision to one empire, you can have one empire assign just for the vision for test purpose


* Is it normal that the game/ai only use between 20 and 30% of my cpu (on a ryzen 1600x so 6cores/12threads)? the decision counter in enfer debug tool only goes up about one decision per second which seems slow...

For the moment there is one thread assigned for the AI, so the CPU seem normal,  in order to increase this limit there some dev to do in our side to ensure that all the system is fully thread safe.

Maybe we rise the number of thread for the future if this was mandatory



* How often are decision generated/updated? it seems not very often, is there some kind of trigger? any way to control this?

We do 4 full decision by turn, and one more by gameplay event (click, fleet movement, battle, notification ....)


* Can we add/replace analysis? for example to tweak the Computestrategicstock & resourceneed one?

Yes , you can, if you open the EndlessWar example project, the ForceNemesis job override the ComputeBestEnemy job, 

You just need wait the job you want enriched, and do what you want to the desired value !


* Note: I had this build error on both examples:


MSBUILD : error MSB1009: Project file does not exist.

Switch: Amplitude.AI.Core\Amplitude.AI.Core.csproj


I had to change the name of the project in the task.json to the correct one (like "Sources\\AIModEndlessWar.csproj") this should probably be fixed to help other to start :)

Are you in visual studio code, or visual studio ?



* I saw that we can create new fleet behavior with a nice looking decision tree. Nothing preventing us to use that right?

No you can, you have just to create a FleetMissionTask linked to the created FleetMission that handle your behavior tree !

there is no limitation ! 


* have you tried to compare AI before and after changes by having them battle? like half of the player using the original and the other half the modified one? Any recommended way to do that? for new generator, it easy enough to disable them conditionally in the getcontexts for example, but is there a way to conditional disable existing generator?

For the moment we dont have this kind of feature. we dont have different version of generator for the moment.

But we have some conditional generator by faction in order to specialize AI by faction or personality.


 


0Send private message
7 years ago
Jul 25, 2017, 8:39:28 PM

After playing a little with the modding version, I have a few questions (Not sure if posting everything here is the best way, should I create specific topics?):


* I am not able to get the heuristic information on the decision. I started a new game and imediatly checked the enable heuristic checkbox and still nothing. even after several turns, on decision which appeared after I checked the box I don't have the details. the box state is saved since if I reopen the page, it stay checked. What I am missing?


* with the debug menu, is there a way to reveal the whole galaxy without giving this information to the currently active empire? I found the empire switch so its ok, but this could still be useful.


* Is it normal that the game/ai only use between 20 and 30% of my cpu (on a ryzen 1600x so 6cores/12threads)? the decision counter in enfer debug tool only goes up about one decision per second which seems slow...

* How often are decision generated/updated? it seems not very often, is there some kind of trigger? any way to control this?


* Can we add/replace analysis? for example to tweak the Computestrategicstock & resourceneed one?


* Note: I had this build error on both examples:


MSBUILD : error MSB1009: Project file does not exist.

Switch: Amplitude.AI.Core\Amplitude.AI.Core.csproj


I had to change the name of the project in the task.json to the correct one (like "Sources\\AIModEndlessWar.csproj") this should probably be fixed to help other to start :)



* I saw that we can create new fleet behavior with a nice looking decision tree. Nothing preventing us to use that right?


* have you tried to compare AI before and after changes by having them battle? like half of the player using the original and the other half the modified one? Any recommended way to do that? for new generator, it easy enough to disable them conditionally in the getcontexts for example, but is there a way to conditional disable existing generator?

Updated 7 years ago.
0Send private message
7 years ago
Jul 21, 2017, 7:58:43 AM
bnspalding wrote:


Really looking forward to reading more documentation. Looking over the example code provided, I'm not at all certain where the hooks are for communicating information outward to the player. Are there ways to trigger pop-up communication with arbitrary text (to, for example, add more faction-specific dialogue that can communicate AI state to the player in a diegetic fashion)? I would love to see a section of documentation dedicated to explaining the different tools available for this type of state communication.



Also, hello everyone!

When will provide a complete AI mod with the documentation in order to have some concrete example!


For do some new popup, there a mood message system (you must just create a MoodMessageTask), but you must mod the localization files too to have the text in all language.



0Send private message
7 years ago
Jul 21, 2017, 7:50:53 AM

I Stilgar,

Stilgar wrote:

Ok thanks for the quick answer.


So if I understand correctly, if we have several contexts or parents for a decision, we could call ContinueDecision several time in the same call of GetContexts/GetParents. GenerateDecision would them be called several time allowing to return either the same task/goal for all pairs of context, parent or to use different ones. I suppose that all the pair context, parent that return the same task will have their local contribution summed (otherwise how to you generate a task with several parent?)).

In addition ContinueDecision can probably be called several time in GenerateDecision to to general several tasks/goal for the same pairs of context, parent?


I don't really understand why ComputeLocalMotivation is not done directly in GenerateDecision with the local motivation passed to ContinueDecision so I must be missing something.



You understand right !

when you create a generator you choose the type of context a goal, and create taks or goal for each pair ! or multiple if you want do different tasks.


for the ComputeLocalMotivation we decide to separate the creation of the task to this motivation computation for reason of readability and to separate the task creation and the task motivation computation.


when the two are complicated, we mix two algorithms in one, with the separation, it is more simple to read, the motivation that you see in E.N.F.E.R is in ComputeLocalMotivation


0Send private message
7 years ago
Jul 21, 2017, 1:06:52 AM
zBobiwan wrote:


We are working to produce a general documentation about the AI system today or tomorow.

This documention will explain all our main concepts, and we will be here to help when you have specifics questions.

Really looking forward to reading more documentation. Looking over the example code provided, I'm not at all certain where the hooks are for communicating information outward to the player. Are there ways to trigger pop-up communication with arbitrary text (to, for example, add more faction-specific dialogue that can communicate AI state to the player in a diegetic fashion)? I would love to see a section of documentation dedicated to explaining the different tools available for this type of state communication.


Also, hello everyone!

Updated 7 years ago.
0Send private message
7 years ago
Jul 20, 2017, 4:00:52 PM

Ok thanks for the quick answer.


So if I understand correctly, if we have several contexts or parents for a decision, we could call ContinueDecision several time in the same call of GetContexts/GetParents. GenerateDecision would them be called several time allowing to return either the same task/goal for all pairs of context, parent or to use different ones. I suppose that all the pair context, parent that return the same task will have their local contribution summed (otherwise how to you generate a task with several parent?)).

In addition ContinueDecision can probably be called several time in GenerateDecision to to general several tasks/goal for the same pairs of context, parent?


I don't really understand why ComputeLocalMotivation is not done directly in GenerateDecision with the local motivation passed to ContinueDecision so I must be missing something.



0Send private message
7 years ago
Jul 20, 2017, 8:13:40 AM

Hi Stilgar,


We are working to produce a general documentation about the AI system today or tomorow.

This documention will explain all our main concepts, and we will be here to help when you have specifics questions.


About your questions:

1) Generators allow to create a decision (a task or a goal), for a a given context and a given parent


In each generator the ContinueDecision allow to pass in the next step of the generator, 

in most cases the step are :

* 1st step : GetContexts -> ContinueDecision(AIPlayer, Context)  (only in context based generator not in root generator)

* 2nd step : GetParents (call for each contexts) -> ContinueDecision(AIPlayer, Context, Parent)

* 3rd step : GenerateDecision (call for each pair context, parent) -> ContinueDecision(AIPlayer, this.GetGenerationData(Context, Parent, Task)

* 4th step : ComputeLocalMotivation (call for each tuple context, parent, task)

 

2) The generators are stateless (multithread purpose) , but you can store some informations in the task (or goal) created or you prepare the data before in the strategic data (in strategic jobs). 


3) There are not computation quota, but for big computation, we can say that we want to compute data only in start of turn for exemple

in all our IntelligenceJob you can override this method :


protected virtual bool MustCompute()
{
return true;
}

by (for exemple) :


protected override bool MustCompute()
{
return this.IsNewTurnComputation();
}

Thanks for your comment.

0Send private message
7 years ago
Jul 19, 2017, 11:03:49 PM

If your writing about possible issues with build, you may want to mention that .Net Framework 3.5 should be installed/enabled (although the error messages would be quite clear)


In case people are wondering how to do this, For Win10:

1) Go to Control Panel Then Uninstall a Program

2) Then Select Turn Windows Features on and off (its on the left, See below)

3) Click the .Net Framework 3.5 check box so that it is not blank and press ok (as shown below)

4) If given the option to donwload the files pick it.

5) After a short period of time it should be done.




Stillgar by the sounds of it they will be releasing a Doc sometime soon.

We will make a special documentation about how to use this tool and improve the overall AI modding documentation as soon as we can.

0Send private message
7 years ago
Jul 19, 2017, 9:25:25 PM

Hi Tichau,


Do you plan to release some API documentation? I started looking at your dll with ilspy and based on the existing AI code can probably work it out myself, but having access to your generated api doc would probably speed things up a lot (I suppose that you document your api right :) ?)


I already have two questions:

* what does this ContinueDecision do?

* should the generator be stateless or can we store some data in there or somewhere? at least cached data (which can be recreated on reload) if not persistent one? and what is the lifecycle of those classes?

* Is there some kind of computation quota, meaning that while ai turn should not be too long but if we have some free time, why not use it so we could adjust the amount of computation we do? Also spreading long term strategic compuation over several turns?


Maybe you could also write down (or do a stream video if faster for you) to present the main concepts (generator, strategy, goal, task, snapshot, generation data...), important classes and how the AI is executed?


I know that any doc or stuff take times and you are already doing a lot to support the mod community which I appreciate, but I am greedy :)?  In the mean time, I will watch the enfer stream video again, read the ai debug guide and read the code in the AI dll.


Oh and I forgot to say: Good Work! It really seems like you gave us full control over the AI on top of a very flexible and composable system which is really nice! 

0Send private message
7 years ago
Jul 19, 2017, 4:53:11 PM

There no hard restrictions on what can be enabled. Effectively, it will increase chances of errors if you enable a lot of Ai mods. 


You can also make overall mods, you just have to deactivate all generators (use wildcard *), then you can write your own ai.

0Send private message
7 years ago
Jul 19, 2017, 4:05:30 PM

What is the expected compatibility between AI Mods?


Now this is written assuming this modding system will work in a similar way to the current one of being able to make changes to existing "things" by overwriting them or add new ones, is this the case?


Is only one AI mod allowed to be enabled at a time? (Like Overhaul mods)

Or can only AI mods that modify different areas be allowed to be simultaneously enabled?

Or is there no hard restrictions on what can be enabled? (Only increased chances of errors & Issues)

0Send private message
7 years ago
Jul 19, 2017, 3:55:30 PM

EDIT: I added a mod example (made by zBobiwan) that is focus on AI making war to the human player (in an unfair way :) ). 


This will help you to understand how to create or override AI behaviors.

0Send private message
7 years ago
Jul 19, 2017, 3:39:19 PM

EDIT: I have updated the sample project and the build section of this tutorial.

0Send private message
7 years ago
Jul 19, 2017, 3:39:09 PM

The ENFER AI DEBUG TOOLS is partially correct ^^ (some changes have been made since). I will add a more advanced guide in this section of the forum and will improve it with you when problems will be encountered.

0Send private message
0Send private message
7 years ago
Jul 19, 2017, 3:14:38 PM

Hello!


Yes! the Shift+F1 menu, the empire switch (hitting numbers on the keyboard) will be activated (alongside ENFER) with --enablemoddingtools so you can have the best environment possible to develop tools.

0Send private message
7 years ago
Jun 20, 2017, 10:05:53 AM

[This post is originally from the AI Modding closed beta. We have moved it here along with the questions and answers our testers had, just in case you'd like to give it a try too!]




In order to create an AI mod, you need to create an additional C# dll that will be loaded into the AI brain. Here is the information to help you do that.

We currently support two code editors but you can use any editor you want (you can see the build commands in the .vscode/tasks.json file).



Install the development environment


Using Visual Studio

  1. Download and install Visual Studio Community [link].
  2. Download and install Visual Studio Tools for Unity in order to compile your code with assembly settings compatible with Unity [link]


Using Visual Studio Code

  1. Download and install Visual Studio Code [link].
  2. Download and install MSBuild in order to compile your code [link].
  3. Download and install Visual Studio Tools for Unity in order to compile your code with assembly settings compatible with Unity [link].
  4. Download and install the .NET Core SDK for command line [link].



Create an AI mod skeleton


Here is a skeleton mod project: ExampleAI.zip.

Download it and extract it in the Endless Space 2 community folder, My Documents/Endless Space 2/Community (create this folder if it does not exists).



Configure the mod meta information


All the information about your mod is stored in what we called a runtime module. This data are stored in an XML file in the root of your mod directory (in this example ExampleAI.xml).

You can configure the name, the description, etc ... of your mod.

Add the AI tag to help the player know what your mod modify (available tags are: AI, Art, Buildings, Gameplay, Improvements, MajorFactions, Maps, MinorFactions, Multiplayer, Other, Resources, Technologies, Units).

Then, in the Plugins part, you need to describe what the game needs to load in your mod.



Build the mod


For visual studio users

  • You can find the visual studio project that allows you to build the AIModSampleProject.dll in the folder Sources/AIModSampleProject.sln.
  • Open it and click on Build -> Build Solution. The code will be built and the resulting dll will be copied in the `AI` folder.


For visual studio code users

  • Open the mod root folder (the folder that contains the `.vscode` folder). 
  • Open a c# file (*.cs) in the `Sources/Project` folder. VS Code will automatically found the solution (you can see `Running` and then the Solution name `AISampleModProject.sln` in the bottom right corner).
  • Then you need to verify that the build task is correctly configured. Open the file `.vscode/tasks.json` and verify the **"command"** property is correct (which should be if you have installed MSBuild in the default repository).
  • Then you can build the dll using the build task (CTRL + SHIFT + B by default). To run other tasks hit CTRL + SHIFT + P and enter "run task" you can then choose the task you want to run.

Issues you can encounter with build


You may have this error when you try to build the mod:

------ Build started: Project: AIModSampleProject, Configuration: Release Any CPU ------
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Amplitude.AI.Common". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Amplitude.AI.Core". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.


This means the references to the AI dlls are not correct. By default it search Endless Space 2 in this folder: C:\Program Files (x86)\Steam\steamapps\common\.

If you have installed Endless Space 2 in another folder, you need to change the dll referencing.

  • Open AIModSampleProject.csproj with a text editor (it's an XML file).
  • Look for the dll references (line 35 and 38 for the sample mod).
  • Change the paths according to your steamApps folder.


Development tools


Now that your mod can be loaded in the game using the modding interface, you want to see if your code is correct. 

We have developed a powerfull tool to develop the AI, to be able to access it, you need to launch Endless Space 2 in a special configuration.

To do so, add the --enablemoddingtools launch option in steam:

  • Right click on Endless Space 2 (in steam) and open the Properties panel.
  • Click on the  Set Launch Options... button.
  • Enter the --enablemoddingtools option.


When you activate the modding tools you will have access to special development tools in the game but it will decrease the game performance.

Launch a game with your mod activated then open a web browser and enter the following address: http://localhost:4377.


You should see the following interface



Mod example


Here is a mod example where all AIs try to go to war against the first player, keep cold war or better between AIs and try to attack all fleets of the first player: EndlessWar.




You are now able to create an AI mod and access to the debugger to test it. 

We will make a special documentation about how to use this tool and improve the overall AI modding documentation as soon as we can.

Don't hesitate to ask questions.


Updated 6 years ago.
0Send private message
?

Click here to login

Reply
Comment
0Send private message