Beispiel #1
0
 private void MoveHero(Direction direction, int stepsCount)
 {
     for (var i = 0; i < stepsCount; i++)
     {
         sensorData = client.Move(direction);
     }
 }
Beispiel #2
0
 private void MoveHero(params Direction [] sequenceOfDirections)
 {
     foreach (var direction in sequenceOfDirections)
     {
         sensorData = client.Move(direction);
     }
 }
        static void Print(HommSensorData data)
        {
            Console.WriteLine("---------------------------------");

            Console.WriteLine($"You are here: ({data.Location.X},{data.Location.Y})");

            Console.WriteLine($"You have {data.MyTreasury.Select(z => z.Value + " " + z.Key).Aggregate((a, b) => a + ", " + b)}");

            Console.WriteLine($"My army: {data.MyArmy.Select(dct => dct.Key + " " + dct.Value).Aggregate((a, b) => a + ", " + b)}");

            var location = data.Location.ToLocation();

            Console.Write("W: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.Up)));

            Console.Write("E: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.RightUp)));

            Console.Write("D: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.RightDown)));

            Console.Write("S: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.Down)));

            Console.Write("A: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.LeftDown)));

            Console.Write("Q: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.LeftUp)));
        }
Beispiel #4
0
 // Конструктор
 public BestAI(HommSensorData sensorData, HommClient client)
 {
     this.sensorData = sensorData;
     this.client     = client;
     myMap           = new MyMap(sensorData.Map.Width, sensorData.Map.Height);
     myMap.UpdateMap(sensorData);
 }
Beispiel #5
0
        public void Act(HommSensorData sensorData)
        {
            if (timesDwellingsUpdated < (int)sensorData.WorldCurrentTime / (7 * 5))
            {
                UpdateDwellings();
            }
            foreach (var pair in memorizedMap.Where(x => x.Value.Hero != null).ToList())
            {
                memorizedMap.Remove(pair.Key);
            }
            var pathfinder    = new Pathfinder(sensorData, memorizedMap);
            var possibleMoves = new List <IMove> {
                new Wait(client, sensorData)
            };

            possibleMoves.AddRange(pathfinder.ReachableObjects.MoveTargets.Select(target => new Move(client, pathfinder, sensorData, target)));
            possibleMoves.AddRange(pathfinder.ReachableObjects.MoveAndHireTargets.Select(target => new MoveAndHire(client, pathfinder, sensorData, target)));
            #region bigrams
#if bigrams
            possibleMoves.RemoveAll(m => m.GetPriority() <= 0);
            var possibleBigrams = possibleMoves
                                  .AsParallel()
                                  .Select(m => new Pathfinder(m.GetNewSensorData(), memorizedMap.DeepCopyByExpressionTree()))
                                  .Select(p =>
            {
                var result = new List <IMove> {
                    new Wait(client, sensorData)
                };
                result.AddRange(p.ReachableObjects.MoveTargets.Select(target => new Move(client, p, p.SensorData, target)));
                result.AddRange(p.ReachableObjects.MoveAndHireTargets.Select(target => new MoveAndHire(client, p, p.SensorData, target)));
                return(result);
            })
                                  .Zip(possibleMoves.AsParallel(), (list, move) =>
            {
                var result = new List <MoveNGram>();
                result.AddRange(list.Select(move1 => new MoveNGram(move, move1)));
                return(result);
            })
                                  .SelectMany(x => x)
                                  .ToList();
            try
            {
                possibleBigrams.MaxBy(m => m.GetPriority()).Invoke();
            }
            catch (Exception)
            {
            }
#endif
            #endregion
#if !bigrams
            try
            {
                possibleMoves.MaxBy(m => m.GetPriority()).Invoke();
            }
            catch (Exception)
            {
            }
#endif
        }
Beispiel #6
0
 public Move(HommClient client, Pathfinder pathfinder, HommSensorData sensorData, MapObjectData target)
 {
     Client     = client;
     Pathfinder = pathfinder;
     Target     = target;
     SensorData = sensorData;
     EnemyArmy  = Target.NeutralArmy?.Army
                  ?? (Target.Hero?.Name != sensorData.MyRespawnSide ? Target.Hero?.Army : null)
                  ?? (Target.Garrison?.Owner != sensorData.MyRespawnSide ? Target.Garrison?.Army : null);
     if (EnemyArmy != null)
     {
         CombatResult = Combat.Resolve(new ArmiesPair(SensorData.MyArmy, EnemyArmy));
     }
 }
Beispiel #7
0
        public Pathfinder(HommSensorData sensorData, Dictionary <Location, MapObjectData> memorizedMap)
        {
            var map = sensorData.Map;

            SensorData   = sensorData;
            HeroLocation = sensorData.Location.ToLocation();
            rightSpawn   = new Location(map.Height - 1, map.Width - 1);
            var updatedMap = map.Objects.ToDictionary(x => x.Location.ToLocation(), x => x);

            ObjectMap = memorizedMap;
            foreach (var objectData in updatedMap)
            {
                memorizedMap[objectData.Key] = objectData.Value;
            }
            TravelTimes = new Dictionary <Location, double> {
                [HeroLocation] = 0
            };
            FindPaths();
        }
Beispiel #8
0
        // Метод обновления карты
        public void UpdateMap(HommSensorData data)
        {
            sensorData = data;
            for (int h = 0; h < height; h++)
            {
                for (int w = 0; w < weight; w++)
                {
                    // Если клетка пустая
                    if (cells[w, h].travel_cost == 0)
                    {
                        FillCurrentCell(w, h);
                    }
                }
            }

            UpdateDwelling();
            UpdateMine();
            UpdateResource();
            UpdateNeutral();
        }
        private static void Connect(string[] args)
        {
            if (args.Length == 0)
            {
                //args = new[] { "homm.ulearn.me", "18700" };
                args = new[] { "127.0.0.1", "18700" }
            }
            ;
            var ip   = args[0];
            var port = int.Parse(args[1]);

            client = new HommClient();

            sensorData = client.Configurate(
                ip, port, CvarcTag,

                timeLimit: 500,            // Продолжительность матча в секундах (исключая время, которое "думает" ваша программа).

                operationalTimeLimit: 500, // Суммарное время в секундах, которое разрешается "думать" вашей программе.
                                           // Вы можете увеличить это время для отладки, чтобы ваш клиент не был отключен,
                                           // пока вы разглядываете программу в режиме дебаггинга.

                seed: 9,                   // Seed карты. Используйте этот параметр, чтобы получать одну и ту же карту и отлаживаться на ней.
                                           // Иногда меняйте этот параметр, потому что ваш код должен хорошо работать на любой карте.

                spectacularView: true,     // Вы можете отключить графон, заменив параметр на false.

                debugMap: false,           // Вы можете использовать отладочную простую карту, чтобы лучше понять, как устроен игоровой мир.

                level: HommLevel.Level3,   // Здесь можно выбрать уровень. На уровне два на карте присутствует оппонент.

                isOnLeftSide: false        // Вы можете указать, с какой стороны будет находиться замок героя при игре на втором уровне.
                                           // Помните, что на сервере выбор стороны осуществляется случайным образом, поэтому ваш код
                                           // должен работать одинаково хорошо в обоих случаях.
                );
        }
Beispiel #10
0
        public ActionManager(HommClient client, HommSensorData sensorData)
        {
            Client     = client;
            SensorData = sensorData;

            var startCell = sensorData.Location.CreateCell();

            EnemyRespawn =
                startCell.SameLocation(new Cell(0, 0)) ?
                sensorData.Map.Objects.SingleOrDefault(o => o.Location.X == 13 && o.Location.Y == 13) :
                sensorData.Map.Objects.SingleOrDefault(o => o.Location.X == 0 && o.Location.Y == 0);
            MapType = MapType.Single;

            if (sensorData.Map.Objects.Count < sensorData.Map.Height * sensorData.Map.Width)
            {
                MapType = MapType.DualHard;
            }
            else if (EnemyRespawn.Hero != null)
            {
                MapType = MapType.Dual;
            }

            Map = new List <Cell>();
        }
        private static void Print(HommSensorData data)
        {
            Console.WriteLine("---------------------------------");

            Console.Write(data.IsDead ? "You are dead\n" : "");

            Console.WriteLine($"You are here: ({data.Location.X},{data.Location.Y})");

            Console.WriteLine($"You have {data.MyTreasury.Select(z => z.Value + " " + z.Key).Aggregate((a, b) => a + ", " + b)}");

            Console.WriteLine($"You have {data.MyArmy.Select(z => z.Value.ToString() + " " + z.Key.ToString()).Aggregate((a, b) => a + ", " + b)}");

            Console.WriteLine($"Current game progress is {data.WorldCurrentTime / 90:P0}");

            Console.WriteLine($"You spawned on the {data.MyRespawnSide} side");

            var location = data.Location.ToLocation();

            Console.Write("W: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.Up)));

            Console.Write("E: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.RightUp)));

            Console.Write("D: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.RightDown)));

            Console.Write("S: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.Down)));

            Console.Write("A: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.LeftDown)));

            Console.Write("Q: ");
            Console.WriteLine(GetObjectAt(data.Map, location.NeighborAt(Direction.LeftUp)));
        }
Beispiel #12
0
 public void Init()
 {
     client     = new HommClient();
     sensorData = client.Configurate("127.0.0.1", 18700, Guid.Empty, operationalTimeLimit: 5, debugMap: true);
 }
Beispiel #13
0
        // Метод Updates, обработчик события, обновляет локальную карту
        public void Updates(HommSensorData sensorData)
        {
            this.sensorData = sensorData;

            myMap.UpdateMap(sensorData);
        }
Beispiel #14
0
 public MoveAndHire(HommClient client, Pathfinder pathfinder, HommSensorData sensorData,
                    MapObjectData target) : base(client, pathfinder, sensorData, target)
 {
 }
Beispiel #15
0
 public Wait(HommClient client, HommSensorData sensorData)
 {
     this.client     = client;
     this.sensorData = sensorData;
 }