public StrategicDecision RunAway_FreeWay(TurnState turnState, Ship ship, StrategicDecision prevDecision) { var finalCoords = new List <int>(); foreach (var enemyShip in turnState.enemyShips) { var move = FastShipPosition.Move(enemyShip.fposition, ShipMoveCommand.Faster); move = FastShipPosition.Move(FastShipPosition.GetFinalPosition(move), ShipMoveCommand.Faster); move = FastShipPosition.Move(FastShipPosition.GetFinalPosition(move), ShipMoveCommand.Faster); var finalCoord = FastShipPosition.Coord(FastShipPosition.GetFinalPosition(move)); finalCoords.Add(finalCoord); } var candidates = runTargets.OrderByDescending(t => (int)finalCoords.Average(fc => FastCoord.Distance(t, fc) * FastCoord.Distance(t, fc))).Take(3).ToArray(); var runTarget = candidates.OrderBy( t => { var cost = 0; foreach (var enemyShip in turnState.enemyShips) { cost += WayEvaluator.CalcCost(ship.fcoord, t, enemyShip.fcoord); } return(cost); }).First(); return(new StrategicDecision { role = StrategicRole.RunAway, targetCoord = runTarget }); }
private static NavigationMethod GetNavigationMethod(StrategicDecision decision) { switch (decision.role) { case StrategicRole.Approach: return(NavigationMethod.Approach); case StrategicRole.Collector: return(NavigationMethod.Collect); default: return(NavigationMethod.Default); } }
public StrategicDecision MakeStrategicDecision(TurnState turnState, StrategicDecision prevDecision, Ship ship, Ship enemyShip) { var barrels = CollectableBarrels(turnState, enemyShip); var nextShipPosition1 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship.fposition, ShipMoveCommand.Faster)); var nextShipPosition2 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship.fposition, ShipMoveCommand.Wait)); var target = barrels.FirstOrDefault( b => FastShipPosition.DistanceTo(nextShipPosition1, b.barrel.fcoord) < b.dist - 1 || FastShipPosition.DistanceTo(nextShipPosition2, b.barrel.fcoord) < b.dist - 1); if (target == null) { return(strateg.RunAway(turnState, ship, prevDecision)); } var barrelToFire = barrels.TakeWhile(b => b != target).LastOrDefault(); return(strateg.Collect(target.barrel).FireTo(barrelToFire?.barrel.fcoord)); }
public StrategicDecision WalkFree(TurnState turnState, Ship ship, StrategicDecision prevDecision) { switch (prevDecision?.role) { case StrategicRole.Free: break; default: prevDecision = new StrategicDecision { role = StrategicRole.Free, targetCoord = freeTargets[0] }; break; } if (FastShipPosition.DistanceTo(ship.fposition, prevDecision.targetCoord.Value) < Settings.FREE_WALK_TARGET_REACH_DIST) { var freeIndex = (Array.IndexOf(freeTargets, prevDecision.targetCoord.Value) + 1) % freeTargets.Length; return(new StrategicDecision { role = StrategicRole.Free, targetCoord = freeTargets[freeIndex] }); } return(prevDecision); }
public StrategicDecision RunAway(TurnState turnState, Ship ship, StrategicDecision prevDecision) { return(RunAway_FreeWay(turnState, ship, prevDecision)); //return WalkFree(turnState, ship, prevDecision); }