Page 7 of 9

Posted: Wed Feb 24, 2010 12:16 am
by martin
Ok, so I did a bit of work on the coroutines stuff, I didn't like the way it worked before so basically rewrote it.

If you check out the multithreading.lua in Joshua, you'll see that all functions are now in a single table acting as a namespace (globals are eeeeeevil). The most important change is timing, you can set the time that the tasks have to execute, it will then keep executing tasks until that time is exceeded. If yield is called when there is still spare time, it will ignore the yield, and if a task finishes when there are more in the queue it will start the next task and so on. This all sound good, except that in practice I have found that using a time of anyhting larger than 1 millisecond will crash defcon, which is unfortunate. 1ms is a surprisingly long time, however, and some of my long tasks take much less time to execute now :D

EDIT:: If you guys nab the multithreading file off the svn, feel free to use it.

My only advantage writing Joshua is I'm a far more experienced coder, why am I giving these benefits away? ;)

Re: Joshua

Posted: Wed Feb 24, 2010 12:25 am
by roflamingo
martin wrote:my bot, called Joshua


I think of it as CatBot.

Posted: Wed Feb 24, 2010 2:06 am
by martin
CatBot? :/

What I really came here to say:

I've improved my multithreading module to execute tasks strictly in the order they were issued. Which is really really helpful!

Edit::

Ok, so I said that a queue for in order execution was useful, here's an example, this is part of my placement code (obviously drawing a box isn't really a long task, it's just here for an example):

Code: Select all

local bound
Multithreading.StartLongTask(function()
   bound = GenerateCityBoundingBox(JoshuaInstance)
end)
      
Multithreading.StartLongTask(function()
   whiteboard.drawBox(bound.minLongitude, bound.minLatatitude, bound.maxLongitude, bound.maxLatatitude)
end)


So, as you can see, I can logically divide up my big task into a series of smaller tasks

Posted: Wed Feb 24, 2010 6:56 pm
by martin
Work Log:

Been working on the unit placement code, at the moment the bots scans the bounding box around all allied cities, and generates a score for every integer location in the box. It then finds the highest scoring position and sticks a silo there, it keeps on until there are no more silos left. I have a pretty crappy silo placement system at the moment, I'll be working on that next, for now I need a break from 5 hours of Lua coding ><

Posted: Wed Feb 24, 2010 6:58 pm
by Ace Rimmer
martin wrote:Work Log:

Been working on the unit placement code, at the moment the bots scans the bounding box around all allied cities, and generates a score for every integer location in the box. It then finds the highest scoring position and sticks a silo there, it keeps on until there are no more silos left. I have a pretty crappy silo placement system at the moment, I'll be working on that next, for now I need a break from 5 hours of Lua coding ><

Why not do what I do and find the first best position and place around that, instead of 'first best', 'second best', etc. :?:

Posted: Wed Feb 24, 2010 7:01 pm
by martin
Well your arrangement will always generate a ring of silos, I was looking for something a little more flexible than that, if I up the score just around a silo, then I can increase the probability of a ring. However, if there was a map with two really huge cities a long way apart I would probably end up with 2 rings. It's all in the scoring function

Posted: Wed Feb 24, 2010 9:44 pm
by Ace Rimmer
martin wrote:Well your arrangement will always generate a ring of silos ...

Actually, my arrangement will [REDACTED] and [REDACTED], thus allowing [REDACTED]. So you see, while you think yours is more flexible, it's really just more 'haphazard'. :wink:

Edit: In truth, yours is just more flexible in terms of what game mode is being played and only with regard to game mode; it can place in any/all setups (or should be able to). While mine is more restricted at that level, it's much more flexible within the game mode than you would initially think.

Posted: Wed Feb 24, 2010 10:15 pm
by martin
It might be useless flexibility, in which case I can swap out silo placement for a different method later. Coming up with a good score function is difficult, and it's probably gonna need a genetic algorithm or something to pick decent values, which is more effort than I'm really willing to put into this.

Posted: Fri Feb 26, 2010 12:35 am
by martin
I spent today porting some code over from C#, a min-max-heap, which allows efficient extraction of the largest and smallest items from a large set of values (ie. I can mess with heaps of about 3000 items without a single yield, pretty efficient). So now I can just throw score values for every point in my territory into the heap, and pull out the maximum one.

Next, I'm going to move away from building placement and play with air patrols

Posted: Fri Feb 26, 2010 1:48 am
by roflamingo
Sounds like Ace borrowed some code :D

I wouldn't split up silos to guard 2 large cities.

Posted: Fri Feb 26, 2010 2:44 am
by Ace Rimmer
Actually, I haven't even seen that new code, yet. :wink:

Posted: Fri Feb 26, 2010 5:28 am
by roflamingo
Right. Well if you want any placement code, I will trade you for some navy code. 8)

Posted: Fri Feb 26, 2010 6:58 pm
by martin
Ace, how are you retrieving unit IDs for things once you've placed them (specifically airbases). PlaceStructure doesn't return a unitID which I expected it to, are you placing all structures and then going through a list of all units, pulling out just the airbases?

Posted: Fri Feb 26, 2010 9:22 pm
by Ace Rimmer
martin wrote:Ace, how are you retrieving unit IDs for things once you've placed them (specifically airbases). PlaceStructure doesn't return a unitID which I expected it to, are you placing all structures and then going through a list of all units, pulling out just the airbases?

Yep, exactly what I'm doing. It only takes half a tick to do it.

For the navy code, I'm not even looking in any tables, rather using GetAllUnits() and TeamID() ~= or == to "us".

Posted: Fri Feb 26, 2010 9:48 pm
by martin
Ok, well I implemented that, it's a bit of a pain though, I'd like to use my processing time for more useful things!

Next, I'm either going to play with air patrols, or guestimating positions of enemy silos from scouts (backtracking incoming shots)