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 void CollectEnemyBarrels(TurnState turnState, Ship enemyShip1, Ship enemyShip2) { var barrels1 = strateg.strategy1vs1.CollectableBarrels(turnState, enemyShip1); var barrels2 = strateg.strategy1vs1.CollectableBarrels(turnState, enemyShip2); var ship1 = turnState.myShips[0]; var ship2 = turnState.myShips[1]; var nextShip1Position1 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship1.fposition, ShipMoveCommand.Faster)); var nextShip1Position2 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship1.fposition, ShipMoveCommand.Wait)); var nextShip2Position1 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship2.fposition, ShipMoveCommand.Faster)); var nextShip2Position2 = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship2.fposition, ShipMoveCommand.Wait)); var target1 = barrels1.FirstOrDefault( b => FastShipPosition.DistanceTo(nextShip1Position1, b.barrel.fcoord) < b.dist - 1 || FastShipPosition.DistanceTo(nextShip1Position2, b.barrel.fcoord) < b.dist - 1); var target2 = barrels2.FirstOrDefault( b => FastShipPosition.DistanceTo(nextShip2Position1, b.barrel.fcoord) < b.dist - 1 || FastShipPosition.DistanceTo(nextShip2Position2, b.barrel.fcoord) < b.dist - 1); while (true) { if (target1 == null) { StrategicDecision decision; strateg.decisions.TryGetValue(ship1.id, out decision); strateg.decisions[ship1.id] = strateg.RunAway(turnState, ship1, decision); } if (target2 == null) { StrategicDecision decision; strateg.decisions.TryGetValue(ship2.id, out decision); strateg.decisions[ship2.id] = strateg.RunAway(turnState, ship2, decision); } if (target1 == null && target2 == null) { return; } if (target1 != null && target2 == null) { var barrelToFire = barrels1.TakeWhile(b => b != target1).LastOrDefault(); strateg.decisions[ship1.id] = strateg.Collect(target1.barrel).FireTo(barrelToFire?.barrel.fcoord); return; } if (target2 != null && target1 == null) { var barrelToFire = barrels2.TakeWhile(b => b != target2).LastOrDefault(); strateg.decisions[ship2.id] = strateg.Collect(target2.barrel).FireTo(barrelToFire?.barrel.fcoord); return; } if (target1.barrel != target2.barrel) { var barrelToFire1 = barrels1.TakeWhile(b => b.barrel != target1.barrel && b.barrel != target2.barrel).LastOrDefault(); strateg.decisions[ship1.id] = strateg.Collect(target1.barrel).FireTo(barrelToFire1?.barrel.fcoord); var barrelToFire2 = barrels2.TakeWhile(b => b.barrel != target1.barrel && b.barrel != target2.barrel && b.barrel != barrelToFire1?.barrel).LastOrDefault(); strateg.decisions[ship2.id] = strateg.Collect(target2.barrel).FireTo(barrelToFire2?.barrel.fcoord); return; } var dist1 = Math.Min(FastShipPosition.DistanceTo(nextShip1Position1, target1.barrel.fcoord), FastShipPosition.DistanceTo(nextShip1Position2, target1.barrel.fcoord)); var dist2 = Math.Min(FastShipPosition.DistanceTo(nextShip2Position1, target1.barrel.fcoord), FastShipPosition.DistanceTo(nextShip2Position2, target1.barrel.fcoord)); if (dist1 < dist2) { target2 = barrels2.FirstOrDefault( b => b.barrel != target1.barrel && (FastShipPosition.DistanceTo(nextShip2Position1, b.barrel.fcoord) < b.dist - 1 || FastShipPosition.DistanceTo(nextShip2Position2, b.barrel.fcoord) < b.dist - 1)); } else { target1 = barrels1.FirstOrDefault( b => b.barrel != target2.barrel && (FastShipPosition.DistanceTo(nextShip1Position1, b.barrel.fcoord) < b.dist - 1 || FastShipPosition.DistanceTo(nextShip1Position2, b.barrel.fcoord) < b.dist - 1)); } } }