Skip to content

Commit

Permalink
more defensive
Browse files Browse the repository at this point in the history
  • Loading branch information
Error323 committed Nov 15, 2010
1 parent f87222e commit e9098c3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions MyBot.cc
Expand Up @@ -128,7 +128,7 @@ bool Defend(int tid, std::vector<Planet>& AP, std::vector<Fleet>& AF,
return success;
}

bool Attack(int sid, int tid, std::vector<Planet>& AP, std::vector<Fleet>& AF,
bool Attack(Map& map, std::vector<int>& EPIDX, int sid, int tid, std::vector<Planet>& AP, std::vector<Fleet>& AF,
std::vector<int>& EFIDX, std::vector<Fleet>& orders, bool restore) {

Simulator sim;
Expand All @@ -139,8 +139,16 @@ bool Attack(int sid, int tid, std::vector<Planet>& AP, std::vector<Fleet>& AF,
sim.Start(dist, AP, AF, false, true);
int numShipsRequired = sim.GetPlanet(tid).NumShips();
int numShips = source.NumShips()-GetIncommingFleets(sid, EFIDX);
int eid = map.GetClosestPlanetIdx(source.Loc(), EPIDX);
canAttack = numShips > numShipsRequired;

if (eid != tid && eid != -1 && canAttack)
{
numShips -= (AP[eid].NumShips() - (source.GrowthRate() * source.Distance(AP[eid])));
numShips = std::min<int>(source.NumShips()-GetIncommingFleets(sid, EFIDX), numShips);
canAttack = numShips > numShipsRequired;
}

if (canAttack)
{
Fleet order(1, numShips, sid, tid, dist, dist);
Expand Down Expand Up @@ -318,7 +326,7 @@ void DoTurn(PlanetWars& pw) {
bestTarget = tid;
}
}
if (bestTarget != -1 && Attack(sid, bestTarget, AP, AF, EFIDX, orders, true))
if (bestTarget != -1 && Attack(map, EPIDX, sid, bestTarget, AP, AF, EFIDX, orders, true))
{
targets[bestTarget] = sid;
DAPIDX.push_back(bestTarget);
Expand All @@ -341,7 +349,7 @@ void DoTurn(PlanetWars& pw) {
}
else
{
if (Attack(targets[tid], tid, AP, AF, EFIDX, orders, false))
if (Attack(map, EPIDX, targets[tid], tid, AP, AF, EFIDX, orders, false))
{
IssueOrders(orders);
}
Expand Down

0 comments on commit e9098c3

Please sign in to comment.