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));
        }
示例#2
0
        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));
                }
            }
        }
        public void MakeStrategicDecisions(TurnState turnState)
        {
            if (turnState.barrels.Any())
            {
                strateg.MakeStandardStrategicDecisions(turnState);
                return;
            }

            if (turnState.myShips.Max(s => s.rum) > turnState.enemyShips.Max(s => s.rum) || turnState.myShips.Min(s => s.rum) > 50)
            {
                foreach (var ship in turnState.myShips)
                {
                    StrategicDecision prevDecision;
                    strateg.decisions.TryGetValue(ship.id, out prevDecision);
                    strateg.decisions[ship.id] = strateg.RunAway(turnState, ship, prevDecision);
                }
                return;
            }

            if (turnState.myShips.Count == 1)
            {
                var ship = turnState.myShips[0];
                StrategicDecision prevDecision;
                strateg.decisions.TryGetValue(ship.id, out prevDecision);
                strateg.decisions[ship.id] = strateg.RunAway(turnState, ship, prevDecision);
                return;
            }

            var maxRum = turnState.myShips.Max(s => s.rum);
            var minRum = turnState.myShips.Min(s => s.rum);
            var ship1  = turnState.myShips.First(s => s.rum == minRum);
            var ship2  = turnState.myShips.Last(s => s.rum == maxRum);
            var last   = turnState.myShips.FirstOrDefault(s => s != ship1 && s != ship2);

            if (last != null)
            {
                StrategicDecision prevDecision;
                strateg.decisions.TryGetValue(last.id, out prevDecision);
                strateg.decisions[last.id] = strateg.RunAway(turnState, last, prevDecision);
            }

            if (FastCoord.Distance(ship1.fbow, ship2.fbow) <= 4)
            {
                StrategicDecision prevDecision;
                strateg.decisions.TryGetValue(ship1.id, out prevDecision);
                if (prevDecision?.role == StrategicRole.Fire || prevDecision?.role == StrategicRole.Explicit)
                {
                    strateg.decisions[ship1.id] = new StrategicDecision {
                        role = StrategicRole.Explicit, explicitCommand = ShipMoveCommand.Slower
                    };
                    strateg.decisions[ship2.id] = new StrategicDecision {
                        role = StrategicRole.Approach, targetCoord = prevDecision.fireToCoord
                    };
                }
                else
                {
                    var nextShip1Position = FastShipPosition.GetFinalPosition(FastShipPosition.Move(ship1.fposition, ShipMoveCommand.Wait));
                    nextShip1Position           = FastShipPosition.GetFinalPosition(FastShipPosition.Move(nextShip1Position, ShipMoveCommand.Slower));
                    strateg.decisions[ship1.id] = new StrategicDecision {
                        role = StrategicRole.Fire, fireToCoord = FastShipPosition.Coord(nextShip1Position)
                    };
                    strateg.decisions[ship2.id] = new StrategicDecision {
                        role = StrategicRole.Approach, targetCoord = FastShipPosition.Coord(nextShip1Position)
                    };
                }
            }
            else
            {
                var x = (FastCoord.GetX(ship1.fcoord) + FastCoord.GetX(ship2.fcoord)) / 2;
                var y = (FastCoord.GetY(ship1.fcoord) + FastCoord.GetY(ship2.fcoord)) / 2;
                if (x < 5)
                {
                    x = 5;
                }
                if (x > Constants.MAP_WIDTH - 6)
                {
                    x = Constants.MAP_WIDTH - 6;
                }
                if (y < 5)
                {
                    y = 5;
                }
                if (y > Constants.MAP_HEIGHT - 6)
                {
                    x = Constants.MAP_HEIGHT - 6;
                }

                strateg.decisions[ship1.id] = new StrategicDecision {
                    role = StrategicRole.Approach, targetCoord = FastCoord.Create(x, y)
                };
                strateg.decisions[ship2.id] = new StrategicDecision {
                    role = StrategicRole.Approach, targetCoord = FastCoord.Create(x, y)
                };
            }
        }