Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more defensive

  • Loading branch information...
commit e9098c33556aa6252c6a6a0f7fad9895d3e06970 1 parent f87222e
@Error323 authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 MyBot.cc
View
14 MyBot.cc
@@ -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;
@@ -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);
@@ -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);
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.