Light Style© by Fisana

Jump to content


Photo

qBot (yet another AI)


  • Please log in to reply
244 replies to this topic

#1 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 21 September 2011 - 09:30 PM

Since 0 A.D. clearly doesn't have enough AI's I decided to make a new one. It is actually a fork of testbot, but has had some fairly large changes.

I have been working on it for about the last 1.5 weeks on and off (faster progress recently since it is making me excited). I decided to announce it now because I just got it to beat JuBot for the first time on Oasis (it may well not do this on other maps).

Key changes from testbot:

- Replaced the plan manager with a new queue system which is persistent.
--- This allows predictive resource priorities so the right stuff is gathered when needed.
--- Should lead to a more efficient AI in the future since plans are not discarded at the end of a turn.
--- Does fairer priority balancing, keeping an account of resources spent.

- Buildings are demand driven
--- Houses keep up with demand and don't waste wood by having too many
--- Farms will be replanted forever (well until the wood runs out)

- The military is currently a heavy work in progress.
--- Currently it builds several barracks then spams spearmen and javelinists until it has twice as many troops as the enemy (or 60 units), then walks up to their CC and lets the troops have fun :).
--- It now builds advanced units, and defence buildings. Also it defends against attacks.

More information

There is an overview of how qBot works at https://github.com/q...ucture-Overview

The Code
This resides on github.

https://github.com/quantumstate/qBot

Bug Reports
There is an issue tracker on github if you have/are willing to create and account there. Otherwise please contact me through the 0AD forums or irc.

NOTE: qBot requires a recent svn version of the game, it will not work with alpha 7

Edited by quantumstate, 14 October 2011 - 08:21 PM.

  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#2 Pureon

Pureon

    Primus Pilus

  • 0 A.D. Art Team
  • 3,655 posts

Posted 21 September 2011 - 10:24 PM

Tested and it works as described. Keep the updates coming! :)
  • 0

Pureon
0 A.D. Part time Designer / Texturer / 3D Artist
Contact email:
pureon{@}wildfiregames.com


#3 gudo

gudo

    Duplicarius

  • Community Members
  • PipPipPip
  • 239 posts

Posted 23 September 2011 - 04:41 AM

Nice looking bot you got there. I did some testing and it plays well. I would slightly lower the priority on food and slightly raise it for wood though. On the tests that I did with it, qBot stocked tons of food but was consistently bottle-necked by wood shortages.

As far as non-trivial changes go though, I found that placing a mill and farmstead (on the line between your civ center and your opponent's, roughly 40-45 tiles away from your own) gave the AI quite the boost, more-so than using your citizen soldiers to gather. Sure, it's not the most intelligent way to place a mill, but it's better than Jubot's method and certainly better than nothing. No clue how you'd do that though.

Speaking of Citizen soliders, I've been poking around in the code and I think I've found a way to get them to gather and build too. I'll give it a shot over the weekend and post a patch on the off-chance I get it working.

Again, nice bot. :) Keep up the development!
  • 0
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot

#4 JuliusColtranePille

JuliusColtranePille

    Sesquiplicarius

  • Donator
  • 129 posts

Posted 23 September 2011 - 09:39 AM

great to hear that guys!

can't wait to get finally a bot which is really hard to match!

regards,
claas
  • 0
"Jazz means Freedom."

Miles Davis

#5 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 23 September 2011 - 11:54 AM

Thanks for the comments, at this early stage my planned improvement list seems to be pretty large, quite a few are "architectural" things which makes it hard to figure how much improvement they will give initially but should help later on.

Nice looking bot you got there. I did some testing and it plays well. I would slightly lower the priority on food and slightly raise it for wood though. On the tests that I did with it, qBot stocked tons of food but was consistently bottle-necked by wood shortages.


Yes this is a problem in the predictive system because houses and barracks get put into the queue just before they are needed so the prediction code can't see them far in advance. This is compounded by the economic manager never reassigning villagers. I plan to fix both of these problems fairly soon by rewriting the futureNeeds function and implementing the villager reassignment (I just need to make sure the villagers aren't being reassigned constantly wasting loads of time walking between places).

As far as non-trivial changes go though, I found that placing a mill and farmstead (on the line between your civ center and your opponent's, roughly 40-45 tiles away from your own) gave the AI quite the boost, more-so than using your citizen soldiers to gather. Sure, it's not the most intelligent way to place a mill, but it's better than Jubot's method and certainly better than nothing. No clue how you'd do that though.


This sounds like a pretty map dependent fix, I would prefer to have a better system. The jubot approach should be better in principle, I haven't looked in detail at how it works though. I don't think it is worth spending time figuring out how to do your suggestion when it will be replaced later.

Speaking of Citizen soliders, I've been poking around in the code and I think I've found a way to get them to gather and build too. I'll give it a shot over the weekend and post a patch on the off-chance I get it working.


The main complication for this is sorting out how to juggle them between the economic and military managers. I think generally the military manager should have priority and will be able to use the citizen soldiers whenever it wants them. The military manager is still is a state of flux so it might be best to leave this at the current time until it stabilises, otherwise the changes may get out of date very fast. The villager reassignment issue will also affect this.

It would be great if you do want to work on patches, it is just that I don't think that this area is a good one to look at currently, unless you plan on broader changes to the current role system.
  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#6 gudo

gudo

    Duplicarius

  • Community Members
  • PipPipPip
  • 239 posts

Posted 23 September 2011 - 02:41 PM

This sounds like a pretty map dependent fix, I would prefer to have a better system. The jubot approach should be better in principle, I haven't looked in detail at how it works though. I don't think it is worth spending time figuring out how to do your suggestion when it will be replaced later.

Yeah, it really is pretty dumb, I wouldn't waste time on it either.

The main complication for this is sorting out how to juggle them between the economic and military managers. I think generally the military manager should have priority and will be able to use the citizen soldiers whenever it wants them. The military manager is still is a state of flux so it might be best to leave this at the current time until it stabilizes, otherwise the changes may get out of date very fast. The villager reassignment issue will also affect this.


Well, the basic idea is to spawn citizen soliders with the "worker" role. The AI should then treat them just like women. However, we'll give them a new metadata class "canattack" and start if off with "yes". The military manager will be looking for units with "canattack" == "yes" and once it finds enough, will sort them into a squad, change the role from worker to solider, clear out the subrole, and set canattack to "isattacking". Later, when the military manager is done with them, we can have it reset the units role to worker, and change canattack back to "yes". For the short term though, there should be a way for the economy manager to find idle workers and change their role to worker.

This way, citizen soldiers spawn as workers, and can be re-tasked by the military manager. When they go idle, we re-task them again as workers. Once re-assignement issues get fixed, we can remove the code that makes them workers.

There's still a bit of work to do to see if it's even do-able, but I can't see why it wouldn't work.

Edited by gudo, 23 September 2011 - 02:45 PM.

  • 0
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot

#7 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 23 September 2011 - 03:34 PM

Well, the basic idea is to spawn citizen soliders with the "worker" role. The AI should then treat them just like women. However, we'll give them a new metadata class "canattack" and start if off with "yes". The military manager will be looking for units with "canattack" == "yes" and once it finds enough, will sort them into a squad, change the role from worker to solider, clear out the subrole, and set canattack to "isattacking". Later, when the military manager is done with them, we can have it reset the units role to worker, and change canattack back to "yes". For the short term though, there should be a way for the economy manager to find idle workers and change their role to worker.

This way, citizen soldiers spawn as workers, and can be re-tasked by the military manager. When they go idle, we re-task them again as workers. Once re-assignement issues get fixed, we can remove the code that makes them workers.

There's still a bit of work to do to see if it's even do-able, but I can't see why it wouldn't work.


That sounds pretty good in general. I will hold off doing this at the moment because of the lacking defence logic. Currently the defence works by letting the idle soldiers attack when the enemy gets within the radius (this is unitAI code). So setting them to become workers automatically would mean that there would be no defence at all with the current AI, the attackers would gradually slaughter them 1 by 1. But once incoming enemies can be spotted this would be good.

Also I have just commited a change to the resource predictions. From a quick test it seems to be allocating them a bit better and it should cope better in the future.
  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#8 UV_Completion

UV_Completion

    Discens

  • Community Members
  • Pip
  • 16 posts

Posted 23 September 2011 - 07:55 PM

I tried your Bot in a random map and it put up a lot more resistance than JuBot, nice work!

The only obvious flaw I could spot is that it builds an insane amount of units before it attacks which hurts performance a lot (it may be that not all of its attacks are that huge because I played with more than one qBot and they probably attacked each other earlier in the game). As I started an attack on its base it threw literally hundreds of infantry units at me, in the middle of an almost equal number of females. I didn't check the code but maybe you could lower the number of units it gathers before attacking a bit.. at least as long as the performance impact of large armies is so high.

Other things I noticed: One of the qBots tried to build a farmstead directly at my border (far away from its civ center). And the bot could probably build some defense towers, if only for aesthethic reasons. But I know that you just started working on it (and yet it's already quite impressive).

EDIT: Just had a brief look at the code and noticed this piece of code in military.js:
gameState.entities.forEach(function(ent) {
				if (ent.owner() === i && (ent.hasClass("CitizenSoldier") || ent.hasClass("Super"))){
					count ++;
				}
			});
And then he tries to build an army twice the size of the strongest enemy army.
I don't know Java script so I just assume that === does a comparison ;)
But if you play with more more than one qBot this code could probably lead to an arms race between the two qBots (which explains the fact that in my game the second qBot only attacked when I had reduced the army of the other one significantly).

Edited by UV_Completion, 23 September 2011 - 08:35 PM.

  • 0

#9 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 23 September 2011 - 08:40 PM

The only obvious flaw I could spot is that it builds an insane amount of units before it attacks which hurts performance a lot (it may be that not all of its attacks are that huge because I played with more than one qBot and they probably attacked each other earlier in the game). As I started an attack on its base it threw literally hundreds of infantry units at me, in the middle of an almost equal number of females. I didn't check the code but maybe you could lower the number of units it gathers before attacking a bit.. at least as long as the performance impact of large armies is so high.


Yes, this is because you have multiple qBots. The default attack behaviour currently is to wait until they have twice as many soldiers as the most powerful enemy. So they were just sitting because the other qBots would have matched the training rate. This is because I haven't got round to implementing most of the military module. I have set a new maxAttackSize=60 as a quick fix.

Other things I noticed: One of the qBots tried to build a farmstead directly at my border (far away from its civ center). And the bot could probably build some defense towers, if only for aesthethic reasons. But I know that you just started working on it (and yet it's already quite impressive).


That sounds strange, I haven't seen behaviour like that. The current building placement code is still from testbot and is due to be replaced though (sometime, there seems to be a lot of stuff to be replaced :)).

I think my idea of a really strong economic bot (lots of workers) is probably causing a lot of slowdown as well. I have lowered the max number of gatherers a bit for now.

Edit: You are indeed correct in your edit.

Edited by quantumstate, 23 September 2011 - 08:41 PM.

  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#10 Jubalbarca

Jubalbarca

    Sesquiplicarius

  • WFG Retired
  • 127 posts

Posted 24 September 2011 - 01:15 PM

Speaking of arms races, expect a new version of JuBot pretty soon as well. :P
  • 0

Sig_axe.jpg


#11 WhiteTreePaladin

WhiteTreePaladin

    Primus Pilus

  • WFG Retired
  • 1,665 posts

Posted 24 September 2011 - 02:16 PM

Ah, nice. Looking forward to both of them. :)
  • 0

Brian [aka WhiteTreePaladin]

0 A.D. Gameplay and UI Developer


#12 gudo

gudo

    Duplicarius

  • Community Members
  • PipPipPip
  • 239 posts

Posted 24 September 2011 - 04:31 PM

Nice changes to Jubot there Jubal :P I just ran some tests with qBot and Jubot. Jubot certainly has an early advantage, but I couldn't seem to induce it to attack... I haven't looked very hard at the code though so I'm quite sure what Jubot looks for before starting to attack.

As far as qBot goes though, it got stuck. It tried to train lots and lots of Greek Calvary, but ran out of metal after just 10 units. qBot doesn't currently assign workers to mine for metal and it doesn't change it's plans when it runs out of resources. So it just sat around, not making anything till Jubot finally killed it.
  • 0
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot

#13 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 24 September 2011 - 06:13 PM

As far as qBot goes though, it got stuck. It tried to train lots and lots of Greek Calvary, but ran out of metal after just 10 units. qBot doesn't currently assign workers to mine for metal and it doesn't change it's plans when it runs out of resources. So it just sat around, not making anything till Jubot finally killed it.


Ah, thanks for this I had been wondering why it stopped training, that makes sense now. The reason is that the worker reallocation isn't written yet so by the time gold starts being needed by the dynamic resource demand system all the villagers are allocated to food or wood.
  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#14 Jubalbarca

Jubalbarca

    Sesquiplicarius

  • WFG Retired
  • 127 posts

Posted 24 September 2011 - 08:03 PM

Which faction was JuBot playing as, and how long did you leave it in which it didn't attack?
  • 0

Sig_axe.jpg


#15 quantumstate

quantumstate

    Primus Pilus

  • WFG Retired
  • 1,150 posts

Posted 25 September 2011 - 09:21 PM

I have pushed an update which reallocates workers occasionally and also fixes a divide by zero error in the resource priority code, the result is that it now works correctly and doesn't fatally run out of gold. Also I fixed a typo so the maxattacksize thing actually works now.
  • 0

Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#16 Pureon

Pureon

    Primus Pilus

  • 0 A.D. Art Team
  • 3,655 posts

Posted 26 September 2011 - 10:16 AM

Looking forward to your AI's military improvements. After you left IRC yesterday I tried out the updated qBot, and it did what you said it would.

As you well know, there are still quite a few improvements to make to its economy, most importantly making citizen-soldiers gather resources (and therefore stop blocking access to the cc for other gatherers). If you can make this AI as aggressive as you are in a multiplayer match, then I'll be very happy ;)
  • 0

Pureon
0 A.D. Part time Designer / Texturer / 3D Artist
Contact email:
pureon{@}wildfiregames.com


#17 gudo

gudo

    Duplicarius

  • Community Members
  • PipPipPip
  • 239 posts

Posted 30 September 2011 - 06:04 PM

Just discovered a serious flaw in the latest version of qBot. I set up a random map w/4 players in free for all. Me, SplitBot, JuBot, and qBot. Shortly after the match stared, qBot sent about 10-15 women across the map to go farm off of one of JuBot's farms. It was the nearest farm to them. I think the problem is that qBot doesn't check ownership of farms, and the game permits farming of enemy farms.

Needless to say, all the women were killed (nice defensive behavior form JuBot, and the farm was on the other side of a tower >_>)

Jubal take note, I also saw your bot do this.

Edited by gudo, 30 September 2011 - 06:28 PM.

  • 0
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot

#18 historic_bruno

historic_bruno

    Primus Pilus

  • WFG Programming Team
  • 2,485 posts

Posted 30 September 2011 - 06:21 PM

the game permits farming of enemy farms

Interesting, I guess we need to check that a farm (any resource?) is either player owned or gaia before gathering from it :)
  • 0
Ben Brian [ aka historic_bruno ]

Wildfire Games Programmer
Contact me: ben [at] wildfiregames [dot] com

#19 feneur

feneur

    Cartographer of imaginary worlds

  • 0 A.D. Project Leader
  • 7,963 posts

Posted 30 September 2011 - 08:56 PM

Or we could force players to defend their farms ;) It's no big deal either way for me, perhaps it's easier for the AIs to not have to check whether a farm is enemy/defended before farming, but apart from that people should mind where they build their farms/that they defend their farms :)
  • 0

Erik Johansson [ aka feneur ]

Wildfire Games
Contact me: feneur@wildfiregames.com



Support Wildfire Games!


#20 gudo

gudo

    Duplicarius

  • Community Members
  • PipPipPip
  • 239 posts

Posted 01 October 2011 - 12:31 AM

Heads up quantamstate, as of r10348, the farm thing is a non-issue. Also, IsSeaCreature has been renamed to just SeaCreature.
  • 0
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot