EggPlant AI ramblings

For AI and campaign script related discussions and questions
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

How do I stop having ideas?

Post by aubergine »

@zydonk: thanks! i hope it works out for me too!

One of the problems I'm suffering currently is a severe case of 'too many ideas'.

For example, at 3AM this morning I woke up and started coding a target prediction AI, which required me to write a reconnaissance tracker first. The recon tracker basically keeps track of enemy units on the map - their current location and their previous location a few seconds ago. From this I hope to be able to determine what direction they are heading in, and at what speed. With that information I can then work out where they are heading towards (eg. one of my bases) and roughly how long it will take them to get there, and in turn guess at what their target might be. And, knowing what their target might be I can see if I have any free battle groups and if so choose the nearest one to intercept the enemy before they reach the target.

EDIT: Roadblock: I'd need to have access via JS API to the "continent" information about map tiles, and then be able to identify on-ramps and off-ramps from that continent to other continents. The 2P SkStartup map is a good example of why - enemy in top-left corner will often travel down the left side of the map (a narrow road through the hills) to bottom left corner, then along the bottom of the map to my base in the bottom-right corner. While the target prediction AI would become effective in the last stretch of the journey (as enemy travels from bottom-left to bottom-right) it would be reporting a lot of false information while the enemy travels down the left side of the map (from top-left to bottom-left).
Last edited by aubergine on 17 Jan 2012, 13:05, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Rman Virgil
Professional
Professional
Posts: 3812
Joined: 25 Sep 2006, 01:06
Location: USA

Re: How do I stop having ideas?

Post by Rman Virgil »

aubergine wrote:........

For example, at 3AM this morning I woke up and started coding a target prediction AI, which required me to write a reconnaissance tracker first. The recon tracker basically keeps track of enemy units on the map - their current location and their previous location a few seconds ago. From this I hope to be able to determine what direction they are heading in, and at what speed. With that information I can then work out where they are heading towards (eg. one of my bases) and roughly how long it will take them to get there, and in turn guess at what their target might be. And, knowing what their target might be I can see if I have any free battle groups and if so choose the nearest one to intercept the enemy before they reach the target.
Will Eggplant be able to Threat Assess fine enough to distinguish gambits from substantive, real McCoys ? (Be vulnerable to multiple "pin-pricks" as a diversionary & corrosive tactic, in other words.)
.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: How do I stop having ideas?

Post by aubergine »

Yes, sort of.

I'm thinking of having some form of heuristics in there to assess changes in false positives over time for given areas of the map (eg. if map features cause false positives) and enemy players (eg. in case a specific player starts using different tactics). This would mean that each "target prediction" would come with a health warning based on past predictions of a similar nature, as well as being able to highlight anomalies which might need closer attention.

In addition, it should be possible to increase the number of data points to strengthen or weaken a prediction as the data series increases. So, if a unit is seen to be heading in the same general direction for longer the certainty of the prediction will increase and even if the predicted target turns out not to be correct, my intercept group will still have a better idea of where to be on the map for best chances of interception.

One of the other things I'm working on (I wasn't joking when I said I'm all over the place with too many ideas!) is calculating values of droid groups and building clusters. Essentially how much did my stuff cost, how much did the group I plan to protect it with cost, and how much did the enemy group that might attack it cost? Combined with a metrics of "how important is the possible target?" and "how difficult would it be to recapture that area?" this could mean, for example, that I allow a base to be destroyed because I have another base (or multiple "survivor" droids hidden in ally bases) meaning that I can recover quickly. In turn, that could lead to my AI creating "honey pots" to tempt a player to do something that will later cause them lots of pain.

Anyway, for now I'm continuing with my VTOL dogfighting code (which is turning out to be rather more mind-bending than expected). I hope to have fully dynamic VTOL air-to-air battles against enemy VTOL groups, complete with "baiting" which is where my VTOL group(s) will draw enemy VTOL groups closer to my surface-to-air defences (one of the biggest opportunities for radar jammers would be to prevent the enemy from realising this is happening). If I can get that working, I'll be a very happy person!
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Using OOP to manage target designators

Post by aubergine »

As I mentioned previously, I'm working on 30+ target designators (think of them as advanced tactical targeting computers of for a droid or group of droids) and my code was getting messy. I realised that my OOP inheritance code could be of great value here...

First, I've made a little pointer reference to enable me to make my classes stand out from from the crowd:

Code: Select all

// I've no idea if this will cause an issue with savegame persistence, but more on that in a later post
var class = Function;
// note: i've not even tested if this works, just had the idea now while writing this post lol
Next, create a container for basic targeting designators that generally apply to all types of attack group:

Code: Select all

class rootDesignators() { ... }
Now let's add some target designator functions (remember this is just very basic things, that aren't even really "targets"):

Code: Select all

// ... = removed designator code for sake of clarity
rootDesignators[EP_TARGET_NONE] = function() { ... }
rootDesignators[EP_TARGET_ONE] = function() {...}
rootDesignators[EP_TARGET_AGGRO] = function() {...}
 ... etc ...
You'll notice that I'm using constants as function names (you can see an example of these in my earlier post). Despite some of the constant values having spaces, eg. EP_TARGET_ONE = "Target One", it works just fine - because JS objects are just hash maps (name=value pairs) so we're just creating named references to functions. A benefit of using the constants this way is that the constant can now be used throughout the code making it very clear where it's getting used. It means I don't have to map constants to function names with some crufty if..then..else or switch statement.

Let's say the EP_TARGET_NONE designator looks something like this:

Code: Select all

// pseudo-code for sake of clarity
set unit attack mode to "hold fire"
set unit stance mode to "hold position"
move unit(s) to target location
return []
That will work fine for land units, but it would be somewhat risky for VTOL units because they'd *land* putting them in greater risk of enemy artillery fire. To get round this problem, we need to create a VTOL specific EP_TARGET_NONE designator...

Code: Select all

// create  a new class that will contain VTOL specific stuff
class vtolDesignators() { ... }

// inherit the root designators
vtolDesignators.epInherit(rootDesignators);

// now override the EP_TARGET_NONE designator
vtolDesignators[EP_TARGET_NONE] = function() { ... }
And, in that designator the code would be something like:

Code: Select all

// pseudo-code for sake of clarity
set unit attack mode to "hold fire"
set unit stance mode to "hold position"
circle unit(s) to target location // this is the changed bit
return []
Finally, I can attach the desired set of designators to my group AI class:

Code: Select all

class EPAirAtkGroup() { ... }

EPAirAtkGroup.prototype.designator = vtolDesignators;
Now all my VTOL attack groups will have a full compliment of designators tailored to VTOLs :) You'll notice that I didn't inherit the vtolDesignators - instead I hooked them up to my class using a property on it's prototype. I did this so that I can switch designator computer for all related groups at any time during the game.

So, let's say a bunch of my designators need to act differently because of something the enemy has researched (like Stormbringer) - I could have code to check for presence of stormbringer in a bunch of designators, or I could just have a new class of stormbringer-aware designators:

Code: Select all

class vtolDesignatorsStormbringer() { ... }

// inherit the normal vtol designators
vtolDesignatorsStormbringer.epInherit(vtolDesignators);

// now override the EP_TARGET_NONE designator
vtolDesignatorsStormbringer[EP_TARGET_NONE] = function() { ... }
In the new EP_TARGET_NONE designator, I might include additional checks to look for nearby enemy Stormbringers and make the VTOL group react differently if any are found.

Then I just switch the designator on my group prototype:

Code: Select all

EPAirAtkGroup.prototype.designator = vtolDesignatorsStormbringer;
And voila! All my VTOL attack groups just got new designators that are Stormrbringer-aware.
Last edited by aubergine on 17 Jan 2012, 17:26, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
cumandgetit
Trained
Trained
Posts: 103
Joined: 06 Feb 2009, 04:02

Re: EggPlant AI ramblings

Post by cumandgetit »

from the looks of it your eggplant ai could be making converts from wz net mp to wz skirmish when it's done. you can read between the lines on that one. ;)

i'm also thinking your methods at least, if not the work itself, could apply outside wz and possibly even oss games. while saying that last may sound wierd here, maybe stir up mobish ire, it could potentially bring a different, more appreciative, facial expression to you know who. :)
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: EggPlant AI ramblings

Post by aubergine »

I would think of EggPlant currently more as a proof of concept. Until it all starts coming together properly (which would require some discipline on my part to not randomly code in dozens of different directions at once!) it will be difficult to assess how well it will turn out.

One of my bigger concerns currently is the amount of list iterating the AI will have to do. So I'm working on a pattern for multi-frame pseudo-threads using the JS API queue function.

Code: Select all

queue("frameThread",someTask);
someTask would be an object containing a list (eg. of droids), an index pointer (where is it currently up to in that list), a function enclosure (the code to run on the next part of the list, with enclosed vars pointing back to the main AI objects) and any other data that is relevant.

This will:

1. Spread bigger tasks across multiple frames, avoiding stuttering of the gameplay for humans
2. Ensure that pretty much everything in my AI runs across frames, because pretty much everything has to iterate through lists
3. Ensure that event handlers don't do too much processing which could cause stuttering
4. Make the AI somewhat more human like - it's not making big decisions "instantly", it's taking some time to think about them

The "frameThread" would be a very basic event listener, something like:

Code: Select all

function frameThread(task) {
  if (!task.isComplete(maxTime)) queue("frameThread",task);
}
task.isComplete is basically an iterator function that will continue processing the list (enclosed var in task) from wherever it's currently up to in that list, for a maximum of maxTime ms. If it reaches end of list before maxTime, it returns true, otherwise it updates the index pointer to "remember where it's up to" and then returns false, causing it to get queued again for more processing on the next frame.

EDIT: If anyone has any ideas as to what value I should use for maxTime, I'm all ears. I'd ideally like it to throttle cross-frame tasks based on current game load, but I have no idea how to work that out via JS API.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
cumandgetit
Trained
Trained
Posts: 103
Joined: 06 Feb 2009, 04:02

Re: EggPlant AI ramblings

Post by cumandgetit »

I read those ai decison tree links rman posted and it looked to me like iteration efficiency was a key factor of the id algorithms reducing processsing overhead through what I took for some sort of training procedure for lack of a better term. but i could be off in my reading. sorry if i'm rambling. this proof of concept is compelling.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: EggPlant AI ramblings

Post by aubergine »

cumandgetit wrote:... looked to me like iteration efficiency was a key factor of the id algorithms reducing processsing overhead through what I took for some sort of training procedure ...
Problem is that my brain and maths don't get along. So when my eyes see something that looks like this:

Image

My brain goes to its "happy place" and replaces the image with something more like this: factsandchicks.com

So I had to stop reading at that point before awakening the Neanderthal part of my brain. I will probably have to "do maths" at some point in this AI, but for now I'm avoiding the use of numbers for anything other than array indexes wherever possible.
Last edited by aubergine on 17 Jan 2012, 19:48, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Heraclitus

Post by aubergine »

And, while we're on the subject of math, finally a respected academic has basically admitted that reality is in fact real and that current math is making assumptions it really shouldn't be making:

The End Of A Physics Worldview: Heraclitus and the Watershed of Life

I was even more impressed that the lecture referenced my favourite pre-Socratic philosopher: Heraclitus - someone who to me had a very unique ability to see what was going on in front of his eyes. I say "his", but I still feel that Heraclitus was possibly female - at a time when women were thought of as nothing more than property, why would a family name a son after the female god Hera?

BTW, this is what I'm like when I'm not buried in some complex task. Hello, pleased to meet you all :)

Anyway, back to coding... And OMG I wish there was a JS debugger or even JS console window in-game, would make JS AI dev so much more productive. (but I'm not complaining - being able to code an AI for a desktop game using JS is frikkin awesome!)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Rman Virgil
Professional
Professional
Posts: 3812
Joined: 25 Sep 2006, 01:06
Location: USA

Re: EggPlant AI ramblings

Post by Rman Virgil »

aubergine wrote:And, while we're on the subject of math, finally a respected academic has basically admitted that reality is in fact real and that current math is making assumptions it really shouldn't be making:

The End Of A Physics Worldview: Heraclitus and the Watershed of Life
Stuart Kauffman, THE preimminent complexity theorist of his generation, is certainly no slouch intellectually but he's not the first by any means to express such about mathematics. Bertrand Russell, whose stature is at least the equal of Stuart Kaufman's, put it this way almost a hundred years ago:
“Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.” ~ Bertrand Russell
And some others from a past preceding Kaufman, with equally impeccable academic credentials:
"Still more astonishing is that world of rigorous fantasy we call mathematics." ~ Gregory Bateson
"Mathematics are well and good but nature keeps dragging us around by the nose." ~Albert Einstein
"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." ~ Albert Einstein
And while she was better known for asking Cary Grant - "Is that a gun in your pocket or are you just glad to see me ?" - she was a natural and instinctively on the right track when it came to mathematics:
"A man has one hundred dollars and you leave him with two dollars. That's subtraction." ~ Mae West
:lol2:

But yea, I can relate to mathematics making one's head spin and ache at the same which is what happens to me every time I try to grasp String Theory geometry. :stressed: O_o :oops:

aubergine wrote:I was even more impressed that the lecture referenced my favourite pre-Socratic philosopher: Heraclitus - someone who to me had a very unique ability to see what was going on in front of his eyes. I say "his", but I still feel that Heraclitus was possibly female - at a time when women were thought of as nothing more than property, why would a family name a son after the female god Hera?
I've never seen such about Heraclitus being a woman. Kinda makes sense about the name. I'll have to look at the etymology. I've had my copy of his "Fragments" for a long time and the work holds a special place in my fundamental metaphysics - on a par with Taoism, truth be told. Thanks for the Kauffman-Heraclitus link, a fascinating paper indeed. :3

And BTW, some 800 years after Heraclitus, about 400 AD, there was the female scientist-philosopher-mathematician Hypatia who was also the last custodian of the Library of Alexandria before it was burnt to the ground, one the greatest tragedies of the anchient world. This was one extraordinary woman for any era, let alone that time.
Here's a quick link

aubergine wrote:BTW, this is what I'm like when I'm not buried in some complex task. Hello, pleased to meet you all :)
Ditto, and back at ya. :)

Regards, RV. :hmm:
.
cumandgetit
Trained
Trained
Posts: 103
Joined: 06 Feb 2009, 04:02

Re: EggPlant AI ramblings

Post by cumandgetit »

as long as we be talkin math, women and comp ai....

ada lovelace, the poet lord byron's daughter (1815-1852), wrote the very first algorithm which was supposed to run on what is considered the first comp, charles babbage's analytical engine. she even saw beyond babbage's vision of just calculating functions. a good case can be made for her being the world's first computer programmer.

too bad none hypatia's work survived the burning. i bet heraclitis' complete works went up in smoke along with countless other treasures of the creative anchient mind that infamous day.

these ramblings are facinating, I must say. :)
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: EggPlant AI ramblings

Post by aubergine »

I'm actually approaching the point in my AI where I will have no alternative but to do math. I will be wearing protective clothing and have a pictorial version of my "Future Wives To-Do List" within arms reach as an added safety precaution. Wish me luck...
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
bendib
Regular
Regular
Posts: 1011
Joined: 29 Aug 2010, 05:22
Location: Imeuta
Contact:

Re: EggPlant AI ramblings

Post by bendib »

aubergine wrote:I'm actually approaching the point in my AI where I will have no alternative but to do math. I will be wearing protective clothing and have a pictorial version of my "Future Wives To-Do List" within arms reach as an added safety precaution. Wish me luck...
Poor soul.... nice knowing him...
Also known as Subsentient.
cumandgetit
Trained
Trained
Posts: 103
Joined: 06 Feb 2009, 04:02

Re: EggPlant AI ramblings

Post by cumandgetit »

aubergine wrote:I'm actually approaching the point in my AI where I will have no alternative but to do math. I will be wearing protective clothing and have a pictorial version of my "Future Wives To-Do List" within arms reach as an added safety precaution. Wish me luck...
rotflol. :lol:

sure enough, good luck ! :D
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

maths

Post by aubergine »

Image
That is all.

I feel better now I've got that out of my system.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply