Skip to content

Commit

Permalink
Update OpenRA.Mods.RA/AI/HackyAI.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
earthpig committed Apr 25, 2012
1 parent 8190ddc commit b8c834b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions OpenRA.Mods.RA/AI/HackyAI.cs
Expand Up @@ -275,10 +275,16 @@ void AssignRolesToIdleUnits(Actor self)

activeUnits.Add(a);
}

/* Create an attack force when we have enough units around our base. */
// (don't bother leaving any behind for defense.)
if (unitsHangingAroundTheBase.Count >= Info.SquadSize)
int randomizedSquadSize = 0;
while (randomizedSquadSize <= Info.SquadSize-3)

This comment has been minimized.

Copy link
@chrisforbes

chrisforbes Apr 28, 2012

let's just write this whole loop as

var randomizedSquadSize = Info.squadSize - 3 + random.Next(300);

that looks equivalent, has bounded running time, and doesn't burn through so much of the random stream.

{
randomizedSquadSize = random.Next(300);
}

if (unitsHangingAroundTheBase.Count >= randomizedSquadSize)
{
BotDebug("Launch an attack.");

Expand Down Expand Up @@ -314,7 +320,7 @@ void AssignRolesToIdleUnits(Actor self)
// Check how many own units we have gathered nearby...
var ownUnits = world.FindUnitsInCircle(a1.CenterLocation, Game.CellSize * 2)
.Where(unit => unit.Owner == p).ToList();
if (ownUnits.Count < Info.SquadSize)
if (ownUnits.Count < randomizedSquadSize - 3)

This comment has been minimized.

Copy link
@chrisforbes

chrisforbes Apr 28, 2012

this -3 seems spurious

This comment has been minimized.

Copy link
@earthpig

earthpig Apr 29, 2012

Author Owner

It's to reduce the amount of time that is spent doing the 'rally before attack' dance. My initial temptation was to get rid of that check entirely; this was the 'conservative' approach.

{
// Not enough to attack. Send more units.
world.IssueOrder(new Order("Stop", a1, false));
Expand Down

0 comments on commit b8c834b

Please sign in to comment.