Author Topic: AI Script Idea - Autolearning Ability  (Read 4505 times)

eserlxl

  • Guest
AI Script Idea - Autolearning Ability
« on: 11 November 2008, 08:26:43 »
Here's the new AI script which gives the user to change AI behaviour without any coding or compiling. I will distriubte it and modified code soon, but now I wonder your comments.

Code: [Select]
#Ai Script for Glest by eserlxl

(The_format_is_important_for_now)
harvesterPercent 30
maxBuildRadius 60
minMinWarriors 7
maxMinWarriors 50
minStaticResources 10
minConsumableResources 20
maxExpansions 4
villageRadius 50
EMERGENCY_WORKERS 6
WORKER_COUNT0 12
WORKER_COUNT 10
WORKER_COUNT2 15
WORKER_RATIO1 0.2
WORKER_RATIO2 0.3
WARRIOR_COUNT 40
WARRIOR_RATIO1 0.2
WARRIOR_RATIO2 0.3
BUILDING_COUNT1 6
BUILDING_COUNT2 10
BUILDING_RATIO 0.2

These configurations can also be changed through the game. In other words, the AI can react to your capacity. AI strategy can be harder or easier according to your performance in the same game.
« Last Edit: 11 November 2008, 20:52:28 by eserlxl »

daniel.santos

  • Guest
Re: AI Script Idea
« Reply #1 on: 11 November 2008, 08:29:24 »
is this lua scripting?

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea
« Reply #2 on: 11 November 2008, 10:29:50 »
no its not lua

please tell us a bit more about your switches,
what are these switches for?

maxBuildRadius 60
minMinWarriors 7
maxMinWarriors 50
maxExpansions
villageRadius

And is there a switch for extended settlement? The cpu is very bad in exploring new castle/ressource places.
Will this be improved a bit and will there be a switch to effect this behaviour too?


Some more thoughts about the cpu settings:
I think these AI settings should be embedded into something xml-like, like all things in glest.
There should be some predefined and named AI settings in a special directory which should be selectable in the game setup menu.
Something like cpu-easy/cpu-medium/cpu-good/cpu-strong/cpu-ultra and you should be able to setup your own custom named cpu setting too.
Every cpu setting is in its own file.
The scenarios can select one of the defined cpu settings, but should they be able to setup their own cpu players too?
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

eserlxl

  • Guest
Re: AI Script Idea
« Reply #3 on: 11 November 2008, 10:49:09 »
Yes these parameters can be extended, these parameters are from ai.cpp and ai_rule.cpp. (I will distriubute the modified code after some cleaning/improving)

For example the modified part of the ai_rule.cpp :
Code: [Select]
//workers
if(workerCount<EMERGENCY_WORKERS+1) ai->addTask(new ProduceTask(ucWorker));
if(workerCount<WORKER_COUNT) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<WORKER_RATIO1) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<WORKER_RATIO2) ai->addTask(new ProduceTask(ucWorker));

//warriors
if(warriorCount<WARRIOR_COUNT) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<WARRIOR_RATIO1) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<WARRIOR_RATIO2) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=WORKER_COUNT) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=WORKER_COUNT2) ai->addTask(new ProduceTask(ucWarrior));

//buildings
if(buildingCount<BUILDING_COUNT1 || buildingRatio<BUILDING_RATIO) ai->addTask(new BuildTask());
if(buildingCount<BUILDING_COUNT2 && workerCount>WORKER_COUNT0) ai->addTask(new BuildTask());

//upgrades
if(upgradeCount==0 && workerCount>EMERGENCY_WORKERS) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>WORKER_COUNT) ai->addTask(new UpgradeTask());
if(upgradeCount==2 && workerCount>WORKER_COUNT2) ai->addTask(new UpgradeTask());
if(ai->isStableBase()) ai->addTask(new UpgradeTask());

The AI strategy script is in my own format, of course it can be changed.
« Last Edit: 11 November 2008, 20:22:31 by eserlxl »

eserlxl

  • Guest
Re: AI Script Idea
« Reply #4 on: 11 November 2008, 11:37:28 »
Quote
Some more thoughts about the cpu settings:
I think these AI settings should be embedded into something xml-like, like all things in glest.
There should be some predefined and named AI settings in a special directory which should be selectable in the game setup menu.
Something like cpu-easy/cpu-medium/cpu-good/cpu-strong/cpu-ultra and you should be able to setup your own custom named cpu setting too.
Every cpu setting is in its own file.
The scenarios can select one of the defined cpu settings, but should they be able to setup their own cpu players too?

You are right, I should translate it to xml. These configurations should be set from the game setup menu. Better than these different cpu settings, I have a different idea. There should be one cpu with the ai strategy initials(in the script) and this cpu can adjust itself according to the player's capacity. In other words, this cpu player can change the ai strategy initials through the game. If you are about to beat the cpu, you want to resume the game, but it is so late and you win, and the game ends. With the changable AI, there can be a balance between the player and cpu and therefore long and more enjoyable games.
 I think this option should be changed from the game setup menu.
« Last Edit: 11 November 2008, 20:19:22 by eserlxl »

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea
« Reply #5 on: 11 November 2008, 12:41:47 »
This kind of autolearning is really a great feature  :D ! I always loved it in games like ut2004 !

Nevertheless I would prefer some unchangable default cpu settings too.
This will make it possible to create an official online highscore table for single player scenarios one day.
Due to the problem with cross platform multiplayers and too little players for often multiplayer games this would be a nice feature for active glest players to compare with others. And this will be great for all those single player heros out there :) .

By the way, don't forget to distribute these cpu settings to the clients of a multiplayer game, or you stay with the default settings!
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

eserlxl

  • Guest
Re: AI Script Idea
« Reply #6 on: 11 November 2008, 20:35:02 »
Yes the right word is "aoutolearning" and the last AI configurations will be saved for the next game. Therefore, the next game AI will automatically adjust itself to the player's abilities. At the end, you will never say that "oh that's it, I can beat this AI or what a stupid AI". It's because, AI strategy changes everytime and you cannot predict the next strategy at any time.

I want to emphasize that this will be an extra future and it will be changed from the game setup menu(if I'll succes :)

I can't beat  a CPU-Ultra player with the given parameters at the top, this is impossible without rush. Usually rush doesn't work too :)

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea - Autolearning Ability
« Reply #7 on: 11 November 2008, 22:01:07 »
A very strong cpu is something nice for me and my boys, when playing together versus one cpu.
By the way, I hope you used the GAE code to start implementing, not the original glest code.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

eserlxl

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #8 on: 12 November 2008, 01:52:09 »
I started to change the original code, but if it is the wrong way, I will turn to GAE. Actually, I don't know very much.

The first test & results :

The Autolearning AI checks the balance between the CPU and the player for every 50 seconds
and changes his strategy to bring into balance the game.

To balance, I allow the AI to change only EMERGENCY_WORKERS & WARRIOR_COUNT parameters.

Gains:
Code: [Select]
int K1=2.1,K2=1.5; ///Gains for the balance, K1=CPU_unit/player's_unit , K2=player's_unit/CPU_unit
Conditions:
Code: [Select]
for(i=1;i<getFactionCount();i++){
if(unit_numbers[i]>unit_numbers[0]*K1){
if(WARRIOR_COUNT>8)WARRIOR_COUNT=WARRIOR_COUNT-1;
if(EMERGENCY_WORKERS>4)EMERGENCY_WORKERS=EMERGENCY_WORKERS-1;
}
else if(unit_numbers[i]*K2<unit_numbers[0]){
if(WARRIOR_COUNT<100)WARRIOR_COUNT=WARRIOR_COUNT+1;
if(EMERGENCY_WORKERS<10)EMERGENCY_WORKERS=EMERGENCY_WORKERS+1;
}
}

Original Script :

Code: [Select]
#Ai Script for Glest by eserlxl

(The_format_is_important_for_now)
harvesterPercent 30
maxBuildRadius 60
minMinWarriors 7
maxMinWarriors 50
minStaticResources 10
minConsumableResources 20
maxExpansions 4
villageRadius 50
[b]EMERGENCY_WORKERS 6[/b]
WORKER_COUNT0 12
WORKER_COUNT 10
WORKER_COUNT2 15
WORKER_RATIO1 0.2
WORKER_RATIO2 0.3
[b]WARRIOR_COUNT 40[/b]
WARRIOR_RATIO1 0.2
WARRIOR_RATIO2 0.3
BUILDING_COUNT1 6
BUILDING_COUNT2 10
BUILDING_RATIO 0.2

Result - Modified Script by AI
Code: [Select]
#Ai Script for Glest by eserlxl

(The_format_is_important_for_now)
harvesterPercent 30
maxBuildRadius 60
minMinWarriors 7
maxMinWarriors 50
minStaticResources 10
minConsumableResources 20
maxExpansions 4
villageRadius 50
[b]EMERGENCY_WORKERS 4.000000[/b]
WORKER_COUNT0 12.000000
WORKER_COUNT 10.000000
WORKER_COUNT2 15.000000
WORKER_RATIO1 0.200000
WORKER_RATIO2 0.300000
[b]WARRIOR_COUNT 23.000000[/b]
WARRIOR_RATIO1 0.200000
WARRIOR_RATIO2 0.300000
BUILDING_COUNT1 6.000000
BUILDING_COUNT2 10.000000
BUILDING_RATIO 0.200000

Better results can be obtained changing the parameters & gains.

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea - Autolearning Ability
« Reply #9 on: 12 November 2008, 08:14:33 »
You should really use the GAE code, because original glests authors have problems with code of other people and I think they will not include it into their svn.
Thats the reason why GAE project exists.
This is the homepage of GAE
http://glest.codemonger.org/home_page.php
svn:
https://glest.codemonger.org/svn/repos

There are several branches and so on, so you better contact daniel before you start implementing this in GAE
(daniels email is on the last line of this the homepage)
If you want more access ask daniel too, he is the boss :) .
----
AI updates every 50 seconds?
Why 50? I think its a good idea to make this time settable!
If you play another map, YOUR AI is probabaly too strong. So is it also possible for the AI to get more and more bad if this happens?

Please, don't add too much features at once. I think the settable cpu is enough for a first step. The autolearning cpu is the second step( for my opinion ).
for this settable AI you have to add:
- xml-files with embedded ai script
- 6? default ai setups
- changed game setup menu
- changed scenario structure
- changed multiplayer setup/start
and probabaly I forgot something else.
I think this change is really big enough for a first step! Try to get it stable and usable even for noobs and then go for the next step.
( GAE has no lua support yet, so this is something that has to be done before )
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

eserlxl

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #10 on: 12 November 2008, 10:58:42 »
I understand, thanks. But I have to do with myself first, if I succes then I will contact with daniel.

50 is a random nuber, it can be 10 or anything, it should be changed from the game setup menu.

If the checking time is 10 or less, I think the AI can adjust itself very quickly for any map. If limits are set to zero or near zero, then AI will do nothing.

Quote
Please, don't add too much features at once. I think the settable cpu is enough for a first step. The autolearning cpu is the second step( for my opinion ).
for this settable AI you have to add:
- xml-files with embedded ai script
- 6? default ai setups
- changed game setup menu
- changed scenario structure
- changed multiplayer setup/start

I agree with you in "changed game setup menu" and maybe "- changed multiplayer setup/start".
*If it is necessary I will change this short AI script into xml.

*There's no extra CPU settings, that's all, if you turn on Autolearning AI from game-setup menu, then AI tries to balance with you for single player, scenario and I suppose for multiplayer game. However if Autolearning AI is off then there's no change in the game. Therefore, there's no neccessity to change scenario structure and ai setups. The Autolearning AI is valid and the same manner with CPU and CPU_ULTRA for now(it can be changed also).

*In the game-setup menu, there will be a chance to choose "load original AI parameters".Then the game is completely same with the original game.

*To sum up, there are not much features, that's all. I don't think to put a settable cpu for now. Autolearning AI is enough for now. I have to test AI reactions to Autolearning AI then I will be able to put a stable version. But like all new ideas, this will be unstable for a long period.(tests, changes,code improvings etc.)

Why lua? I'm using C codes in C++ and this is valid and I can compile. I will contact daniel as soon as possible.

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea - Autolearning Ability
« Reply #11 on: 13 November 2008, 14:11:03 »
Lua scripting is for implementing scenarios. Its not made to modify glest.

Here is my idea for CPU-setups. It contains an example setup for the "normal cpu"
The contained directory should be placed in the glests root directory or probably in every techtree directory. Different CPU-setups for every techtree are nice, but for now a common ai_scripts folder in glest should be good enough.

What do you think of this, is this a good idea? Is it possible? Probabaly you get interested in the idea of settable cpu  ;D .
( the included image for every CPU-setup is just a gimmick for the GUI, you can remove it if you want)
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

eserlxl

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #12 on: 14 November 2008, 21:40:16 »
Yes, I like it very much, thank you for your work. As I said before, I need a testing process to improve Autolearning AI. The last tests show that there should be different CPU levels, but if we will prepare CPU levels for every tech tree, it needs a very long testing process for every faction,tech tree,cpu levels(total probability is the multiplication of all these combinations :).

 The gains of decision :
Code: [Select]
int K1=2.1,K2=0.8; ///Gains for the balance, K1=CPU_unit/player's_unit , K2=player's_unit/CPU_unit

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI Script Idea - Autolearning Ability
« Reply #13 on: 11 December 2008, 17:50:02 »
we want more news  ;)
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: AI Script Idea - Autolearning Ability
« Reply #14 on: 17 December 2008, 15:51:32 »
... New AI Ultra?
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

modman

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #15 on: 21 December 2008, 03:28:13 »
This would be the CPU ultra.  Learning entire strategies is rare among games...the only one I know is Age of Empires.  It uses the strategy from the last game against you to try and counteract you.  Now if only our CPU would learn from all past played games!

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: AI Script Idea - Autolearning Ability
« Reply #16 on: 21 December 2008, 22:33:42 »
That would be sweet, but it could be countered by using a different strategy everytime...
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

mictes

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #17 on: 21 December 2008, 22:36:13 »
Just read this things and it would be ... AWESOME !

modman

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #18 on: 22 December 2008, 01:42:26 »
An example of a strategy is if I attack Tech with Magic Dragons, then it builds more Air Balistas the next time.

Idanwin

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #19 on: 23 December 2008, 15:54:54 »
It should be learning in the game itself.

AI sees lots of flying units, he will build some more AA.
AI discovers enemy has lots of AA, he will send a ground army to counter those, then send in his flying units afterwards.
And other such things.

~Idanwin
« Last Edit: 14 May 2009, 21:52:18 by Idanwin »

daniel.santos

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #20 on: 29 December 2008, 09:17:38 »
I guess the main thread for discussing this topic is http://http://glest.org/glest_board/viewtopic.php?f=15&t=3828.

Idanwin, I like your idea -- basically that the AI is more capable of calculating it's odds with various units and holding back the units that are bound for sure destruction (or at least holding them out of range).  I suppose this also goes along with ranged units attempting to hit their targets from max range and also fleeing when they are chased.  Either way, I wouldn't want this idea to get lost, thanks.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: AI Script Idea - Autolearning Ability
« Reply #21 on: 30 December 2008, 02:24:00 »
Yeah, how hard would it be to have the game look at the field the foe will be on and judge if they are prepared for that field?
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

modman

  • Guest
Re: AI Script Idea - Autolearning Ability
« Reply #22 on: 1 January 2009, 01:46:21 »
Kinda hard.

What happens when the units they see are faster than the first AI's units are?  Then all that happens when the first AI's units try to retreat is they are led back to the first AI's camp, which is bad especially if the AI is not prepared.

The logic should be that if the "scout" unit is slower and they are not prepared, fight the faster unit until dead.

This discussion needs to go in the "Better AI" topic ASAP.

 

anything