SendMoves() публичный статический Метод

Call to send your move orders and complete your turn.
public static SendMoves ( IEnumerable moves ) : void
moves IEnumerable
Результат void
Пример #1
0
    //public ushort treshold = 20;

    public static void Main(string[] args)
    {
        //Log.Setup(@"C:\Users\phili\Desktop\Coveo-Blitz-2018\CSharp\log.txt");

        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);
        ushort myID;
        Map    map = Networking.getInit(out myID);
        MyBot  bot = new MyBot(myID);

        bot.map = map;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */
        bot.Analyze();

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        while (true)
        {
            Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            bot.map = map;

            List <Move> moves;
            bot.ComputeMove(out moves);

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #2
0
    public void Run()
    {
        mMap = Networking.getInit(out mBotID);

        InitSiteNeighbors();
        CalculateExpansionValue();

        Networking.SendInit(BOT_NAME);

        while (true)
        {
            string line = Console.ReadLine();
            if (line == null)
            {
                break;
            }

            mMap.Update(line);

            PrepareSites();
            CalculateMaps();
            DoMoves();
            ReviewMoves();

            Networking.SendMoves(mMySites);

            mRound++;
        }
    }
Пример #3
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort myID;
        var    map = Networking.getInit(out myID);
        var    bot = new IntelligentBotV8(map, myID);

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        try
        {
            while (true)
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn

                IEnumerable <Move> moves = bot.GetMoves();

                Networking.SendMoves(moves); // Send moves
            }
        }
        catch (Exception ex)
        {
        }
    }
Пример #4
0
        private static void PlayTurn()
        {
            turnCount++;
            Log.LogMessage($"Starting turn: {turnCount}");

            Turn turn = TurnFactory.CreateTurn(gameMap, turnCount);

            Networking.SendMoves(turn.Play());
        }
Пример #5
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "T-800";

            _gameMap = Networking.Initialize(name);

            for (;;)
            {
                _moveList.Clear();
                _gameMap.UpdateMap(Networking.ReadLineIntoMetadata());
                _allPlanetsAreOwned = _gameMap.Planets.Values.All(p => p.IsOwned());
                _player             = _gameMap.GetMyPlayer();

                var ships            = _player.Ships.Values;
                var currentMissions  = ships.Where(s => _missions.ContainsKey(s.Id)).ToList();
                var obsoleteMissions = _missions.Keys.Where(k => !_player.Ships.Keys.Contains(k)).ToList();
                foreach (var k in obsoleteMissions)
                {
                    _missions.Remove(k);
                }

                foreach (var ship in currentMissions)
                {
                    try
                    {
                        UpdateMission(ship);
                    }
                    catch (Exception e)
                    {
                        DebugLog.AddLog($"UpdateMission: {e.Message}");
                    }
                }

                foreach (var ship in ships.Except(currentMissions))
                {
                    try
                    {
                        AssignMission(ship);
                    }
                    catch (Exception e)
                    {
                        DebugLog.AddLog($"AssignMission: {e.Message}");
                    }
                }

                Networking.SendMoves(_moveList);
            }
        }
Пример #6
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Tamagocchi";

            Networking networking = new Networking();
            GameMap    gameMap    = networking.Initialize(name);

            List <Move> moveList = new List <Move>();

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    foreach (Planet planet in gameMap.GetAllPlanets().Values)
                    {
                        if (planet.IsOwned())
                        {
                            continue;
                        }

                        if (ship.CanDock(planet))
                        {
                            moveList.Add(new DockMove(ship, planet));
                            break;
                        }

                        ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED / 2);
                        if (newThrustMove != null)
                        {
                            moveList.Add(newThrustMove);
                        }

                        break;
                    }
                }
                Networking.SendMoves(moveList);
            }
        }
Пример #7
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort myID;
        var    map = Networking.getInit(out myID);

        Networking.SendInit(RandomBotName);

        var random = new Random();

        while (true)
        {
            try
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            }
            catch (Exception)
            {
                return;
            }

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        moves.Add(new Move {
                            Location = new Location {
                                X = x, Y = y
                            },
                            Direction = (Direction)random.Next(5)
                        });
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #8
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Galcon";

            Networking networking = new Networking();
            GameMap    gameMap    = networking.Initialize(name);

            List <Move> moveList = new List <Move>();

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                var ships = gameMap.GetMyPlayer().GetShips().Values;

                InitTurn(gameMap, moveList, ships);
                Networking.SendMoves(moveList);
            }
        }
Пример #9
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort myID;
        var    map = Networking.getInit(out myID);

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        while (true)
        {
            Networking.getFrame(ref map); // Update the map to reflect the moves before this turn

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        moves.Add(new Move {
                            Location = new Location {
                                X = x, Y = y
                            },
                            Direction = (Direction)random.Next(5)
                        });
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #10
0
        public static void Main(string[] args)
        {
            Networking networking = new Networking();
            var        gameMaster = GameMaster.Initialize(networking.Initialize("Meucci"));

            List <Move> moveList = new List <Move>();

            while (true)
            {
                moveList.Clear();
                var readLineIntoMetadata = Networking.ReadLineIntoMetadata();
                gameMaster.UpdateGame(readLineIntoMetadata);
                var gameMap = gameMaster.GameMap;

                int shipCount = 0;
                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    var bestMove = GetBestMoveToUnclaimedPlanet(gameMaster, ship);
                    var nextMove = GetBestMoveToClaimedPlanet(gameMaster, ship, shipCount++);

                    if (nextMove != null && nextMove.CompareTo(bestMove) > 0)
                    {
                        bestMove = nextMove;
                    }

                    if (bestMove != null)
                    {
                        moveList.Add(bestMove.Move);
                    }
                }

                Networking.SendMoves(moveList);
            }
        }
Пример #11
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        //File.Delete("Aronbot.log");
        //Log.Setup("Aronbot.log");

        map = Networking.getInit(out myID);

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        while (true)
        {
            Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            var moves = new List <Move>();
            map.ResetCache();

            //Log.Information($"Move: {move++}");
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        moves.Add(Move(new Location {
                            X = x, Y = y
                        }));
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #12
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort       myID;
        var          map           = Networking.getInit(out myID);
        const ushort MAX_STRENGTH  = 255;
        const ushort HALF_STRENGTH = 128;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        //var logFileName = string.Format(@"C:\Users\dolson\Source\Halite\Halite-C#-Starter-Package\Halite-C#-Starter-Package\log{0}.txt", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
        var logFileName = string.Format("log{0}.txt", DateTime.Now.Ticks);

        AppendLog(logFileName, "Starting battle!");
        int frameNumber = 0;

        while (true)
        {
            try
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            }
            catch (Exception)
            {
                return;
            }

            frameNumber++;

            AppendLog(logFileName, string.Format("Frame {0}", frameNumber));

            //Try to attack in a straight line to achive maximum "overkill"
            var previousAttackDirectionByLocation = new Dictionary <Location, Direction>();

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        var activeSite = new SiteEx(map, x, y);

                        var neighbors = new List <SiteEx>()
                        {
                            GetNeighbor(map, activeSite, Direction.West),
                            GetNeighbor(map, activeSite, Direction.East),
                            GetNeighbor(map, activeSite, Direction.North),
                            GetNeighbor(map, activeSite, Direction.South)
                        };

                        var friendlySites       = neighbors.Where(c => c.Owner == myID);
                        var potentialLunchSites =
                            neighbors.Where(c => c.Strength < activeSite.Strength && c.Owner != myID);
                        var killSites   = potentialLunchSites.Where(c => c.Owner != 0);
                        var dangerSites =
                            neighbors.Where(c => c.Strength > activeSite.Strength && c.Owner != myID && c.Owner != 0); //TODO: what to do with danger sites?


                        //1. Continue an attack spearhead from previous turn first
                        if (previousAttackDirectionByLocation.ContainsKey(activeSite.Location))
                        {
                            var directionToMove = previousAttackDirectionByLocation[activeSite.Location];
                            previousAttackDirectionByLocation.Remove(activeSite.Location);

                            var neighbor = GetNeighbor(map, activeSite, directionToMove);
                            if (neighbor.Owner != myID && neighbor.Owner != 0)
                            {
                                previousAttackDirectionByLocation.Add(neighbor.Location, directionToMove);
                            }

                            moves.Add(new Move
                            {
                                Location  = activeSite.Location,
                                Direction = directionToMove
                            });
                        }
                        //2. Try to kill anything in sight
                        else if (killSites.Any())
                        {
                            var killSite        = killSites.First();
                            var directionToMove = GetMoveDirection(map, activeSite, killSite);


                            //AppendLog(logFileName, string.Format("Attack from [{0},{1}] (strength {4}) to [{2},{3}] (strength {5})",
                            //    activeSite.X, activeSite.Y, killSite.X, killSite.Y, activeSite.Strength,
                            //    killSite.Strength));

                            previousAttackDirectionByLocation.Add(GetNeighbor(map, activeSite, directionToMove).Location, directionToMove);

                            moves.Add(new Move
                            {
                                Location  = activeSite.Location,
                                Direction = directionToMove
                            });
                        }
                        //3. Try to take over neutral
                        else if (potentialLunchSites.Any())
                        {
                            var lunchSite       = potentialLunchSites.OrderByDescending(s => s.Production).First();
                            var directionToMove = GetMoveDirection(map, activeSite, lunchSite);

                            //AppendLog(logFileName, string.Format(
                            //    "Consume Neutral from [{0},{1}] (strength {4}) to [{2},{3}] (strength {5})",
                            //    activeSite.X, activeSite.Y, lunchSite.X, lunchSite.Y, activeSite.Strength,
                            //    lunchSite.Strength));


                            moves.Add(new Move
                            {
                                Location  = activeSite.Location,
                                Direction = directionToMove
                            });
                        }
                        //3. Find a buddy to merge with
                        //else if (friendlySites.Any(c => c.Strength < activeSite.Strength && c.Strength + activeSite.Strength > 25) && activeSite.Strength > 10)
                        //{
                        //    var friendSite = friendlySites.FirstOrDefault(c => c.Strength < activeSite.Strength && c.Strength + activeSite.Strength > 25);
                        //    var directionToMove = GetMoveDirection(map, activeSite, friendSite);

                        //    moves.Add(new Move
                        //    {
                        //        Location = activeSite.Location,
                        //        Direction = directionToMove
                        //    });
                        //}



                        //4. If all neighbors are friendly, move towards nearest edge.
                        else if (friendlySites.Count() == neighbors.Count && ((activeSite.Strength >= (activeSite.Production * 5)) || activeSite.Strength > HALF_STRENGTH))
                        {
                            var nearestNonPlayerDirection = GetNearestNonPlayerDirection(map, activeSite, myID);
                            if (nearestNonPlayerDirection != Direction.Still)
                            {
                                //AppendLog(logFileName, string.Format("Move to edge from [{0},{1}] (strength {3}) to {2}",
                                //    activeSite.X, activeSite.Y, nearestNonPlayerDirection, activeSite.Strength));

                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = nearestNonPlayerDirection
                                });
                            }
                            else //All orthagonal directions are occupied.
                            {
                                //TODO: could have logic here to find enemies or something, or go diagonally.
                            }
                        }

                        ////4. TODO: If large enough, move towards the closest neutral edge.
                        ////5. if all else fails, move randomly.
                        //else if (neighbors.Any(n => n.Strength < activeSite.Strength))
                        //{
                        //    moves.Add(new Move
                        //    {
                        //        Location = new Location { X = x, Y = y },
                        //        Direction = (Direction)random.Next(5)
                        //    });
                        //}
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #13
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort       myID;
        var          map           = Networking.getInit(out myID);
        const ushort MAX_STRENGTH  = 255;
        const ushort HALF_STRENGTH = 128;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        //var logFileName = string.Format(@"C:\Users\dolson\Source\Halite\Halite-C#-Starter-Package\Halite-C#-Starter-Package\log{0}.txt", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
        var logFileName = string.Format("log{0}.txt", DateTime.Now.Ticks);

        AppendLog(logFileName, "Starting battle!");
        int frameNumber = 0;

        while (true)
        {
            MySites.Clear();
            AllSites.Clear();

            try
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            }
            catch (Exception)
            {
                return;
            }

            frameNumber++;

            var moves = new List <Move>();
            AppendLog(logFileName, string.Format("Frame {0}", frameNumber));

            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        MySites.Add(new SiteEx(map, x, y));
                    }

                    AllSites.Add(new SiteEx(map, x, y));
                }
            }

            foreach (var mySite in MySites.ToArray())
            {
                ushort distanceFromEdge;
                var    dir = GetNearestNonPlayerDirection(map, mySite, myID, out distanceFromEdge);
                mySite.DistanceFromEdge     = distanceFromEdge;
                mySite.NearestEdgeDirection = dir;
            }

            foreach (var mySite in MySites.OrderBy(s => s.DistanceFromEdge).ToArray())
            {
                if (mySite.DistanceFromEdge <= 1)
                {
                    var neighbors = GetAllNeighbors(map, mySite);
                    var closestToConsumeNeighbor =
                        neighbors.Where(n => n.IsEnemy(myID) || n.IsNeutral)
                        .OrderByDescending(n => (n.Production * 1.5) + n.Strength).First();

                    if (mySite.Strength > closestToConsumeNeighbor.Strength)
                    {
                        moves.Add(new Move
                        {
                            Location  = mySite.Location,
                            Direction = GetMoveDirection(map, mySite, closestToConsumeNeighbor)
                        });

                        mySite.IntendedLocation =
                            closestToConsumeNeighbor.Location;
                    }
                    else //Try and work together with a neighbor?
                    {
                    }
                }
                else if (mySite.Strength >= HALF_STRENGTH)
                {
                    moves.Add(new Move
                    {
                        Location  = mySite.Location,
                        Direction = mySite.NearestEdgeDirection ?? Direction.Still
                    });

                    mySite.IntendedLocation =
                        GetNeighbor(map, mySite, mySite.NearestEdgeDirection ?? Direction.Still).Location;
                }
            }



            //for (ushort x = 0; x < map.Width; x++)
            //{
            //    for (ushort y = 0; y < map.Height; y++)
            //    {
            //        if (map[x, y].Owner == myID)
            //        {
            //            var activeSite = new SiteEx(map, x, y);

            //            var neighbors = new List<SiteEx>()
            //            {
            //                GetNeighbor(map, activeSite, Direction.West),
            //                GetNeighbor(map, activeSite, Direction.East),
            //                GetNeighbor(map, activeSite, Direction.North),
            //                GetNeighbor(map, activeSite, Direction.South)
            //            };

            //            var friendlySites = neighbors.Where(c => c.Owner == myID);
            //            var potentialLunchSites =
            //                neighbors.Where(c => c.Strength < activeSite.Strength && c.Owner != myID);
            //            var killSites = potentialLunchSites.Where(c => c.Owner != 0);
            //            var dangerSites =
            //                neighbors.Where(c => c.Strength > activeSite.Strength && c.Owner != myID && c.Owner != 0); //TODO: what to do with danger sites?

            //            //Try to kill anything in sight
            //            if (killSites.Any())
            //            {
            //                var killSite = killSites.First();
            //                var directionToMove = GetMoveDirection(map, activeSite, killSite);

            //                moves.Add(new Move
            //                {
            //                    Location = activeSite.Location,
            //                    Direction = directionToMove
            //                });
            //            }
            //            //Try to take over neutral
            //            else if (potentialLunchSites.Any())
            //            {
            //                var lunchSite = potentialLunchSites.OrderByDescending(s => s.Production).First();
            //                var directionToMove = GetMoveDirection(map, activeSite, lunchSite);

            //                //AppendLog(logFileName, string.Format(
            //                //    "Consume Neutral from [{0},{1}] (strength {4}) to [{2},{3}] (strength {5})",
            //                //    activeSite.X, activeSite.Y, lunchSite.X, lunchSite.Y, activeSite.Strength,
            //                //    lunchSite.Strength));


            //                moves.Add(new Move
            //                {
            //                    Location = activeSite.Location,
            //                    Direction = directionToMove
            //                });
            //            }
            //            //Find a buddy to merge with
            //            //else if (friendlySites.Any(c => c.Strength < activeSite.Strength && c.Strength + activeSite.Strength > 25) && activeSite.Strength > 10)
            //            //{
            //            //    var friendSite = friendlySites.FirstOrDefault(c => c.Strength < activeSite.Strength && c.Strength + activeSite.Strength > 25);
            //            //    var directionToMove = GetMoveDirection(map, activeSite, friendSite);

            //            //    moves.Add(new Move
            //            //    {
            //            //        Location = activeSite.Location,
            //            //        Direction = directionToMove
            //            //    });
            //            //}



            //            //If all neighbors are friendly, move towards nearest edge.
            //            else if (friendlySites.Count() == neighbors.Count && ((activeSite.Strength >= (activeSite.Production * 5)) || activeSite.Strength > HALF_STRENGTH))
            //            {
            //                var nearestNonPlayerDirection = GetNearestNonPlayerDirection(map, activeSite, myID);
            //                if (nearestNonPlayerDirection != Direction.Still)
            //                {
            //                    //AppendLog(logFileName, string.Format("Move to edge from [{0},{1}] (strength {3}) to {2}",
            //                    //    activeSite.X, activeSite.Y, nearestNonPlayerDirection, activeSite.Strength));

            //                    moves.Add(new Move
            //                    {
            //                        Location = activeSite.Location,
            //                        Direction = nearestNonPlayerDirection
            //                    });
            //                }
            //                else //All orthagonal directions are occupied.
            //                {
            //                    //TODO: could have logic here to find enemies or something, or go diagonally.
            //                }
            //            }

            //            ////4. TODO: If large enough, move towards the closest neutral edge.
            //            ////5. if all else fails, move randomly.
            //            //else if (neighbors.Any(n => n.Strength < activeSite.Strength))
            //            //{
            //            //    moves.Add(new Move
            //            //    {
            //            //        Location = new Location { X = x, Y = y },
            //            //        Direction = (Direction)random.Next(5)
            //            //    });
            //            //}



            //        }
            //    }
            //}

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #14
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort myID;
        var    map = Networking.getInit(out myID);

        // ***********************************************************************
        //    Do more prep work, see rules for time limit

        Log.Setup("error.log");


        ushort turnCount  = 0;
        byte   UnitsMoved = 0;

        float AggressivenessFactor = (float)0.01;

        ushort MapHeight = map.Height;
        ushort MapWidth  = map.Width;
        ushort MapArea   = (ushort)(MapHeight * MapWidth);

        ushort MyTotalUnits        = 0;
        ushort TurnsToMove         = 5;
        float  PercentOfMapToGrab  = (float)0.10;
        ushort MaxTopTargetsToGrab = (ushort)(PercentOfMapToGrab * MapArea); // max targets to grab
        ushort MaxUnitsToMove      = 350;                                    //MaxUnitsToMove units that will use move

        if (MapArea > 1500)
        {
            TurnsToMove = 5;
        }
        else if (MapArea > 1000)
        {
            TurnsToMove = 6;
        }
        else
        {
            TurnsToMove = 6;
        }

        List <SiteInfo> MyUnitsEligibleToMove    = new List <SiteInfo>();
        List <SiteInfo> MyTopUnitsEligibleToMove = new List <SiteInfo>();

        List <SiteInfo> DesireableTargets         = new List <SiteInfo>();
        List <SiteInfo> TopDesireableTargets      = new List <SiteInfo>();
        List <SiteInfo> ModifiedDesireableTargets = new List <SiteInfo>();


        // ***********************************************************************

        Networking.SendInit(MyBotName); // Acknowledge the init and begin the game



        var random = new Random();

        while (true)
        {
            Networking.getFrame(ref map); // Update the map to reflect the moves before this turn

            turnCount++;
            UnitsMoved   = 0;
            MyTotalUnits = 0;

            //Log.Information(String.Format("Best Direction: {0}", map.FindAttackableEnemies(2, 2, myID) ));

            //Reset Variables
            DesireableTargets.Clear();
            ModifiedDesireableTargets.Clear();
            MyUnitsEligibleToMove.Clear();
            MyTopUnitsEligibleToMove.Clear();
            TopDesireableTargets.Clear();

            // first we want to build a desireable map and list so that we can gather the most desireable targets for aStar.
            var moves = new List <Move>();

            AggressivenessFactor = map.GetAggroLevel(myID);

            // collect targets and units
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    float desirableness = 0;

                    if (map[x, y].Owner != myID && map[x, y].Owner != 0)
                    {
                        // determine desirable targets list desirableness
                        desirableness = (float)((100 / (map[x, y].Production + 1)) / AggressivenessFactor);
                        DesireableTargets.Add(new SiteInfo(desirableness, x, y));
                    }
                    else if (map[x, y].Owner == 0)
                    {
                        // determine desirable targets list desirableness
                        desirableness = (float)(map[x, y].Strength / (map[x, y].Production + 1));
                        DesireableTargets.Add(new SiteInfo(desirableness, x, y));
                    }
                    else // if it is me
                    {
                        // if it is my own unit it is not eligible to be a target
                        MyTotalUnits++;

                        if (map[x, y].Strength >= map[x, y].Production * TurnsToMove)
                        {
                            // If is my unit and it has the strength to move add it to the MyUnitsEligibleToMove list
                            MyUnitsEligibleToMove.Add(new SiteInfo(map[x, y].Strength, x, y));
                        }
                    }
                }
            }



            // sort my eligible units to move by strength (In MyUnitsEligibleToMove Desirableness represents the strength of the unit)
            MyUnitsEligibleToMove = MyUnitsEligibleToMove.OrderByDescending(a => a.Desirableness).ToList();
            // only grab top so many targets
            DesireableTargets = DesireableTargets.OrderBy(a => a.Desirableness).ToList();

            ushort NumOfTargetsToGrab = 0;
            if (DesireableTargets.Count <= MaxTopTargetsToGrab)
            {
                NumOfTargetsToGrab = (ushort)(DesireableTargets.Count);
            }
            else
            {
                NumOfTargetsToGrab = MaxTopTargetsToGrab;
            }

            TopDesireableTargets = DesireableTargets.GetRange(0, NumOfTargetsToGrab);



            ushort NumOfTargetsToMove = 0;
            if (MyUnitsEligibleToMove.Count <= MaxUnitsToMove)
            {
                NumOfTargetsToMove = (ushort)(MyUnitsEligibleToMove.Count);
            }
            else
            {
                NumOfTargetsToMove = MaxUnitsToMove;
            }

            MyTopUnitsEligibleToMove = MyUnitsEligibleToMove.GetRange(0, NumOfTargetsToMove);



            foreach (SiteInfo Unit in MyTopUnitsEligibleToMove)
            {
                ushort   DistBetweenUnitAndTarget = 0;
                SiteInfo TopTarget = new SiteInfo(0, 0, 0);

                ModifiedDesireableTargets.Clear();

                // calculate desirable map based on the distance from each unit to each target
                foreach (SiteInfo Target in TopDesireableTargets)
                {
                    DistBetweenUnitAndTarget = map.CalcDistance(Unit.X, Unit.Y, Target.X, Target.Y);

                    float tempDesiredness = DistBetweenUnitAndTarget + Target.Desirableness;

                    ModifiedDesireableTargets.Add(new SiteInfo(tempDesiredness, Target.X, Target.Y));
                }

                ModifiedDesireableTargets = ModifiedDesireableTargets.OrderBy(a => a.Desirableness).ToList();

                Direction GoDirection = DoMove(new Location {
                    X = ModifiedDesireableTargets.First().X, Y = ModifiedDesireableTargets.First().Y
                }, Unit.X, Unit.Y, ref map, myID);

                UnitsMoved++;
                moves.Add(new Move
                {
                    Location = new Location {
                        X = Unit.X, Y = Unit.Y
                    },
                    Direction = GoDirection
                });
            }

            //Log.Information("sending moves");
            Networking.SendMoves(moves); // Send moves
            moves.Clear();
        }
    }
Пример #15
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        try
        {
            var map = Networking.getInit(out _MyID);
            DarreksLog.LogFileName = String.Format("log{0}.txt", _MyID);
            _MaxScanDistance       = (ushort)(map.Width / 4);



            #region Check Production before game start

            var sb = new StringBuilder();
            sb.Append("production values:");

            //TODO: find nearest high production zone and head there.
            for (ushort y = 0; y < map.Height; y++)
            {
                sb.Append("\r\n");
                for (ushort x = 0; x < map.Width; x++)
                {
                    var prodVal = map[x, y].Production;

                    sb.Append(prodVal + " ");

                    if (_MaxProductionValue < prodVal)
                    {
                        _MaxProductionValue = prodVal;
                    }
                }
            }

            //DarreksLog.AppendLog(sb.ToString());

            _TopProductionValuesGreaterThan = (ushort)(_MaxProductionValue * .75);

            DarreksLog.AppendLog(string.Format("Max Production Value Found = {0}", _MaxProductionValue));
            DarreksLog.AppendLog(string.Format("Top Production Values >= {0}", _TopProductionValuesGreaterThan));

            #endregion



            LinkedList <Location> currentSnakePath = null;
            bool currentSnakePathIsCompleted       = true;

            /* ------
            *   Do more prep work, see rules for time limit
            *  ------ */

            sb.Clear();
            sb.Append("Value to Me:");
            var valueMap = new short[map.Width, map.Height];
            for (ushort y = 0; y < map.Height; y++)
            {
                sb.Append("\r\n");
                for (ushort x = 0; x < map.Width; x++)
                {
                    var activeSite = map[x, y];
                    valueMap[x, y] = GetValueOfSite(activeSite);
                    sb.Append(valueMap[x, y] + " ");
                }
            }
            //DarreksLog.AppendLog(sb.ToString());

            var gaussianValueMap = GetGaussianValueMap(valueMap, map.Width, map.Height);

            sb.Clear();
            sb.Append("Gaussian Values:");
            for (ushort y = 0; y < map.Height; y++)
            {
                sb.Append("\r\n");
                for (ushort x = 0; x < map.Width; x++)
                {
                    sb.Append(gaussianValueMap[x, y] + " ");
                }
            }

            DarreksLog.AppendLog(sb.ToString());

            Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

            var random = new Random();

            DarreksLog.AppendLog("Starting battle!");
            int      frameNumber   = 0;
            Location startLocation = new Location(0, 0);

            while (true)
            {
                try
                {
                    Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
                }
                catch (Exception)
                {
                    return;
                }

                frameNumber++;
                DarreksLog.AppendLog(string.Format("Frame {0}", frameNumber));

                var moves = new HashSet <Move>();


                for (ushort x = 0; x < map.Width; x++)
                {
                    for (ushort y = 0; y < map.Height; y++)
                    {
                        if (map[x, y].Owner == _MyID)
                        {
                            //DarreksLog.AppendLog("GetProductionSeekerBotMove...");
                            var move = GetProductionSeekerBotMove(map, x, y);
                            if (move.HasValue)
                            {
                                //DarreksLog.AppendLog(String.Format("Added Move {0},{1}->{2}...", move.Value.Location.X, move.Value.Location.Y, move.Value.Direction));
                                moves.Add(move.Value);
                            }

                            if (frameNumber == 1)
                            {
                                startLocation = new Location(x, y);
                            }
                        }
                    }
                }



                #region Pick new Snake Destination

                if (currentSnakePathIsCompleted && frameNumber < 10)
                {
                    //we have a notion of the "head" of the line (linkedlist), and also which locations are feeding into it. These locations should all just send their resources through towards the head.
                    //TODO: when the snake moves, the new location becomes the head, and drop the tail if longer than the limit

                    //TODO: as the size grows, multiple lines could exist to search out the best production zones.


                    currentSnakePathIsCompleted = false;

                    DarreksLog.AppendLog("Setting Snake Destination...");

                    var snakeStartLocation = currentSnakePath == null
                        ? startLocation
                        : currentSnakePath.Last.Value;

                    DarreksLog.AppendLog(string.Format("Starting at {0},{1}", snakeStartLocation.X, snakeStartLocation.Y));
                    var snakeDestination = GetNearestFreeHighProductionDirection(map, gaussianValueMap, snakeStartLocation);
                    DarreksLog.AppendLog(string.Format("Snake Destination Set to {0},{1}. Production there is {2}", snakeDestination.X, snakeDestination.Y, map[snakeDestination].Production));

                    DarreksLog.AppendLog("Getting Snake's Best Path To Destination...");

                    var newPathBits = GetBestPathToLocation(map, gaussianValueMap, snakeStartLocation, snakeDestination);
                    if (currentSnakePath == null)
                    {
                        currentSnakePath = newPathBits;
                    }
                    else
                    {
                        foreach (var newPathBit in newPathBits)
                        {
                            if (!currentSnakePath.Last.Value.Equals(newPathBit))
                            {
                                currentSnakePath.AddLast(newPathBit);
                            }
                        }


                        //Remove duplicates in the path
                        var locationsInSnake = new HashSet <Location>();
                        var looker           = currentSnakePath.Last;

                        do
                        {
                            DarreksLog.AppendLog("Checking for looping in the snake.");

                            if (locationsInSnake.Contains(looker.Value))
                            {
                                DarreksLog.AppendLog(string.Format("Found a loop on {0},{1}.", looker.Value.X, looker.Value.Y));
                                do
                                {
                                    currentSnakePath.RemoveFirst();
                                } while (!currentSnakePath.First.Value.Equals(looker.Value));
                                currentSnakePath.RemoveFirst();
                                if (currentSnakePath.Count <= 1)
                                {
                                    currentSnakePathIsCompleted = true;
                                }
                            }
                            else
                            {
                                locationsInSnake.Add(looker.Value);
                            }

                            looker = looker.Previous;
                        } while (looker != null);


                        DarreksLog.AppendLog("Path To Destination:");

                        foreach (var node in currentSnakePath)
                        {
                            DarreksLog.AppendLog(string.Format("{0},{1}", node.X, node.Y));
                        }
                    }

                    DarreksLog.AppendLog(string.Format("The New Snake Path is {0} feet long!", currentSnakePath.Count));
                }

                #endregion

                #region Snake Movement

                currentSnakePathIsCompleted = MakeSnakeMovements(currentSnakePath, map, currentSnakePathIsCompleted, moves);

                #endregion Snake Movement

                Networking.SendMoves(moves); // Send moves
            }
        }
        catch (Exception ex)
        {
            DarreksLog.AppendLog("Exception Happened: " + ex.Message + "\r\nat\r\n" + ex.StackTrace);
        }
    }
Пример #16
0
        public static void Main(string[] args)
        {
            try {
                string name = args.Length > 0 ? args[0] : "Ze-rone";

                Networking networking = new Networking();
                GameMap    gameMap    = networking.Initialize(name);

                List <Move> moveList = new List <Move>();
                int         step     = 1;
                for (;;)
                {
                    DebugLog.AddLog($"New Move: {step++}----------------------------------------------------------------------");
                    moveList.Clear();
                    gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                    List <Planet> ownedPlanets   = new List <Planet>();
                    List <Planet> unOwnedPlanets = new List <Planet>();

                    foreach (Planet planet in gameMap.GetAllPlanets().Select(kvp => kvp.Value))
                    {
                        if (planet.IsOwnedBy(gameMap.GetMyPlayerId()))
                        {
                            ownedPlanets.Add(planet);
                        }
                        else
                        {
                            unOwnedPlanets.Add(planet);
                        }
                        planet.ShipsByDistance = gameMap.NearbyEntitiesByDistance(planet).Where(e => e.Value.GetType() == typeof(Ship) && e.Value.GetOwner() == gameMap.GetMyPlayerId()).OrderBy(kvp => kvp.Key).ToList();
                    }

                    // To prevent wasted movements from ships, if a ship starts toward a planet it will continue to that planet to complete it's mission.
                    // If the planet is taken over then the bots are no longer "claimed" by it and they can redirect, this happens when we're attacking and in the
                    // constructor for the planet.
                    foreach (var kvp in Planet.ShipsClaimed)
                    {
                        var toRemove = new List <Ship>();
                        foreach (var ship in kvp.Value)
                        {
                            // Make sure the ship is still around.
                            var realShip = gameMap.GetAllShips().FirstOrDefault(s => s.GetId() == ship.GetId());
                            if (realShip == null)
                            {
                                toRemove.Add(ship);
                            }
                            else
                            {
                                // Don't try to redock docking ships.
                                if (realShip.GetDockingStatus() != Ship.DockingStatus.Undocked)
                                {
                                    continue;
                                }
                                var planet = gameMap.GetPlanet(kvp.Key);
                                // We own this planet, or it is not owned, so we must have been flying to it to dock, continue doing so.
                                if (!planet.IsOwned() || planet.IsOwnedBy(gameMap.GetMyPlayerId()))
                                {
                                    NavigateToDock(planet, null, null, moveList, gameMap, false, realShip);
                                }
                                else
                                {
                                    NavigateToAttack(planet, null, null, moveList, gameMap, false, realShip);
                                }
                                realShip.ClaimStateless();
                            }
                        }
                        foreach (var ship in toRemove)
                        {
                            kvp.Value.Remove(ship);
                        }
                    }
                    ownedPlanets.Sort(PlanetComparer);
                    unOwnedPlanets.Sort(PlanetComparer);

                    CalculateMoves(ownedPlanets, unOwnedPlanets, moveList, gameMap);

                    Networking.SendMoves(moveList);
                }
            }
            catch (Exception ex) {
                DebugLog.AddLog($"{ex.Message}: {ex.StackTrace}");
                Networking.SendMoves(new List <Move>());
            }
        }
Пример #17
0
        public void Run()
        {
            string name = "OldBotV1";

            Networking  networking = new Networking();
            GameMap     gameMap    = networking.Initialize(name);
            List <Move> moveList   = new List <Move>();
            var         random     = new Random();

            while (true)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                foreach (var ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    /**
                     * Fly ships. Conquer planets to get more ships. Fight other ships. Repeat.
                     * Ultimate question: what should each ship do?
                     **/
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    Planet bestPlanet         = null;
                    double bestPlanetScore    = 0;
                    Planet closestEnemyPlanet = null;

                    foreach (var planet in gameMap.GetAllPlanets().Values)
                    {
                        if (planet.GetOwner() == gameMap.GetMyPlayerId() || !planet.IsOwned())
                        {
                            if (planet.GetDockedShips().Count == planet.GetDockingSpots())
                            {
                                continue;
                            }

                            var currentPlanetScore = GetPlanetScore(planet, ship);

                            if (currentPlanetScore > bestPlanetScore)
                            {
                                bestPlanetScore = currentPlanetScore;
                                bestPlanet      = planet;
                            }
                        }
                        else
                        {
                            if (closestEnemyPlanet == null)
                            {
                                closestEnemyPlanet = planet;
                            }
                            else if (planet.GetDistanceTo(ship) < closestEnemyPlanet.GetDistanceTo(ship))
                            {
                                closestEnemyPlanet = planet;
                            }
                        }
                    }

                    Move move = null;

                    if (bestPlanet != null)
                    {
                        if (ship.CanDock(bestPlanet))
                        {
                            move = new DockMove(ship, bestPlanet);
                        }
                        else
                        {
                            move = Navigation.NavigateShipToDock(gameMap, ship, bestPlanet, Constants.MAX_SPEED);
                        }
                    }
                    else if (closestEnemyPlanet != null)
                    {
                        move = Navigation.NavigateShipTowardsTarget(gameMap, ship, closestEnemyPlanet, Constants.MAX_SPEED, true, Constants.MAX_NAVIGATION_CORRECTIONS, Math.PI / 180);
                    }

                    if (move != null)
                    {
                        moveList.Add(move);
                    }
                }

                Networking.SendMoves(moveList);
            }
        }
Пример #18
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Sharpie";

            Networking networking = new Networking();
            GameMap    gameMap    = networking.Initialize(name);
            Planet     largestPlanet;

            List <Planet> currentPlanets = new List <Planet>();
            List <Ship>   currentShips   = new List <Ship>();

            List <Move> moveList = new List <Move>();

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                currentShips.AddRange(gameMap.GetMyPlayer().GetShips().Values);
                currentPlanets.AddRange(gameMap.GetAllPlanets().Values);

                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    foreach (Planet planet in gameMap.GetAllPlanets().Values)
                    {
                        if (planet.IsOwned())
                        {
                            continue;
                        }

                        largestPlanet = planet;

                        if (planet.GetRadius() > largestPlanet.GetRadius())
                        {
                            largestPlanet = planet;
                            if (planet.GetDistanceTo(ship) < largestPlanet.GetDistanceTo(ship))
                            {
                                largestPlanet = planet;
                            }
                        }

                        if (ship.CanDock(largestPlanet))
                        {
                            moveList.Add(new DockMove(ship, largestPlanet));
                            break;
                        }
                        else
                        {
                            ThrustMove newLThrustMove = Navigation.NavigateShipToDock(gameMap, ship, largestPlanet, Constants.MAX_SPEED);
                            if (newLThrustMove != null)
                            {
                                moveList.Add(newLThrustMove);
                                break;
                            }
                        }
                    }
                }
                Networking.SendMoves(moveList);
            }
        }
Пример #19
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);


        var map = Networking.getInit(out _MyID);

        DarrekLog.LogFileName = String.Format("log{0}.txt", _MyID);
        const ushort MAX_STRENGTH  = 255;
        const ushort HALF_STRENGTH = 128;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */


        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        DarrekLog.AppendLog("Starting battle!");
        int frameNumber = 0;
        var movesTowardHighProductionByDirection = new Dictionary <Direction, ushort>();

        movesTowardHighProductionByDirection.Add(Direction.North, 0);
        movesTowardHighProductionByDirection.Add(Direction.South, 0);
        movesTowardHighProductionByDirection.Add(Direction.East, 0);
        movesTowardHighProductionByDirection.Add(Direction.West, 0);

        while (true)
        {
            //try
            //{
            Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            //}
            //catch (Exception)
            //{
            //    return;
            //}

            #region Check Production
            if (frameNumber == 0)
            {
                var sb = new StringBuilder();
                sb.Append("production values:");

                //TODO: find nearest high production zone and head there.
                for (ushort y = 0; y < map.Height; y++)
                {
                    sb.Append("\r\n");
                    for (ushort x = 0; x < map.Width; x++)
                    {
                        var prodVal = map[x, y].Production;
                        sb.Append(prodVal + " ");

                        if (_MaxProductionValue < prodVal)
                        {
                            _MaxProductionValue = prodVal;
                        }
                    }
                }

                DarrekLog.AppendLog(sb.ToString());

                _TopProductionValuesGreaterThan = (ushort)(_MaxProductionValue * .70);

                DarrekLog.AppendLog(string.Format("Max Production Value Found = {0}", _MaxProductionValue));
                DarrekLog.AppendLog(string.Format("Top Production Values >= {0}", _TopProductionValuesGreaterThan));
            }
            #endregion

            frameNumber++;

            DarrekLog.AppendLog(string.Format("Frame {0}", frameNumber));

            movesTowardHighProductionByDirection[Direction.North] = 0;
            movesTowardHighProductionByDirection[Direction.South] = 0;
            movesTowardHighProductionByDirection[Direction.East]  = 0;
            movesTowardHighProductionByDirection[Direction.West]  = 0;

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == _MyID)
                    {
                        var activeSite = new SiteEx(map, x, y);

                        if (activeSite.Strength < MAX_STRENGTH / 10)
                        {
                            continue;
                        }

                        var neighbors = new List <SiteEx>()
                        {
                            GetNeighbor(map, activeSite, Direction.West),
                            GetNeighbor(map, activeSite, Direction.East),
                            GetNeighbor(map, activeSite, Direction.North),
                            GetNeighbor(map, activeSite, Direction.South)
                        };

                        var friendlySites       = neighbors.Where(c => c.Owner == _MyID);
                        var neutralNeighbors    = neighbors.Where(c => c.Owner == 0);
                        var potentialLunchSites =
                            neighbors.Where(c => c.Strength < activeSite.Strength && c.Owner == 0);

                        //1. Try to grow
                        if (potentialLunchSites.Any())
                        {
                            if (neutralNeighbors.Count() >= 3 || potentialLunchSites.Count() > 1)
                            {
                                var directionToMove = GetNearestFreeHighProductionDirection(map, activeSite);
                                movesTowardHighProductionByDirection[directionToMove]++;

                                if (GetNeighbor(map, activeSite, directionToMove).Strength < activeSite.Strength)
                                {
                                    moves.Add(new Move
                                    {
                                        Location  = activeSite.Location,
                                        Direction = directionToMove
                                    });
                                }
                            }
                            else
                            {
                                var lunchSite       = potentialLunchSites.OrderByDescending(s => s.Production).First();
                                var directionToMove = GetMoveDirection(map, activeSite, lunchSite);

                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = directionToMove
                                });

                                continue;
                            }
                        }



                        //2. If all neighbors are friendly, move where most of the blob is moving (toward high production)
                        if (friendlySites.Count() == neighbors.Count && ((activeSite.Strength >= (activeSite.Production * 5)) || activeSite.Strength > HALF_STRENGTH))
                        {
                            ushort distanceFromEdge;
                            var    nearestNonPlayerDirection = GetNearestNonPlayerDirection(map, activeSite, _MyID, out distanceFromEdge);

                            if (movesTowardHighProductionByDirection.All(m => m.Value == 0) || distanceFromEdge > 3)
                            {
                                if (nearestNonPlayerDirection != Direction.Still)
                                {
                                    moves.Add(new Move
                                    {
                                        Location  = activeSite.Location,
                                        Direction = nearestNonPlayerDirection
                                    });
                                }
                                else //All orthagonal directions are occupied.
                                {
                                    //TODO: could have logic here to find enemies or something, or go diagonally.
                                }
                            }
                            else
                            {
                                var blobMoveDirection = movesTowardHighProductionByDirection.First(m => m.Value == movesTowardHighProductionByDirection.Max(n => n.Value)).Key;

                                DarrekLog.AppendLog(string.Format("Moving with blob to the {0}", blobMoveDirection));

                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = blobMoveDirection
                                });
                            }
                        }
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #20
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Sharpie";

            Networking networking = new Networking();
            GameMap    gameMap    = networking.Initialize(name);

            List <Move> moveList = new List <Move>();

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    var sorted = new SortedDictionary <double, Entity>(gameMap.NearbyEntitiesByDistance(ship));
                    foreach (KeyValuePair <double, Entity> item in sorted)
                    {
                        double distance = item.Key;
                        if (item.Key > 300)
                        {
                            continue;
                        }


                        if (item.Value.GetType() == typeof(Planet))
                        {
                            Planet planet = (Planet)item.Value;
                            if (planet.IsOwned() && (planet.GetOwner() != gameMap.GetMyPlayerId() || planet.IsFull()))
                            {
                                continue;
                            }
                            else
                            {
                                if (ship.CanDock(planet))
                                {
                                    moveList.Add(new DockMove(ship, planet));
                                    break;
                                }

                                ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED);
                                if (newThrustMove != null)
                                {
                                    moveList.Add(newThrustMove);
                                }
                                break;
                            }
                        }

                        if (item.Value.GetType() == typeof(Ship))
                        {
                            Ship targetShip = (Ship)item.Value;
                            if (targetShip.GetOwner() == gameMap.GetMyPlayerId())
                            {
                                continue;
                            }
                            else
                            {
                                ThrustMove newThrustMove = Navigation.NavigateShipTowardsTarget(gameMap, ship, targetShip, Constants.MAX_SPEED, true, 7, 0);
                                if (newThrustMove != null)
                                {
                                    moveList.Add(newThrustMove);
                                }
                                break;
                            }
                        }
                    }
                    // foreach (Planet planet in gameMap.GetAllPlanets().Values)
                    // {
                    //     if (planet.IsOwned())
                    //     {
                    //         continue;
                    //     }
                    //
                    //     if (ship.CanDock(planet))
                    //     {
                    //         moveList.Add(new DockMove(ship, planet));
                    //         break;
                    //     }
                    //
                    //     ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED / 2);
                    //     if (newThrustMove != null)
                    //     {
                    //         moveList.Add(newThrustMove);
                    //     }
                    //
                    //     break;
                    // }
                }
                Networking.SendMoves(moveList);
            }
        }
Пример #21
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);


        var map = Networking.getInit(out _MyID);

        DarrekLog.LogFileName = String.Format("log{0}.txt", _MyID);
        const ushort MAX_STRENGTH  = 255;
        const ushort HALF_STRENGTH = 128;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */


        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        DarrekLog.AppendLog("Starting battle!");
        int frameNumber = 0;

        while (true)
        {
            try
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            }
            catch (Exception)
            {
                return;
            }

            #region Check Production
            if (frameNumber == 0)
            {
                var sb = new StringBuilder();
                sb.Append("production values:");

                //TODO: find nearest high production zone and head there.
                for (ushort y = 0; y < map.Height; y++)
                {
                    sb.Append("\r\n");
                    for (ushort x = 0; x < map.Width; x++)
                    {
                        var prodVal = map[x, y].Production;
                        sb.Append(prodVal + " ");

                        if (_MaxProductionValue < prodVal)
                        {
                            _MaxProductionValue = prodVal;
                        }
                    }
                }

                DarrekLog.AppendLog(sb.ToString());

                _TopProductionValuesGreaterThan = (ushort)(_MaxProductionValue * .70);

                DarrekLog.AppendLog(string.Format("Max Production Value Found = {0}", _MaxProductionValue));
                DarrekLog.AppendLog(string.Format("Top Production Values >= {0}", _TopProductionValuesGreaterThan));
            }
            #endregion

            frameNumber++;

            DarrekLog.AppendLog(string.Format("Frame {0}", frameNumber));

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == _MyID)
                    {
                        var activeSite = new SiteEx(map, x, y);

                        if ((activeSite.Strength < activeSite.Production * 3) && (activeSite.Strength < MAX_STRENGTH / 12))
                        {
                            continue;
                        }

                        var neighbors = new List <SiteEx>()
                        {
                            GetNeighbor(map, activeSite, Direction.West),
                            GetNeighbor(map, activeSite, Direction.East),
                            GetNeighbor(map, activeSite, Direction.North),
                            GetNeighbor(map, activeSite, Direction.South)
                        };

                        var friendlySites = neighbors.Where(c => c.Owner == _MyID);
                        var friendlySitesWorthVisiting =
                            friendlySites.Where(
                                f =>
                                f.Strength > 0 && f.Strength + activeSite.Strength <MAX_STRENGTH &&
                                                                                    f.Production> (_MaxProductionValue / 4));
                        var neutralNeighbors  = neighbors.Where(c => c.Owner == 0);
                        var weakNeighborSites = neighbors.Where(c => (activeSite.Strength == MAX_STRENGTH || c.Production > 0) && c.Strength < activeSite.Strength && c.Owner == 0);

                        bool shouldCombine = false;

                        if (!weakNeighborSites.Any())
                        {
                            if (activeSite.X + activeSite.Y % 2 == 1) //Only combine from every other square to prevent dancing.
                            {
                                shouldCombine = true;
                            }
                        }

                        //Combine forces if we are a thin line.
                        if (shouldCombine && friendlySitesWorthVisiting.Any())
                        {
                            var destination = friendlySitesWorthVisiting.FirstOrDefault(f => f.Production > activeSite.Production);
                            if (destination != null)
                            {
                                var directionToMove = GetMoveDirection(map, activeSite, destination);
                                DarrekLog.AppendLog("Combine Forces!");

                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = directionToMove
                                });
                                continue;
                            }
                        }

                        //1. Try to grow
                        if (weakNeighborSites.Any())
                        {
                            SiteEx lunchSiteToAttack = null;

                            //Move Between enemies if possible for maximum damage!
                            foreach (var pls in weakNeighborSites)
                            {
                                var nW = GetNeighbor(map, pls, Direction.West);
                                var nE = GetNeighbor(map, pls, Direction.East);
                                var nS = GetNeighbor(map, pls, Direction.South);
                                var nN = GetNeighbor(map, pls, Direction.North);

                                var enemyNeighborsCount = ((nW.Owner != _MyID && nW.Owner != 0) ? 1 : 0) +
                                                          ((nE.Owner != _MyID && nE.Owner != 0) ? 1 : 0) +
                                                          ((nS.Owner != _MyID && nS.Owner != 0) ? 1 : 0) +
                                                          ((nN.Owner != _MyID && nN.Owner != 0) ? 1 : 0);

                                if (enemyNeighborsCount > 1)
                                {
                                    lunchSiteToAttack = pls;
                                }
                            }

                            if (lunchSiteToAttack == null)
                            {
                                lunchSiteToAttack = weakNeighborSites.OrderByDescending(s => s.Production - s.Strength / 10).First();
                            }

                            var directionToMove = GetMoveDirection(map, activeSite, lunchSiteToAttack);

                            if (lunchSiteToAttack.Strength < activeSite.Strength)
                            {
                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = directionToMove
                                });
                                continue;
                            }
                        }


                        //2. If all neighbors are friendly, move towards nearest edge.
                        else if (activeSite.Strength > 0 && friendlySites.Count() == neighbors.Count && ((activeSite.Strength >= (activeSite.Production * 3)) || activeSite.Strength > HALF_STRENGTH / 2))
                        {
                            ushort distanceFromEdge;
                            var    nearestNonPlayerDirection = GetNearestNonPlayerDirection(map, activeSite, _MyID, out distanceFromEdge);
                            if (nearestNonPlayerDirection != Direction.Still)
                            {
                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = nearestNonPlayerDirection
                                });
                            }
                            else //All orthagonal directions are occupied.
                            {
                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = x % 2 == 1 ? Direction.North : Direction.South
                                });
                                //TODO: could have logic here to find enemies or something, or go diagonally.
                            }
                        }
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }
Пример #22
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        map = Networking.getInit(out myID);
#if DEBUG
        using (var writer = new StreamWriter(File.Create(@"C:\Temp\Halite.log"))) {
#endif

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName);     // Acknoweldge the init and begin the game

        var random = new Random();
        int turn   = 1;
        while (true)
        {
#if DEBUG
            writer.WriteLine($"Starting turn {turn}");
#endif
            Networking.getFrame(ref map);     // Update the map to reflect the moves before this turn
            players = new List <Unit>();
            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    players.Add(new Unit(x, y));
                }
            }

            foreach (var player in players.Where(p => p.Site.Owner == myID))
            {
                if (player.Site.Owner == myID)
                {
                    var direction = Direction.Still;
#if DEBUG
                    writer.WriteLine($"Deciding where to move for location{player}");
#endif
                    var location = new Location {
                        X = player.X, Y = player.Y
                    };
                    var adjacent = new List <Unit> {
                        player.North, player.East, player.South, player.West
                    };
#if DEBUG
                    writer.WriteLine($"\tFound adjacent players: \n\tNorth{player.North}\n\tSouth{player.South}\n\tEast{player.East}\n\tWest{player.West}");
#endif
                    var open = adjacent.Where(a => a.Site.Owner != myID);
                    if (!open.Any())
                    {
                        if (player.Site.Strength > 20)
                        {
#if DEBUG
                            writer.WriteLine($"In the safe zone, deciding who needs help...");
#endif
                            direction = FindNearestPerimeter(player);
                        }
                    }
                    else
                    {
                        var weakest = open.First(o => o.Site.Strength == open.Min(s => s.Site.Strength));
                        if (player.Site.Strength > weakest.Site.Strength)
                        {
                            switch (adjacent.IndexOf(weakest))
                            {
                            case 0:
                                direction = Direction.North;
                                break;

                            case 1:
                                direction = Direction.East;
                                break;

                            case 2:
                                direction = Direction.South;
                                break;

                            case 3:
                                direction = Direction.West;
                                break;
                            }
                        }
                    }
#if DEBUG
                    writer.WriteLine($"\tMoving {direction} from [{location.X},{location.Y}]");
#endif
                    moves.Add(new Move {
                        Direction = direction, Location = location
                    });
                }
            }
            Networking.SendMoves(moves);     // Send moves
            turn++;
        }
#if DEBUG
    }
#endif
    }
Пример #23
0
        public void Run()
        {
            string name = "AblimBot";

            Networking  networking = new Networking();
            GameMap     gameMap    = networking.Initialize(name);
            List <Move> moveList   = new List <Move>();

            while (true)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());
                var planetLookup = new Dictionary <int, int>();

                foreach (var ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    /**
                     * Fly ships. Conquer planets to get more ships. Fight other ships. Repeat.
                     * Ultimate question: what should each ship do?
                     **/
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    Planet closestPlanet                = null;
                    double closestPlanetDistance        = double.MaxValue;
                    Planet closestNeutralPlanet         = null;
                    double closestNeutralPlanetDistance = double.MaxValue;

                    foreach (var planet in gameMap.GetAllPlanets().Values)
                    {
                        var distance = planet.GetDistanceTo(ship);

                        if (planet.GetOwner() == gameMap.GetMyPlayerId() &&
                            planet.GetDockedShips().Count < planet.GetDockingSpots() &&
                            distance < closestPlanetDistance)
                        {
                            closestPlanetDistance = distance;
                            closestPlanet         = planet;
                        }
                        else if (!planet.IsOwned() &&
                                 distance < closestNeutralPlanetDistance)
                        {
                            closestNeutralPlanetDistance = distance;
                            closestNeutralPlanet         = planet;
                        }
                    }

                    Ship   closestEnemy               = null;
                    double closestEnemyDistance       = double.MaxValue;
                    Ship   closestDockedEnemy         = null;
                    double closestDockedEnemyDistance = double.MaxValue;

                    foreach (var enemy in gameMap.GetAllShips())
                    {
                        if (enemy.GetOwner() != gameMap.GetMyPlayerId())
                        {
                            var distance = enemy.GetDistanceTo(ship);

                            if (enemy.GetDockingStatus() == Ship.DockingStatus.Undocked)
                            {
                                if (distance < closestEnemyDistance)
                                {
                                    closestEnemy         = enemy;
                                    closestEnemyDistance = distance;
                                }
                            }
                            else
                            {
                                if (distance < closestDockedEnemyDistance)
                                {
                                    closestDockedEnemyDistance = distance;
                                    closestDockedEnemy         = enemy;
                                }
                            }
                        }
                    }

                    Move move = null;

                    //Decide whether to colonise or fight
                    if (closestNeutralPlanet != null && !planetLookup.ContainsKey(closestNeutralPlanet.GetId()))
                    {
                        planetLookup.Add(closestNeutralPlanet.GetId(), ship.GetId());

                        if (ship.CanDock(closestNeutralPlanet))
                        {
                            move = new DockMove(ship, closestNeutralPlanet);
                        }
                        else
                        {
                            move = Navigation.NavigateShipToDock(gameMap, ship, closestNeutralPlanet, Constants.MAX_SPEED);
                        }
                    }
                    else if (closestPlanet != null && !planetLookup.ContainsKey(closestPlanet.GetId()))
                    {
                        planetLookup.Add(closestPlanet.GetId(), ship.GetId());

                        if (ship.CanDock(closestPlanet))
                        {
                            move = new DockMove(ship, closestPlanet);
                        }
                        else
                        {
                            move = Navigation.NavigateShipToDock(gameMap, ship, closestPlanet, Constants.MAX_SPEED);
                        }
                    }
                    else if (closestDockedEnemy != null)
                    {
                        move = Navigation.NavigateShipTowardsTarget(gameMap, ship, closestDockedEnemy, Constants.MAX_SPEED, true, Constants.MAX_NAVIGATION_CORRECTIONS, Math.PI / 180);
                    }
                    else if (closestEnemy != null)
                    {
                        move = Navigation.NavigateShipTowardsTarget(gameMap, ship, closestEnemy, Constants.MAX_SPEED, true, Constants.MAX_NAVIGATION_CORRECTIONS, Math.PI / 180);
                    }

                    if (move != null)
                    {
                        moveList.Add(move);
                    }
                }

                Networking.SendMoves(moveList);
            }
        }
Пример #24
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Sharpie";

            Networking  networking = new Networking();
            GameMap     gameMap    = networking.Initialize(name);
            List <Move> moveList   = new List <Move>();
            int         myPlanets  = 0;
            int         numScouts  = 0;

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                numScouts = 0;
                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.IsScout())
                    {
                        numScouts++;
                    }
                }

                myPlanets = 0;
                foreach (Planet p in gameMap.GetAllPlanets().Values)
                {
                    if (p.IsOwned() && p.GetOwner() == gameMap.GetMyPlayerId())
                    {
                        myPlanets++;
                    }
                }

                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    // if (numScouts < 1 && !(ship.IsScout()) && (myPlanets > 2))
                    // {
                    //     ship.SetScout(true);
                    //     numScouts++;
                    //     foreach (Planet p in gameMap.GetAllPlanets().Values){
                    //         if ( p.IsOwned() && p.GetOwner() != gameMap.GetMyPlayerId() ){
                    //             ship.SetTargetId(p.GetId());
                    //             break;
                    //         }
                    //     }
                    // }
                    //
                    // if (ship.IsScout())
                    // {
                    //     Planet target = gameMap.GetPlanet(ship.GetTargetId());
                    //     if (target.IsOwned() && target.GetOwner() != gameMap.GetMyPlayerId()) {
                    //         CirclePlanet(gameMap, ship, target, moveList);
                    //         break;
                    //     }
                    //     // else
                    //     // {
                    //     //     ship.SetScout(false);
                    //     //     numScouts--;
                    //     //     if (ship.CanDock(target))
                    //     //     {
                    //     //         moveList.Add(new DockMove(ship, target));
                    //     //         break;
                    //     //     }
                    //     // }
                    // }


                    var sorted = new SortedDictionary <double, Entity>(gameMap.NearbyEntitiesByDistance(ship));
                    foreach (KeyValuePair <double, Entity> item in sorted)
                    {
                        double distance = item.Key;
                        if (item.Value.GetType() == typeof(Ship) && distance < 80)
                        {
                            Ship targetShip = (Ship)item.Value;
                            if (targetShip.GetOwner() == gameMap.GetMyPlayerId())
                            {
                                continue;
                            }
                            else
                            {
                                FuckShipUp(gameMap, ship, targetShip, moveList);
                                break;
                            }
                        }

                        if (item.Value.GetType() == typeof(Planet))
                        {
                            Planet planet = (Planet)item.Value;
                            if (planet.IsOwned() && planet.GetOwner() != gameMap.GetMyPlayerId())
                            {
                                bool noMorePlanet = true;
                                foreach (Planet p in gameMap.GetAllPlanets().Values)
                                {
                                    if (!p.IsOwned())
                                    {
                                        noMorePlanet = false;
                                        break;
                                    }
                                }
                                if (noMorePlanet)
                                {
                                    // FuckPlanetUp(gameMap, ship, planet, moveList);
                                    CirclePlanet(gameMap, ship, planet, moveList);
                                    break;
                                }
                                continue;
                            }
                            else if (planet.IsOwned() && planet.IsFull())
                            {
                                // Can add guards to defend
                                // Random rnd = new Random();
                                // if (rnd.Next(1,10) > 9){
                                //     CirclePlanet(gameMap, ship, planet, moveList);
                                //     break;
                                // }
                                continue;
                            }
                            else
                            {
                                //Dock and conquer planet
                                if (ship.CanDock(planet))
                                {
                                    moveList.Add(new DockMove(ship, planet));
                                    break;
                                }

                                ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED);
                                if (newThrustMove != null)
                                {
                                    moveList.Add(newThrustMove);
                                }
                                break;
                            }
                        }

                        if (item.Value.GetType() == typeof(Ship))
                        {
                            Ship targetShip = (Ship)item.Value;
                            if (targetShip.GetOwner() == gameMap.GetMyPlayerId())
                            {
                                continue;
                            }
                            else
                            {
                                FuckShipUp(gameMap, ship, targetShip, moveList);
                                break;
                            }
                        }
                    }
                    // foreach (Planet planet in gameMap.GetAllPlanets().Values)
                    // {
                    //     if (planet.IsOwned())
                    //     {
                    //         continue;
                    //     }
                    //
                    //     if (ship.CanDock(planet))
                    //     {
                    //         moveList.Add(new DockMove(ship, planet));
                    //         break;
                    //     }
                    //
                    //     ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED / 2);
                    //     if (newThrustMove != null)
                    //     {
                    //         moveList.Add(newThrustMove);
                    //     }
                    //
                    //     break;
                    // }
                }
                Networking.SendMoves(moveList);
            }
        }
Пример #25
0
    public static void Main(string[] args)
    {
        Console.SetIn(Console.In);
        Console.SetOut(Console.Out);

        ushort       myID;
        var          map           = Networking.getInit(out myID);
        const ushort MAX_STRENGTH  = 255;
        const ushort HALF_STRENGTH = 128;

        /* ------
        *   Do more prep work, see rules for time limit
        *  ------ */

        Networking.SendInit(MyBotName); // Acknoweldge the init and begin the game

        var random = new Random();

        //var logFileName = string.Format(@"C:\Users\dolson\Source\Halite\Halite-C#-Starter-Package\Halite-C#-Starter-Package\log{0}.txt", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
        var logFileName = string.Format("log{0}.txt", DateTime.Now.Ticks);

        AppendLog(logFileName, "Starting battle!");
        int frameNumber = 0;

        while (true)
        {
            try
            {
                Networking.getFrame(ref map); // Update the map to reflect the moves before this turn
            }
            catch (Exception)
            {
                return;
            }
            frameNumber++;

            AppendLog(logFileName, string.Format("Frame {0}", frameNumber));

            var moves = new List <Move>();
            for (ushort x = 0; x < map.Width; x++)
            {
                for (ushort y = 0; y < map.Height; y++)
                {
                    if (map[x, y].Owner == myID)
                    {
                        var activeSite = new SiteEx(map, x, y);

                        if (activeSite.Strength < MAX_STRENGTH / 10)
                        {
                            continue;
                        }

                        var neighbors = new List <SiteEx>()
                        {
                            GetNeighbor(map, activeSite, Direction.West),
                            GetNeighbor(map, activeSite, Direction.East),
                            GetNeighbor(map, activeSite, Direction.North),
                            GetNeighbor(map, activeSite, Direction.South)
                        };

                        var friendlySites       = neighbors.Where(c => c.Owner == myID);
                        var potentialLunchSites =
                            neighbors.Where(c => c.Strength < activeSite.Strength && c.Owner == 0);

                        //1. Try to grow
                        if (potentialLunchSites.Any())
                        {
                            var lunchSite       = potentialLunchSites.OrderByDescending(s => s.Production).First();
                            var directionToMove = GetMoveDirection(map, activeSite, lunchSite);

                            moves.Add(new Move
                            {
                                Location  = activeSite.Location,
                                Direction = directionToMove
                            });
                        }

                        //2. If all neighbors are friendly, move towards nearest edge.
                        else if (friendlySites.Count() == neighbors.Count && ((activeSite.Strength >= (activeSite.Production * 5)) || activeSite.Strength > HALF_STRENGTH))
                        {
                            var nearestNonPlayerDirection = GetNearestNonPlayerDirection(map, activeSite, myID);
                            if (nearestNonPlayerDirection != Direction.Still)
                            {
                                moves.Add(new Move
                                {
                                    Location  = activeSite.Location,
                                    Direction = nearestNonPlayerDirection
                                });
                            }
                            else //All orthagonal directions are occupied.
                            {
                                //TODO: could have logic here to find enemies or something, or go diagonally.
                            }
                        }
                    }
                }
            }

            Networking.SendMoves(moves); // Send moves
        }
    }