private void ProcessBored(InfanteryMind mind)
        {
            if (mind.SpottedUnitsBag.Any()) {
                mind.ChangeState(EMindState.Engaged);
                ProcessEngaged(mind);
            }
            else
            {

                if(mind.BlockedPositon != null)
                {
                    var upDown = random.Next(0, 100) > 50 ? true : false;
                    var leftRight = random.Next(0, 100) > 50 ? true : false;
                    var next = random.Next(0, 20);
                    var y = upDown ? next*-1 : next;
                    var x = leftRight ? next*-1 : next;
                    var wayPointStore = _pathfindingService.Provide(mind.Infantery.Position, new Vector2(mind.BlockedPositon.X + x, mind.BlockedPositon.X + y));
                    mind.WayPointStore = wayPointStore;
                    mind.BlockedPositon = null;
                }
                else
                {
                    var heatMapSectors = _heatMapService.Get();
                    var heatMapSector = heatMapSectors.OrderByDescending(x => x.HeatFactor).First();

                    var index = random.Next(0, heatMapSectors.Count - 1);
                    Debug.WriteLine("Random was: " + index);
                    var target = heatMapSector.HeatFactor <= 1 ? heatMapSectors[index].Center : heatMapSector.Center;
                    var wayPointStore = _pathfindingService.Provide(mind.Infantery.Position, target);
                    mind.WayPointStore = wayPointStore;

                }
                mind.ChangeState(EMindState.Scouting);
            }
        }
 public InfanteryMind Create(Infantery infantery)
 {
     var infanteryMind = InfanteryMinds.Get(infantery.Id);
     if (infanteryMind == null) {
         infanteryMind = new InfanteryMind(infantery, _aiEventProcessor);
         InfanteryMinds.Store(infantery.Id, infanteryMind);
     }
     return infanteryMind;
 }
 public void Process(InfanteryMind infanteryMind)
 {
     switch (infanteryMind.MindState) {
         case EMindState.Bored:
             ProcessBored(infanteryMind);
             break;
         case EMindState.Scouting:
             ProcessScouting(infanteryMind);
             break;
         case EMindState.Engaged:
             ProcessEngaged(infanteryMind);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
        private void ProcessEngaged(InfanteryMind infanteryMind)
        {
            if(!infanteryMind.SpottedUnitsBag.Any())
            {
                infanteryMind.ChangeState(EMindState.Bored);
                return;

            }

            infanteryMind.EngagedProxy = new EngagedProxy(infanteryMind.SpottedUnitsBag.First().Id);
            var attackEvent = new UnitAttacksEvent(infanteryMind.Infantery.OwnerId, infanteryMind.Infantery.Id,
                                                   infanteryMind.EngagedProxy.TargetId);
            infanteryMind.EngagedProxy.AttackEventId = attackEvent.Id;

            _eventAgent.Enqueue(attackEvent);
        }
        private void ProcessScouting(InfanteryMind infanteryMind)
        {
            if (infanteryMind.SpottedUnitsBag.Any())
            {
                infanteryMind.ChangeState(EMindState.Engaged);
                ProcessEngaged(infanteryMind);

            }
            else {

                var wayPoint = infanteryMind.WayPointStore.FirstOrDefault();
                if (wayPoint == null)
                    infanteryMind.ChangeState(EMindState.Bored);
                else {
                    wayPoint.Event = new MoveUnitEvent(infanteryMind.Infantery.OwnerId, infanteryMind.Infantery.Id,
                                                       wayPoint.Target.X, wayPoint.Target.Y);
                    _eventAgent.Enqueue(wayPoint.Event);
                }
            }
        }