Пример #1
0
        public List <Ship> ShipsOnDropoffs()
        {
            var myShips = new List <Ship>();

            foreach (var drop in GetDropoffs())
            {
                var shipOnDrop = GameInfo.CellAt(drop).ship;
                if (shipOnDrop != null && shipOnDrop.owner.Equals(id))
                {
                    myShips.Add(shipOnDrop);
                }
            }
            return(myShips);
        }
Пример #2
0
            public Command GetMove()
            {
                var dirs = valuer.Target.position.GetAllDirectionsTo(ship.position);

                dirs = dirs.OrderBy(d => GameInfo.CellAt(ship.position.DirectionalOffset(d)).halite).ToList();
                if (dirs.Count == 1 && GameInfo.Distance(ship, valuer.Target.position) > 1)
                {
                    var extraDirs = DirectionExtensions.GetLeftRightDirections(dirs[0]);
                    dirs.AddRange(extraDirs);
                }
                foreach (var d in dirs)
                {
                    var cell = GameInfo.CellAt(ship, d);
                    if (Safety.IsSafeAndAvoids2Cells(ship, d) && Navigation.IsAccessible(cell.position, valuer.Target.position))
                    {
                        return(ship.Move(d, $"moving towards best projection {valuer.Target.position.ToString()}... Expected turns: {numTurns}"));
                    }
                }
                return(null);
            }
Пример #3
0
        public override void CommandShips()
        {
            var prevShipAssignments  = ShipAssignments;
            var prevPointAssignments = PointAssignments;

            ShipAssignments  = new Dictionary <Ship, Assignment>();
            PointAssignments = new Dictionary <Point, Assignment>();

            // stay still...
            foreach (var s in Fleet.AvailableShips.Where(s => !s.CanMove))
            {
                Fleet.AddMove(s.StayStill("Ship cannot move, forcing it to stay still..."));
            }

            // select targets
            Queue <Ship> queue = new Queue <Ship>();

            Fleet.AvailableShips.ForEach(s => queue.Enqueue(s));

            while (queue.Count > 0)
            {
                var     s       = queue.Dequeue();
                var     xLayers = GameInfo.RateLimitXLayers(15);
                var     cells   = GameInfo.Map.GetXLayers(s.position, xLayers);
                MapCell target  = s.CurrentMapCell;
                int     maxVal  = GetCellValue(s, target);
                do
                {
                    foreach (var c in cells)
                    {
                        var otherAssign = PointAssignments.ContainsKey(c.position.AsPoint) ? PointAssignments[c.position.AsPoint] : null;
                        if (otherAssign != null && GameInfo.Distance(s, c.position) >= otherAssign.Distance)
                        {
                            continue;
                        }

                        // value calculation...
                        int val = GetCellValue(s, c);
                        if (prevPointAssignments.ContainsKey(c.position.AsPoint) && prevPointAssignments[c.position.AsPoint].Ship.Id == s.Id)
                        {
                            val = (int)(val * 1.1);
                        }
                        int distDiff = GameInfo.Distance(s, c.position) - GameInfo.Distance(s, target.position);
                        int oppCost  = distDiff < 0 ? distDiff * (int)(c.halite * .125) : // cell is closet to ship than curTarget
                                       distDiff * (int)(target.halite * .125);            // distDiff is 0/positive, cell is further than curTarget
                        if (val - oppCost > maxVal && Navigation.IsAccessible(s.position, c.position))
                        {
                            maxVal = val;
                            target = c;
                        }
                    }
                    xLayers++;
                    cells = GameInfo.GetXLayersExclusive(s.position, xLayers);
                } while(target == null && xLayers <= Math.Min(GameInfo.Map.width, GameInfo.RateLimitXLayers(xLayers)));

                if (target != null)
                {
                    var otherTarget = AssignAndReturnPrevAssignIfAny(s, target);
                    if (otherTarget != null)
                    {
                        queue.Enqueue(otherTarget.Ship);
                    }
                }
            }
            var vals = ShipAssignments.Values.OrderBy(a => a.Distance);

            foreach (var a in vals)
            {
                var dirs = a.Target.position.GetAllDirectionsTo(a.Ship.position);
                dirs = dirs.OrderBy(d => GameInfo.CellAt(a.Ship, d).halite).ToList();
                if (dirs.Any(d => Safety.IsSafeMove(a.Ship, d)))
                {
                    var dir = dirs.First(d => Safety.IsSafeMove(a.Ship, d));
                    Fleet.AddMove(a.Ship.Move(dir, $"Moving to best target {a.Target.position.ToString()} End Game Collect Logic"));
                }
            }
        }