Page 4 of 5

Posted: Thu Jan 28, 2010 10:04 pm
by Ace Rimmer
Alright, I've got another issue I need to work out; I can't seem to get my loop to place more than two silos (or more accurately, one silo). It seems I just need to figure out how to get the loop to 'move on' to the second silo. Help!

Code: Select all

   local longone = math.random(-95, -80)
   local latone = math.random(44, 54)
   DrawWhiteboardSquare(longone, latone, 5)         
   if (IsValidPlacementLocation (longone, latone, "Silo")) then
      PlaceStructure (longone, latone, "Silo")
   end
   YieldLongTask()

   units = GetAllUnits()
   repeat
      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
      YieldLongTask()
      S1 = siLos[1] -- S1 Goes after YieldLongTask() (after for end) and before block end
   until # siLos == 1
   
   SendChat("There have been " .. # siLos .. " silos placed")

-- Working code above


   repeat
      local e = # siLos
      local x = siLos[e]:GetLongitude() + math.random(4, 5)
      local y = siLos[e]:GetLatitude() - math.random(3, 4)

      SendChat(siLos[e]:GetLongitude() .. " , " .. siLos[e]:GetLatitude())
      SendChat(x  .. " , " ..  y)
      
         if (IsValidPlacementLocation (x, y, "Silo")) then
            PlaceStructure (x, y, "Silo")
         else
            SendChat("Not valid")
            WhiteboardDraw (longone, latone, x, y)
         end
         YieldLongTask()
      units = GetAllUnits()
      local lastkey = # siLos
   
      SendChat("There have been " .. # siLos .. " silos placed")
      
      for i, unit in ipairs(units) do
         if unit:GetTeamID() == GetOwnTeamID() then
            if unit:GetUnitType() == "Silo" then
               if unit:GetLongitude() ~= siLos[lastkey]:GetLongitude() then
                  table.insert(siLos, unit)
               end
            end
         end
         YieldLongTask()
      end
      YieldLongTask()
   until GetRemainingUnits("Silo") == 3
   YieldLongTask()

   SendChat(# siLos)
   SendChat("1 " .. siLos[1]:GetLongitude() .. " " .. siLos[1]:GetLatitude() .. " 2  " .. siLos[2]:GetLongitude() ..  " " .. siLos[2]:GetLatitude() .. " 3  " .. siLos[3]:GetLongitude() ..  " " .. siLos[3]:GetLatitude() .. " 4 " .. siLos[4]:GetLongitude() .. " " ..siLos[4]:GetLatitude())   
   SendChat(myCities[1]:GetLongitude())
   SendChat(myCitiesLong[1])
   SendChat(myCitiesLat[1])
   SendChat(myCities[1]:GetLatitude())
   SendChat(tostring(siLos[1]) .. " " .. tostring(siLos[2]) .. " " .. tostring(siLos[3]) .. " " .. tostring(siLos[4]))

-- Working code Below



Some of the code is simple there to help me asses what is actually happening (i.e., unnecessary). It looks to me like I can't make Silo#2 the starting point and it keeps going back to Silo#1 and trying to place Silo#3 on top of Silo#2, which is impossible.

Any suggestions?

Edit: I seem to have had it a bit backwards (table entry first, then placement, duh!), but now I can't seem to work out the table.insert function at the end. It'll place a bunch of silos now, but when it get's to the sea (Atlantic, from USA East Coast), it can't place any more but still loops through the code and tells me "there have been 16 silos placed", which is obviously incorrect.

New results: (corrected code above)

Image

Edit: I've worked it all out except for the table.insert portion. It keeps entering the first silo twice. (new code above)

Posted: Mon Feb 01, 2010 7:10 pm
by Ace Rimmer
Triple post (this is a pseudo work log):

I managed to figure out how insert non-duplicate silos into the table; now they can be individually referenced and in the correct order, which will make launching much better (I think). Before, my code was placing silo 1, entering silo 1 into table, placing silo 2, entering silo 1 and 2 into table (silo 1 twice), and so on. Now, it only enters the silo (unit) into the table if it didn't exist before.

local items = Set (siLos)

Code: Select all

   if items[unit] then -- relies on function Set (list)
      SendChat("oops")
   else
      table.insert(siLos, unit)
      SendChat("There have been " .. # siLos .. " silos placed")
   end


Code: Select all

function Set (list)
  local set = {}
  for _, l in ipairs(list) do set[l] = true end
  return set
end


Got this solution from here.

Now I can also use this same function to prevent silos from being placed on top of cities. I'll just need to work out how close a city can be.

Posted: Mon Feb 15, 2010 11:52 pm
by Ace Rimmer
I've updated the original post with some helpful info.

Also, OnEvent() is driving my crazy. Well, actually using it to keep track of enemy units is. I'm using OnTick() (every 10 ticks, or every real life second regardless of game speed) to log enemy unit IDs that become visible (BBs, CVs, Radar, etc), but for the life of me can't figure out a decent way to remove them once they've been killed/destroyed. table.remove needs an exact position (to work correctly) and various forms of table.unitID = nil doesn't work either.

:x

In other news, table.sort doesn't like userdata.

:x :x

Posted: Tue Feb 23, 2010 11:57 pm
by Ace Rimmer
Just because: If you want to know the radius of unit Radar for future use: (subtract 1 from the output as I forgot to tell it that)

Image

I believe I said somewhere the radius for Radar is ~20.

Posted: Wed Feb 24, 2010 12:03 am
by martin
I can help you with table.sort, this is how Joshua sorts his city lists for example:

Code: Select all

table.sort(Joshua.cities.allied, function(a, b) return a:GetCityPopulation() < b:GetCityPopulation() end)


I would imagine that just sorting a table of user data will sort by pointer value, which is useless :P

Posted: Wed Feb 24, 2010 12:08 am
by Ace Rimmer
Hehe, beat you to it. I implemented that bit of Joshua earlier today to target closer cities. :P

(Thanks)

Edit:

Code: Select all

table.sort(silotargetCities, function(a, b) return a:GetLongitude() < b:GetLongitude() end)

Posted: Wed Feb 24, 2010 12:21 am
by roflamingo
Ace Rimmer wrote:Just because: If you want to know the radius of unit Radar for future use: (subtract 1 from the output as I forgot to tell it that)

Image

I believe I said somewhere the radius for Radar is ~20.


How many segments in those circles? How do you get them to draw so quickly? When I go over 24 segments in a circle things start to hang up.

Posted: Wed Feb 24, 2010 12:30 am
by Ace Rimmer

Code: Select all

function CircleTest()
   StartLongTask(function()
   
   
      local a, b, c, d, e, f, g, h, i, j = -117, 56,-96, 52,-143, 45, -141, 17, -170, 30
      PlaceStructure (a,b,"Silo")
      PlaceStructure (c,d, "AirBase")
      PlaceFleet (e,f,"BattleShip")
      PlaceFleet (g,h, "Carrier")
      PlaceFleet (i,j, "Sub")
      
      
      local counter = 0
      local radius = 1
      repeat
         WhiteboardDrawCircle(a,b, radius)
         counter = counter + 1
         YieldLongTask()
         radius = radius + 1
      until counter == 10
      SendChat("Silo " .. radius)
      

      local counter = 0
         local radius = 1
         repeat
            WhiteboardDrawCircle(c,d, radius)
         counter = counter + 1
         YieldLongTask()
         radius = radius + 1
         until counter == 10
               SendChat("Airbase " .. radius)


      local counter = 0
         local radius = 1
         repeat
            WhiteboardDrawCircle(e,f, radius)
         counter = counter + 1
         YieldLongTask()
         radius = radius + 1
         until counter == 10
               SendChat("Battleship " .. radius)


      local counter = 0
         local radius = 1
         repeat
            WhiteboardDrawCircle(g,h, radius)
         counter = counter + 1
         YieldLongTask()
         radius = radius + 1
         until counter == 15
               SendChat("Carrier " .. radius)


      local counter = 0
         local radius = 1
         repeat
            WhiteboardDrawCircle(i,j, radius)
         counter = counter + 1
         YieldLongTask()
         radius = radius + 1
         until counter == 3
               SendChat("Sub " .. radius)

   end
   )
end


Segments I tried: 20, 30, 40. Worked for 20 and 30, 40 was too much.

Posted: Fri Feb 26, 2010 1:23 am
by Ace Rimmer
Booyah! First Bot win over CPU where I didn't manually interfere! No subs, no bomber nukes, only silos and a very primitive fleet reaction code. :D

Edit: Bot 6, CPU -3

Posted: Fri Feb 26, 2010 1:27 am
by Montyphy
Ace Rimmer wrote:Booyah! First Bot win over CPU where I didn't manually interfere! No subs, no bomber nukes, only silos and a very primitive fleet reaction code. :D

Edit: Bot 6, CPU -3


Random territories or NA vs EU?

Posted: Fri Feb 26, 2010 1:30 am
by Ace Rimmer
NA vs EU of course. :P

Although, once I make sure a spec can make it all the way through, it'll simply be a matter of adding the skeleton to all 1v1 combos and then fine tuning them. Now, versus a human player I'll need sub code (which I don't have), bomber flight management, airbase management (have a start there), naval nuking (which should come with bomber management), and some proper Silo management. Sounds like a lot, but versus most people it should be able to be pretty basic stuff.

The fleet management is very very primitive, but I just wanted to see if I could make it work at all.

Posted: Fri Feb 26, 2010 1:32 am
by Montyphy
Sounding very good.

Posted: Fri Feb 26, 2010 10:18 am
by roflamingo
Gratz Ace!! That's huge progress!

(I have scouts bb's up now in shared ocean locations, but no nuking at all and no intelligent fleet placement yet.)

Posted: Fri Feb 26, 2010 6:22 pm
by Ace Rimmer
Well, I'm trying to get them same code to apply to bombers and fighters, but doesn't seem to work exactly right. Also, trying to give bombers the ability to naval nuke, which has failed up to this point.

Posted: Mon Jun 28, 2010 6:37 pm
by Ace Rimmer
I haven't completely figured this out yet, but it appears as though the closer a nuke launch point is to it's target (i.e. shorter flight time) the larger the radius of damage it will do.

I've been testing my city avoidance code in order to fine tune it to an acceptable level (for placing Silos, Radar, Airbases) and found that striking cities that appear visually close yield different results from different distances.

It takes three nukes to kill a silo, so I've been sending three nukes to those cities that I would otherwise say "yeah, it's too close to that silo" (after the placement code has done it's job). Sometimes the silo will take some damage, but not be destroyed, even though the required three nukes all landed at the exact same spot (on a city).

I'm not sure this will ever help anybody, but there it is.