Page 1 of 2

Where to Start?

Posted: Wed May 19, 2010 5:33 pm
by Th3xpl0iT
I really want to write a Bot AI, either in Lua or C++, but I don't know where to start or how. Can someone PLEASE point me in the right direction.. Maybe give me some steps in starting?

- Th3xpl0iT

Posted: Wed May 19, 2010 5:34 pm
by Ace Rimmer
This is a very good place to start: http://www.doc.ic.ac.uk/~rb1006/projects:api

It has all the information you need for Lua and C++ (I think).

Posted: Wed May 19, 2010 6:27 pm
by Th3xpl0iT
Yeah I looked there, I didn't know where to click. Is there a tutorial on this forum, or no?

Posted: Wed May 19, 2010 6:48 pm
by Ace Rimmer
No tutorial.

How much information do you need? That page has everything you need to get started; the Defcon API for LUA, Defcon 1.57 (bot-enabled version), documentation (some is included in the downloads.

Posted: Wed May 19, 2010 6:53 pm
by Montyphy
Th3xpl0iT wrote:Yeah I looked there, I didn't know where to click. Is there a tutorial on this forum, or no?


Tutorial for what exactly? How to program? How to code in Lua? How to make an AI? How to use the API? There should be an example bot included with the API on the above link which, providing you know a little about how to code in your chosen language, should get you going. Possibly the closest thing to a tutorial is this, an explanation of how and why to use the yield feature in the Lua API since it can be a bit tricky to get your head around but nothing really more specific than that.

If you get stuck or have a particular problem you can just post here and people will normally help if they can. Alternatively you can try reading through some of the threads here as they'll include snippets of code and document times when people slipped up.

Posted: Wed May 19, 2010 7:05 pm
by Th3xpl0iT
Maybe I should give an example..

I guess I can piece it together but I want to see what you guys say first. I want my bot to launch a nuke at New York when Defcon 1 hits. What would that look like? Two variables and an if/then statement?

Posted: Wed May 19, 2010 7:54 pm
by Montyphy
Th3xpl0iT wrote:Maybe I should give an example..

I guess I can piece it together but I want to see what you guys say first. I want my bot to launch a nuke at New York when Defcon 1 hits. What would that look like? Two variables and an if/then statement?


Step 1, determine if NA is playing. (loop and if)
Step 2, determine what continent you are. (if)
Step 3, determine where to place your silos based on your given continent. (loop and if)
Step 4, Wait til Defcon 1. (if)
Step 5, Get New York object/location. (get)
Step 6, iterate through your silos targeting New York until all nukes fired. (loop and if)

How complex all that is depends on if you want it to be smart or dumb i.e. place silos based on population densities, enemy location, enemy placements, etc. or just hard code silo locations.

Posted: Wed May 19, 2010 9:40 pm
by Th3xpl0iT
Okay, I'll start working on that, thank you very much.

Now how about something simple but effective.

An enemy fires upon one of my units. I calculate the shot's origin and I fire back. Can you help me write the C++ code?

Posted: Wed May 19, 2010 9:48 pm
by Montyphy
Th3xpl0iT wrote:Can you help me write the C++ code?


Depends what you mean by help. Will I write it for you? No. Will I help troubleshoot the odd error and provide hints on optimisations in code you post? Yes. Although if you want to maximise your chances of receiving help I would suggest you use the Lua API since that's what most/all people here use and understand.

Posted: Wed May 19, 2010 9:58 pm
by Th3xpl0iT
Well I'm brand new to this API, so I don't expect you to write it for me - But it would be nice for you to write it WITH me. :)

First I want the bot to identify itself, what continent it is so it can place it's fleets in certain places. What function can I do to do that?

Posted: Wed May 19, 2010 10:11 pm
by Montyphy
GetOwnTeamId
GetTerritoryId
GetCityIds

Posted: Wed May 19, 2010 10:15 pm
by Th3xpl0iT
So how do I find out the x,y of a city? This bot will be a South American bot.

Posted: Wed May 19, 2010 10:21 pm
by Montyphy
GetLongitude
GetLatitude


You really should just read through the API documentation:
Quickstart
Function list
Constants

Posted: Wed May 19, 2010 10:28 pm
by Th3xpl0iT
Okay so at the beginning of bool Bot::Update()

Code: Select all

     float longitude = m_game->GetLongitude(1);
     float latitude = m_game->GetLatitude(1);



Something like that?

EDIT: I am, but it's a little confusing..

Posted: Wed May 19, 2010 10:30 pm
by Montyphy
Providing 1 is a valid unitId, cityId, or eventId.