Esempio n. 1
0
        static void Main(string[] args)
        {
            int  myTeamId = int.Parse(Console.ReadLine()); // if 0 you need to score on the right of the map, if 1 you need to score on the left
            Game game     = new Game()
            {
                Turn = 0, MyTeamId = myTeamId
            };

            // game loop
            while (true)
            {
                string[] inputs  = Console.ReadLine().Split(' ');
                int      myScore = int.Parse(inputs[0]);
                int      myMagic = int.Parse(inputs[1]);
                game.Board.MyScore = myScore;
                game.Board.MyMana  = myMagic;
                inputs             = Console.ReadLine().Split(' ');
                int opponentScore = int.Parse(inputs[0]);
                int opponentMagic = int.Parse(inputs[1]);
                game.Board.EnnemyScore = opponentScore;
                game.Board.EnnemyMana  = opponentMagic;

                // Change this later to keep trace
                game.Board.Entities.Clear();

                int entities = int.Parse(Console.ReadLine()); // number of entities still in game
                for (int i = 0; i < entities; i++)
                {
                    inputs = Console.ReadLine().Split(' ');

                    int    entityId   = int.Parse(inputs[0]); // entity identifier
                    string entityType = inputs[1];            // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
                    int    x          = int.Parse(inputs[2]); // position
                    int    y          = int.Parse(inputs[3]); // position
                    int    vx         = int.Parse(inputs[4]); // velocity
                    int    vy         = int.Parse(inputs[5]); // velocity
                    int    state      = int.Parse(inputs[6]); // 1 if the wizard is holding a Snaffle, 0 otherwise

                    Entity entity = game.Board.Entities.FirstOrDefault(e => e.Id == entityId);
                    // Add or update specific
                    if (entity == null)
                    {
                        switch (entityType)
                        {
                        case "WIZARD":
                            entity = new Wizard()
                            {
                                TeamId = myTeamId
                            };
                            break;

                        case "OPPONENT_WIZARD":
                            entity = new Wizard()
                            {
                                TeamId = 1 - myTeamId
                            };
                            break;

                        case "SNAFFLE":
                            entity = new Snaffle();
                            break;

                        case "BLUDGER":
                            entity = new Bludger();
                            break;

                        default:
                            throw new Exception("Unknown entity");
                        }
                        game.Board.Entities.Add(entity);
                    }
                    else
                    {
                        switch (entityType)
                        {
                        case "WIZARD":
                        case "OPPONENT_WIZARD":
                            ((Wizard)entity).LastAccioTurn++;
                            ((Wizard)entity).LastFlipendoTurn++;
                            ((Wizard)entity).Action = null;
                            break;

                        default:
                            break;
                        }
                    }

                    // Update common
                    entity.Id          = entityId;
                    entity.Position.X  = x;
                    entity.Position.Y  = y;
                    entity.Velocity.VX = vx;
                    entity.Velocity.VY = vy;
                    entity.State       = state;

                    Console.Error.WriteLine(entity.GetDescription());
                }

                Console.Error.WriteLine("Launching SimpleStrategy");
                var stragegy = new SimpleStrategy();
                stragegy.Compute(game);

                // Write an action using Console.WriteLine()
                // To debug: Console.Error.WriteLine("Debug messages...");

                // Edit this line to indicate the action for each wizard (0 ≤ thrust ≤ 150, 0 ≤ power ≤ 500)
                // i.e.: "MOVE x y thrust" or "THROW x y power"
                //Console.WriteLine("MOVE 8000 3750 100");

                game.Turn++;
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            string[] inputs;
            _myTeamId = int.Parse(Console.ReadLine()); // if 0 you need to score on the right of the map, if 1 you need to score on the left

            var oppReflex = new ReflexBot(_myTeamId == 0 ? 3 : 1);
            var meReflex  = new ReflexBot(_myTeamId == 0 ? 1 : 3);

            var oppSearch = new ReflexBot(oppReflex.Id - 1);
            var meSearch  = new SearchBot(meReflex.Id - 1);

            meSearch.Opponents = new List <Bot>()
            {
                oppReflex, meReflex, oppSearch
            };

            // game loop
            while (true)
            {
                round++;
                _snaffles.Clear();

                inputs = Console.ReadLine().Split(' ');

                int myScore = int.Parse(inputs[0]);
                int myMagic = int.Parse(inputs[1]);
                inputs = Console.ReadLine().Split(' ');
                int opponentScore = int.Parse(inputs[0]);
                int opponentMagic = int.Parse(inputs[1]);
                int entities      = int.Parse(Console.ReadLine()); // number of entities still in game
                int wizCount      = 0;
                int oppWizCount   = 0;
                for (int i = 0; i < entities; i++)
                {
                    inputs = Console.ReadLine().Split(' ');

                    int        entityId   = int.Parse(inputs[0]);                                        // entity identifier
                    EntityType entityType = (EntityType)Enum.Parse(typeof(EntityType), inputs[1], true); // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" or "BLUDGER"
                    int        x          = int.Parse(inputs[2]);                                        // position
                    int        y          = int.Parse(inputs[3]);                                        // position
                    int        vx         = int.Parse(inputs[4]);                                        // velocity
                    int        vy         = int.Parse(inputs[5]);                                        // velocity
                    int        state      = int.Parse(inputs[6]);                                        // 1 if the wizard is holding a Snaffle, 0 otherwise

                    switch (entityType)
                    {
                    case EntityType.Wizard:
                    case EntityType.Opponent_Wizard:
                        var wiz = _wizards.FirstOrDefault(w => w.Id == entityId);
                        if (wiz == null)
                        {
                            wiz        = new Wizard(entityId, x, y, vx, vy, Convert.ToBoolean(state));
                            wiz.TeamId = entityType == EntityType.Wizard ? _myTeamId : Math.Abs(_myTeamId - 1);
                            _wizards.Add(wiz);
                            if (wiz.TeamId == _myTeamId)
                            {
                                _myWiz[wizCount++] = wiz;
                                if (meSearch.Wizard == null)
                                {
                                    meSearch.Wizard = wiz;
                                }
                                else
                                {
                                    meReflex.Wizard = wiz;
                                }
                            }
                            else
                            {
                                _oppWiz[oppWizCount++] = wiz;
                                if (oppSearch.Wizard == null)
                                {
                                    oppSearch.Wizard = wiz;
                                }
                                else
                                {
                                    oppReflex.Wizard = wiz;
                                }
                            }
                        }
                        else
                        {
                            wiz.X          = x;
                            wiz.Y          = y;
                            wiz.Velocity.X = vx;
                            wiz.Velocity.Y = vy;
                            wiz.Carrying   = Convert.ToBoolean(state);
                        }
                        wiz.MP = myMagic;
                        if (wiz.ActiveSpell != null)
                        {
                            wiz.ActiveSpell.Duration--;
                        }
                        wiz.Save();
                        _entities[entityId] = wiz;
                        break;

                    case EntityType.Snaffle:

                        var snaffle = new Snaffle(entityId, x, y, vx, vy, Convert.ToBoolean(state));
                        _snaffles.Add(snaffle);

                        snaffle.Save();
                        _entities[entityId] = snaffle;
                        break;

                    case EntityType.Bludger:

                        var bludger = _bludgers.FirstOrDefault(w => w.Id == entityId);

                        if (bludger == null)
                        {
                            bludger = new Bludger(entityId, x, y, vx, vy);
                            _bludgers.Add(bludger);
                        }
                        else
                        {
                            bludger.X          = x;
                            bludger.Y          = y;
                            bludger.Velocity.X = vx;
                            bludger.Velocity.Y = vy;
                        }
                        bludger.LastTarget = _wizards.FirstOrDefault(w => w.Id == state);
                        bludger.Save();
                        _entities[entityId] = bludger;
                        break;
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    _wizards[i].Snaffle = _snaffles.FirstOrDefault(s => s.Distance(_wizards[i]) < _wizards[i].Radius);
                    _wizards[i].Save();
                }
                _stopwatch = Stopwatch.StartNew();
                int time = round == 0 ? 980 : 92;
                meSearch.Solve(time, round > 0);
                Solution.Output(meSearch.Solution.Moves[0], _wizards.First(w => w.Id == meSearch.Id));

                Console.Error.WriteLine("Score {0}\nNew Pos: {1}", meSearch.Solution.Score, _myWiz[0] as Point);

                //meSearch.Solution.Output(meSearch.Solution.Moves[Chromosones], _wizards.First(w => w.Id == meSearch.Id + 1));
                Console.WriteLine("MOVE 0 0 0 " + _myWiz[0]);
                if (round > 0)
                {
                    Console.Error.WriteLine(string.Format("Sims Per Round: {0}, Avg: {1}", _simulations / round, _simulations * Chromosones / round));
                }
                continue;

                foreach (var wizard in _wizards.Where(w => w.TeamId == _myTeamId))
                {
                    // Write an action using Console.WriteLine() To debug:
                    // Console.Error.WriteLine("Debug messages...");

                    // Edit this line to indicate the action for each wizard (0 ≤ thrust ≤ 150, 0 ≤
                    // power ≤ 500) i.e.: "MOVE x y thrust" or "THROW x y power"
                    if (wizard.Carrying)
                    {
                        var x = _myTeamId == 0 ? Width : 0 - wizard.Velocity.X;
                        var y = GoalY - wizard.Velocity.Y;
                        Console.WriteLine(string.Format("THROW {0} {1} {2}", x, y, MaxPower));
                    }
                    else
                    {
                        //check bludger
                        if (myMagic >= Flipendo.Cost)
                        {
                            int  myGoal = _myTeamId == 0 ? 0 : Width;
                            bool cast   = false;
                            foreach (var s in _snaffles.OrderByDescending(s => s.Distance(wizard)))
                            {
                                var spell = new Flipendo()
                                {
                                    Source = wizard,
                                    Target = s
                                };
                                Console.Error.WriteLine("Old {0}", wizard);
                                spell.GetPower();
                                // s.Thrust((int)spell.Power, new Point(myGoal, GoalY));
                                s.Move(1.0);
                                Console.Error.WriteLine("New {0}", wizard);
                                if (s.X > Width || s.X < 0)
                                {
                                    wizard.ActiveSpell.Cast(s);
                                    myMagic -= Flipendo.Cost;
                                    cast     = true;
                                    break;
                                }
                                s.Load();
                                //if ((_myTeamId == 0 && s.X < 3000 && wizard.X > s.X) || (_myTeamId == 1 && s.X > Width - 3000 && wizard.X < s.X))
                                //{
                                //    wizard.ActiveSpell = new Flipendo()
                                //    {
                                //        Target = s
                                //    };
                                //    wizard.ActiveSpell.Cast(s);
                                //    cast = true;
                                //    myMagic -= Flipendo.Cost;
                                //    break;
                                //}
                            }
                            if (cast)
                            {
                                continue;
                            }
                        }

                        /*
                         * if (myMagic > Obliviate.Cost)
                         * {
                         *  var minBludgerDistance = 10000.0;
                         *  Bludger minBludger = null;
                         *  for (int i = 0; i < 2; i++)
                         *  {
                         *      var d = _bludgers[i].Distance(wizard);
                         *      if (d < minBludgerDistance)
                         *      {
                         *          minBludgerDistance = d;
                         *          minBludger = _bludgers[i];
                         *      }
                         *  }
                         *  if (minBludgerDistance < 1000 && minBludger.LastTarget != wizard)
                         *  {
                         *      wizard.ActiveSpell = new Obliviate();
                         *      wizard.ActiveSpell.Cast(minBludger);
                         *      Console.Error.WriteLine("Oblivia D: {0}", minBludgerDistance);
                         *      myMagic -= Obliviate.Cost;
                         *      continue;
                         *  }
                         * }*/
                        if (myMagic >= Accio.Cost)
                        {
                            bool cast = false;
                            foreach (var s in _snaffles)
                            {
                                if ((_myTeamId == 0 && s.X < 2000) || (_myTeamId == 1 && s.X > Width - 2000))
                                {
                                    wizard.ActiveSpell = new Accio();
                                    wizard.ActiveSpell.Cast(s);
                                    cast     = true;
                                    myMagic -= Accio.Cost;
                                    break;
                                }
                            }
                            if (cast)
                            {
                                continue;
                            }
                        }/*
                          * if (myMagic >= Petrificus.Cost)
                          * {
                          * bool cast = false;
                          * foreach (var enemy in _wizards.Where(w => w.TeamId != _myTeamId && !_wizards.Any(w1 => w1.ActiveSpell?.Target == w)))
                          * {
                          *     if ((_myTeamId == 0 && enemy.X < 3000) || (_myTeamId == 1 && enemy.X > Width - 3000))
                          *     {
                          *         wizard.ActiveSpell = new Petrificus();
                          *         wizard.ActiveSpell.Target = enemy;
                          *         wizard.ActiveSpell.Cast(enemy);
                          *         myMagic -= Petrificus.Cost;
                          *         cast = true;
                          *         break;
                          *     }
                          * }
                          * if (cast) continue;
                          * }
                          */

                        var snaff = _snaffles.OrderBy(s => s.Distance2(wizard)).FirstOrDefault(s => !s.BeingCarried);
                        if (snaff == null)
                        {
                            snaff = _snaffles.FirstOrDefault();
                        }
                        snaff.BeingCarried = true;
                        Console.WriteLine(string.Format("MOVE {0} {1} {2}", snaff.X, snaff.Y, MaxThrust));
                    }
                }
            }
        }