Codename: Gamma

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

Moderator: Defcon moderators

User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Fri Jan 22, 2010 4:38 pm

xander wrote:
Ace Rimmer wrote:SetActionTartget

Is that the command for fetching little cakey things?

xander

Apparently I was hungry and Defcon doesn't have access to food.
Smoke me a kipper, I'll be back for breakfast...
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Fri Jan 22, 2010 7:46 pm

Ok, so I found a little issue with the CitySurvey portion of the code, for anybody that might stumble across it later (or if you decide to reuse it martin):

Code: Select all

function CitySurvey()
   StartLongTask(function()
         SendChat("Starting City Survey")
         local allCities = GetCityIDs()
         myCities = GetCityIDs()
         enemyCities = GetCityIDs()
         local us = GetOwnTeamID()
         for i, city in ipairs(allCities) do
            local long, lat, pop = city:GetLongitude(), city:GetLatitude(), city:GetCityPopulation()
            if city:GetTeamID() == us then
               DrawWhiteboardSquare(long, lat, pop / 3000000)
               table.insert(myCities, city)
            else
               DrawWhiteboardCross(long, lat, pop / 3000000)
               table.insert(enemyCities, city)
            end
            YieldLongTask()
         end
         SendChat("City Survey Complete")
      end)
end


This bit right here:

Code: Select all

         myCities = GetCityIDs()
         enemyCities = GetCityIDs()


I was trying to get [Bot]Gamma to identify which territory it was and which territory it was going to fight, and for the life of me couldn't get my if ... then statements to work 100% of the time. When only one territory (the Bot) was in-game, that code worked fine however, when two territories were used (Bot + CPU), then myCities suddenly became cities on a different territory (breaking my if ... then statements). Took me an hour of looking at my code before I looked at the table code. In short; if Bot was Africa, and CPU was Europe, myCities[1] became Wien (Austria) when it should be Yaoundé, Cameroon (I think). As soon as I removed those two lines, it started working correctly, so far. :P
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Mon Jan 25, 2010 1:16 am

With retrospect I have no idea why I would write those lines of code....

Well fixed ;)

Also, apologies for making you slog through and fix my horribly broken code :(
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Schubdüse
level5
level5
Posts: 1209
Joined: Tue May 08, 2007 10:00 pm
Location: Germany_GMT+1

Postby Schubdüse » Mon Jan 25, 2010 1:26 am

Two gods (Ace and martin) are talking about how to create an AI organism.
Use magic command here...
Add some holy water there...
Wave some hands in a miracle move...

And the devil (xander) gives some funny comments...

I love this thread! :D
Vorsprung durch Kraft - Triebwerke saugen - Präzisionsarbeit... Schubdüse.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Mon Jan 25, 2010 1:33 am

No apologies necessary. If it weren't for Joshua, I would still be scratching my head in a lot more ways. :wink:

Quick question; can a function call another function based on a table? I've gone with if elseif statements for the 1v1 section, but wanted to have a table that said something like:

Code: Select all

1v1Combo = {<have combos listed>}

local myCity1 = <find my territory>
local yourCity1 = <find your territory>
local MatchUp = mycity1yourCity1

function(which placement style to pick) = 1v1Combo(MatchUP)


vs my current:

Code: Select all

if myCity1 = NorthAmerica and yourCity1 = Europe then
NAvsEU()
elseif <all 30 combos>
end


I know the above is not correct syntax, but you get the idea. The Lua documentation may cover this, but if it does, it's beyond me.
User avatar
xander
level5
level5
Posts: 16859
Joined: Thu Oct 21, 2004 11:41 pm
Location: Riverside, CA, USA
Contact:

Postby xander » Mon Jan 25, 2010 2:06 am

It seems to me that you need a switch statement. I don't know if you can do it in Lua, but in C, it would look something like this:

Code: Select all

int Matchup     #in C, switch statements operate on ints

switch (Matchup)
{
     case 0: NAvsSA(); break;     #places units when AI is NA and the other player is SA
     case 1: NAvsEU(); break;
     case 2: NAvsRU(); break;
     ...
     case 30: AFvsAS(); break;
}


You may find something useful for Lua here.

xander
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Mon Jan 25, 2010 2:40 am

In this case, what xander said is the best, go for a switch.

In other cases it may be best to remember that in lua functions are values too, soyou can do things like:

Code: Select all

function foo(n)
{
   return n*2;
}

bar = foo;

bar(2); //returns 4


Which may be useful, in this specific example you could use a switch statement to get your function, assign the result to a variable, and then call the variable. Obviously that's pretty useless since you only do it once, but if you have something you do often, based on territory positions, you can do the switch once in your setup phase, and then just call the stored function.

I hope that made sense...

edit:: Check this out, for a slightly more understandable explanation http://lua-users.org/wiki/FunctionsTutorial
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Mon Jan 25, 2010 6:58 pm

I did read both of those (prior to you two posting them in fact) and I guess it's because I have no real experience with coding that I am almost completely lost when trying to understand how exactly to implement such things. I'll keep trying, but for now will stick with what I can get to work (if, elseif statement).

In other news, now that I've worked out the basic structure for each set-up, I'm trying to fine tune ground unit placement. Read that as 'psuedo random initial silo placement with the rest (except radars) built around Silo1'. In short, a for or while loop. Keep getting "attempt to index global/local '51': a nil value". 51 is longitude. Can't wait to solve this one.

I've tried a number of different things, but this is the current non-working code, if you have suggestions. What I am attempting to do is:

1. Place Silo #1 at random co-ordinates within a small section of NA (near Ontario I guess) and (not worked on yet: make sure location isn't a city)
2. Assign key 1 in table siLos to Silo #1
3. Get actual location (long, lat) of Silo #1
4. Place Silos 2-6 at about 220-240 degrees (+4, -3) from Silo #1
5+ airbases next, then radar (with some exceptions)

Code: Select all

local x  = math.random(-95, -80)
      local y = math.random(44, 54)
      
      if (IsValidPlacementLocation (x, y, "Silo")) then
         PlaceStructure (x, y, "Silo")
      end
      units = GetAllUnits()
      YieldLongTask()
      local us = GetOwnTeamID()
      for i, unit in ipairs(units) do
         if unit:GetTeamID() == GetOwnTeamID() then
            if unit:GetUnitType() == "Silo" then
               table.insert(siLos, unit)
            end
         end
         YieldLongTask()
      end

      S1=siLos[1]

      a = S1:GetLongitude() <------- error is here 'attempt to index global (or local) '51' a nil value
      b = S1:GetLatitude()

      while GetRemainingUnits("Silo") > 0 do
         while true do
            if (IsValidPlacementLocation (a, b, "Silo")) then
               PlaceStructure (a, b, "Silo")
               break
            end
         end
         YieldLongTask()
         a = a +4
         b = b-3
      end


As you can see, it's really just a bastardization of existing code. :P

Edit: I'm also posting all this as a make shift work log for me/others that attempt this later.
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Mon Jan 25, 2010 8:03 pm

Just a guess, are Lua tables zero based, so the first item should be in siLos[0] not siLos[1]?
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

!

Postby Ace Rimmer » Mon Jan 25, 2010 10:17 pm

No, I think it has to do with having the code placing the silo and putting it's unitID in a table at the same time ('startlongtask'). That is, it's trying to place all units into the table at the same time as placing the units, which means nothing goes into the table because at that moment, nothing exists.

:roll:

I broke it out into pieces until I could verify that. Also, I was getting confused by Defcon's chat font; '51' isn't the same as 'S1', but they look nearly identical in the chat box. :P I thought it was giving me co-ordinates as the value and then telling me the value was nil (which is crazy!), instead it was giving me the name of the non-existent value.
User avatar
cza
level4
level4
Posts: 633
Joined: Fri Nov 21, 2008 7:31 am
Location: The Void

Postby cza » Wed Jan 27, 2010 4:46 am

I hope you're going to enable fighters to kill nukes : p
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Wed Jan 27, 2010 11:35 pm

I'm trying to compile and keep getting this error in Visual C++ 2008 Express Ed:

1> Creating library E:\Defcon\AI\AceBot\\AceBot.lib and object E:\Defcon\AI\AceBot\\AceBot.exp
1>luabot.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: struct Funct::UnitData * & __thiscall std::vector<struct Funct::UnitData *,class std::allocator<struct Funct::UnitData *> >::operator[](unsigned int)" (??A?$vector@PAUUnitData@Funct@@V?$allocator@PAUUnitData@Funct@@@std@@@std@@QAEAAPAUUnitData@Funct@@I@Z)

1>E:\Defcon\AI\AceBot\\AceBot.dll : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://e:\Defcon\AI\AceBot\Debug\BuildLog.htm"


I've followed the instructions listed in the API Quickstart Documentation for setting up Visual, the requirements listed on Robin's page, and also here: Clicky. Anybody know what I'm doing wrong? My assumption is that it's looking for a library or something and can't find it?
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Jan 28, 2010 4:57 pm

Hooray! I've finally figured out how to get it to Place Silo, wait for update (tick), put silo in table to be referenced. Whee! (still can't compile).

Now I just need to work out how to place randomly but in a tight formation, then it's on to bomber waves. I foresee that one as a bit of a mountain to tackle (for somebody that doesn't know how to code anyway).

:D
Smoke me a kipper, I'll be back for breakfast...
User avatar
trickser
level5
level5
Posts: 1823
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Thu Jan 28, 2010 5:44 pm

Why do you need to compile at all, when you are using the LUA interface?
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Jan 28, 2010 5:54 pm

Two reasons:

1. I want to rename the luabot.dll
2. I want to have the option to manipulate the C++ part to include functions that might not otherwise be accessible.
Smoke me a kipper, I'll be back for breakfast...

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 1 guest