Another AI startup

Come in here to talk about your sky-net style world-destroying super bots!

Moderator: Defcon moderators

Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Another AI startup

Postby Lord Akkrand » Fri Sep 23, 2011 7:36 am

Hey,

So I've just started writing an AI for Defcon using the API (although I'll be using C++ rather than lua as most people seem to have).
Right now I've done very little, just got it compiling and running, doing some basic scans of the world to try to find out where to place things.
I generally code on the train in the morning and evenings, so don't get that much time (and that's if I get a seat!).
So here's to hoping I get something finished, I'll try to keep this thread updated; I think I'm on the mailing list as well.

Cheers,
Lord Akkrand
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Mon Sep 26, 2011 1:42 am

I think I've gotten the structure of my placement algorithm down, just needs a bit of tweaking.

In essence my silo placement boils down to this:
1. Scan the map, flagging locations where I can place silos (the whole world, in degrees of 1 latitude/longtitude, so 64800 possible positions)
During this scan, I also prepare several other maps such as enemy territory, enemy sea territory, etc.

2. Iterate over all the cities, and when I find a friendly city, mark all the locations within distance 2 of that city as invalid locations for a silo (to prevent splash damage).
3. 'Blot' a circle of influence from each city, degrading with distance, and of a strength proportional to the size of the city.
4. For each piece of enemy territory, blot a circle of negative influence from that location of a RadarStation's RADAR_RANGE. This influence does not degrade with distance.

5. Use roulette-wheel selection to pick the best place for a silo (where the fitness of a location is based on a weighting between enemy radar range & friendly city range.)
Place that silo, mark all locations within 5 of it as invalid placement locations, and then blot an influence equal to the silo's combat range at it's location, to show that any other buildings placed within it's influence are protected by it.
6. If there are silos remaining to be placed, go to step 5.

Numbers need to be tweaked (such as the exponent in the roulette-wheel selection), but it currently clusters it's silos (although my first run had 2 distinct clusters on each side of India due to the exponent being a little weak).

My next stage is to provide radar coverage for all enemy territory/the silos/the country. Any ideas on how that should be weighted? Is it more important to have coverage of your own assets (so your silos can fire defensively), or of enemy movements so you can attack effectively?

Then will come something that works out if our naval territory is divided and decide if it needs to split the navy to cover both, based on it's enemy.
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Wed Sep 28, 2011 12:29 am

Just a query to anyone who is reading and used the API before; I noticed a thread below about the ai='ai/bot/bot.dll' command line argument not working. I'm finding that's the case as well, and it's annoying. Has anyone got it to work?
It's just that it's a few seconds each time I compile and run to drag my touchpad to select the bot, and it gets old real fast.
Also, I've got it to automatically start the game if 2 players get in the lobby, does anyone know if there's a command line argument to add an internal AI player? It would be nice for testing purposes to only hit F5 and have the game load, enter the lobby, select my bot, add an internal AI player, and start the game without input.

In other news, found and fixed a bug in my scanning algorithm that meant my influence maps were upside down. Haven't got a seat on the train last few mornings, so progress slow... :(
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Thu Sep 29, 2011 6:21 am

I'm gathering that the mailing list is dead? I've tried registering for it but gotten no replies.

In updates, got radar being placed; the algorithm looks at all placeable locations, giving them a score for how many new locations will be covered by radar as a result of placing a station there.
I'm including a weighting for those locations being covered by silo range (as it's extra important to have your silos defence range be covered, otherwise they won't be able to see incoming nukes to shoot them)
I also intend to give a weighting to the placement of silos and radar to a backtrack of where likely nukes would be coming from; although I think I need a basic formula for the trajectory of nukes first, so it knows that they follow those arcs. I'll probably start my silos firing on enemy cities in D1 so I can view the nuke trajectories myself if noone has a ready-made formula for me?
User avatar
Schubdüse
level5
level5
Posts: 1210
Joined: Tue May 08, 2007 10:00 pm
Location: Seoul

Postby Schubdüse » Thu Sep 29, 2011 9:13 am

Lord Akkrand wrote:I'll probably start my silos firing on enemy cities in D1 so I can view the nuke trajectories myself if noone has a ready-made formula for me?


I'm not quite sure, but I think Senator (aka trickser) has created such a formula. Pm him. I guess you have read all posts concerning AI bots?
Vorsprung durch Kraft - Triebwerke saugen - Präzisionsarbeit... Schubdüse.
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Fri Sep 30, 2011 1:56 am

Thanks, I have read all the posts on this subforum, and I remember reading something about trajectory calculation code, but when I went back to find it, I couldn't.
It's right there on the page, "Nuke Code (lua)" by trickser (as you suggested).
Using the API document nuke speed of 2.0 did not end with synchronised landings, although I did get my silos to fire in the correct order. I'll plug tricksers formula in and see what I get.
Thanks again,
Akkrand
User avatar
Schubdüse
level5
level5
Posts: 1210
Joined: Tue May 08, 2007 10:00 pm
Location: Seoul

Postby Schubdüse » Fri Sep 30, 2011 10:36 am

NP! And keep up the work! :wink:
Vorsprung durch Kraft - Triebwerke saugen - Präzisionsarbeit... Schubdüse.
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Tue Oct 04, 2011 12:15 am

Not much to add, no seat last two mornings.
Have threaded my defcon5 initialisation; after getting as much information about the world as I can (scanned into my maps), have a thread running in the background which creates the analysis of it in terms of placement. This eliminates a massive amount of lag I had at the start of a game, which slowed down my testing.
The bot also slows down game speed until this is complete, and speeds it up once it's done.

Plugged in the formula, and found the speed it calculates is incredibly slow; close to 0.01 instead of a more reasonable 1.5-2.0 that I'm seeing. It does appear to make the arcs well though, although I've yet to plot the expected vs the actual.
It also didn't deal with trajectories that crossed the -180/+180 boundary (it took the long way around the world), but I think that's because it implies the distance function works in the wrap around world. I changed it to detect a shorter path via wrap and set the target to that (so, if you were shooting at Tokyo from SA, instead of listing Tokyo at (140, 45) it would list it at (-220, 45);
Note I don't think that's actually Tokyo's coordinates, but you get the idea.

I realise that even if the formula as it stands doesn't get the times right (which I can tune), if it gets the paths correct then I can still use it, I'm planning that during my defcon5 inititalisation, I can plot the trajectories of nukes launched from anywhere (everywhere?) in hostile territory to each of my cities in turn. Then my maps can store the average trajectory of a hostile nuke travelling over each location in/near my territory, and use that to help it place silos for protection (by increasing the chance of placing a silo directly in the most common trajectory).

Then, of course, if I can get the timing right, my FiringSchedule class will be able to do what it was designed to do, and that's obliterate a single city/installation by have X warheads hit it simultaneously.

The next thing on the horizon for the bot is the air defence; before navy operations, whilst I still mull over whether I'm going with boids or agents or something else. I want the airforce to maintain constant patrols over friendly territory and keep a portion of the bombers airborne (at a safe distance) in case sub launch/random naval threats are detected.
A large cycling fighter presence should help keep my airspace from being trivially scouted, and help hold off the destruction that occurs at defcon1 when my bot sits there and waits for the enemy fleet to launch it's entire payload into my country.

Here's to hoping I get some more train time the next few days ;)

EDIT: I find it amusing that I began with 'not much to add' then proceeded to write my lengthiest post ever. :)
User avatar
trickser
level5
level5
Posts: 1826
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Tue Oct 04, 2011 9:48 pm

Hi,
the code snippet about nukes-path, I posted, is for sure incomplete, cause nukes would never leave the map. I mean, there must be some additional math to avoid such behavior. But I found it fairly accurate somewhere near the equator. Dont remember noticing inaccurate speed, but it's been a while.
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Wed Oct 05, 2011 1:24 am

Now I've messed with it and it's constantly giving me upside down trajectories; like a nuke from Cairo to New York travelling on trajectory that goes south first then curves north to hit the city from the south, instead of arcing across Europe to hit the city from the north.
I'm about to start collecting some data about a nuke trajectory in progress, to see if I can eyeball a pattern in the numbers to help me get an accurate formula.

Side note, I've noticed that my calls to m_game->RequestGameSpeed() are being ignored, which isn't a real problem as I can change it manually by pressing 1-4 on my keyboard, but anything that speeds up my code-run-test cycle is helpful (which is why it's so annoying I can't get ai='/ai/bot/bot.dll' to work!).

Due to the multithreaded nature of my intialisation step, I find it can take a variable amount of game time for my bot to place his silos and radar. This isn't currently a problem, but if the game speed was on 4 during defcon 5, then all of these things might not get done in time. In the future, if I can't get the RequestGameSpeed to work (and even if I can), I may have to sleep the game thread if the bot is running behind, to allow my threads to play catch up.

Still no movement on the airforce front, nor seats on my morning train. :(
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Thu Oct 06, 2011 5:35 am

Hey,
You're right, trickser, there's nothing wrong with your speed calculations, they're pretty accurate. Just found and fixed a few more bugs that meant I've been looking at garbage data the last couple of days :(

Also, noticed the internal AI (that my bot is playing against) shoot at my nuke with his fighters, got a couple of hits (didn't destroy it, though).
I've never been able to target a nuke with a fighter in single player before, was I doing it wrong, or is this possible?
And if it's not possible, but the AI can do it, has anyone ever seen a nuke shot down by fighters?
And if it is possible only for the AI, should the AI do it?
User avatar
trickser
level5
level5
Posts: 1826
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Thu Oct 06, 2011 9:16 am

Lord Akkrand wrote:And if it's not possible, but the AI can do it, has anyone ever seen a nuke shot down by fighters?

You have to be careful with this question, it has a tendency to offspring endless debates. Use the forum search to see it.

Fighters cant shot down nukes, but they can target them. Do to so you need to order airfields or carriers to attack the nukes, maybe you also must use the left-click - drag - release trick. Think this also works with bombers, except they will only follow the nuke, not shoot it.
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Fri Oct 07, 2011 2:43 am

Well, if they cannot shoot them down, then I won't bother making them try.
User avatar
Schubdüse
level5
level5
Posts: 1210
Joined: Tue May 08, 2007 10:00 pm
Location: Seoul

Postby Schubdüse » Fri Oct 07, 2011 4:42 pm

trickser wrote:You have to be careful with this question, it has a tendency to offspring endless debates. Use the forum search to see it.


:lol: Ace has proven that it is possible! (Under certain conditions) :mrgreen:
Lord Akkrand
level1
level1
Posts: 12
Joined: Thu Sep 22, 2011 11:03 am

Postby Lord Akkrand » Tue Oct 11, 2011 11:59 pm

Right, so my vec2 class is no longer giving me garbage when I ask it what the signed angle between 2 directions is. Nor when I ask it to normalise a vector. Copy/paste errors are the worst.

My vector maths is pretty bad at the best of times, so I struggled to understand what tricksers formula was doing in terms of the angle, but I think I've got it now.
What I'm seeing is that at launch, if you take the signed angle between the line originToTarget and north, then the initial direction of the nuke will be 60 degrees northward of this angle. Then, as the nuke travels, it will slowly point closer and closer to the target, but it's not linearly interpolating between 60 and 0, so I'm trying to discover the constants involved in this degradation.
For example, at 0% travelled, it's 60 degrees offset, at 20% travelled, it's 45 degrees offset, at 50% travelled, it's 27 degrees offset. Those aren't exact numbers, but they're close.

EDIT: oh, and the speed stuff by you trickser, isn't just pretty accurate; it's perfect. By watching a nuke over a few successive frames, and noting it's speed, and rate of change of that speed, it should be trivial to determine a) the % of the total distance that nuke has travelled on it's path. And with rate of change, therefore b) the distance the nuke is from it's origin and c) the distance the nuke is from it's target. Knowing this, and having a record of any prior 'Nuclear Launch Detected' events, you should be able to pinpoint when this nuke was fired, from where, and what it's target is.

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 1 guest