From e9098c33556aa6252c6a6a0f7fad9895d3e06970 Mon Sep 17 00:00:00 2001 From: Error323 Date: Mon, 15 Nov 2010 22:55:49 +0100 Subject: [PATCH] more defensive --- MyBot.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/MyBot.cc b/MyBot.cc index 0dc7e4d..ea9e79e 100644 --- a/MyBot.cc +++ b/MyBot.cc @@ -128,7 +128,7 @@ bool Defend(int tid, std::vector& AP, std::vector& AF, return success; } -bool Attack(int sid, int tid, std::vector& AP, std::vector& AF, +bool Attack(Map& map, std::vector& EPIDX, int sid, int tid, std::vector& AP, std::vector& AF, std::vector& EFIDX, std::vector& orders, bool restore) { Simulator sim; @@ -139,8 +139,16 @@ bool Attack(int sid, int tid, std::vector& AP, std::vector& 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(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); }