private void SetAboutToFire()
        {
            var aboutToExplode = Bombs.Where(b => b.timer == 1);

            foreach (var bomb in aboutToExplode)
            {
                var area = PosAffectedIncludingCausingExplosion(bomb);
                foreach (var pos in area)
                {
                    CellDict[pos].ToBeFire = true;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Game Turn
 ///     One game turn is computed as follows:
 ///          Move existing troops and bombs
 ///          Execute user orders
 ///          Produce new cyborgs in all factories
 ///          Solve battles
 ///          Make the bombs explode
 ///          Check end conditions
 /// </summary>
 public void DoNextMove()
 {
     foreach (var factory in Factories.Where(x => x.Side != Side.Neutral))
     {
         if (factory.InactivityDaysLeft <= 0)
         {
             factory.TroopsCount += factory.Income;
         }
         else
         {
             factory.InactivityDaysLeft--;
         }
     }
     foreach (var troop in Troops)
     {
         troop.Remaining--;
     }
     foreach (var bomb in Bombs)
     {
         bomb.Remaining--;
     }
     //Solve battles
     foreach (var troopGroup in Troops.Where(x => x.Remaining == 0).GroupBy(x => x.Dst))
     {
         var factory        = Factories[troopGroup.First().Dst];
         int troopToFactory =
             troopGroup.Where(x => x.Side == Side.MyOwn).Sum(x => x.Size) -
             troopGroup.Where(x => x.Side == Side.Enemy).Sum(x => x.Size);
         if (troopToFactory == 0)
         {
             continue;
         }
         Side troopRestSide = troopToFactory > 0 ? Side.MyOwn : Side.Enemy;
         troopToFactory = Math.Abs(troopToFactory);
         var sign = 1;
         //            if (factory.Side == Side.Neutral  ? troopRestSide == Side.Enemy : (factory.Side != troopRestSide))
         if (factory.Side != troopRestSide)
         {
             sign = -1;
         }
         factory.TroopsCount += troopToFactory * sign;
         if (factory.TroopsCount < 0)
         {
             factory.Side        = troopRestSide;
             factory.TroopsCount = Math.Abs(factory.TroopsCount);
         }
     }
     //Bomb explode
     foreach (var bomb in Bombs.Where(x => x.Remaining == 0))
     {
         var factory = Factories[bomb.Dst];
         factory.TroopsCount -= Math.Max(10, factory.TroopsCount / 2);
     }
     Bombs.RemoveAll(bomb => {
         if (bomb.Remaining > 0)
         {
             return(false);
         }
         var factory                = Factories[bomb.Dst];
         factory.TroopsCount       -= Math.Min(factory.TroopsCount, Math.Max(10, factory.TroopsCount / 2));
         factory.InactivityDaysLeft = Constants.BOMB_EXPLODE_DURATION;
         return(true);
     });
     //
     Troops = Troops.Where(x => x.Remaining > 0).ToList();
     CurrentGameTick++;
     //        foreach (var factory in Factories) {
     //            if (factory.Side == Side.Neutral) {
     //                if (factory.TroopsCount != 0)
     //                    factory.Side = factory.TroopsCount > 0 ? Side.MyOwn : Side.Enemy;
     //            }
     //            else if (factory.TroopsCount < 0)
     //                factory.Side = factory.Side == Side.Enemy ? Side.MyOwn : Side.Enemy;
     //        }
 }
        void aTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (_monitor)
            {
                if (ViewContext != null)
                {
                    ViewContext.Post(async _ =>
                    {
                        foreach (var bomb in Bombs.Where(bomb => Math.Abs(CanvasLeft - bomb.BombCanvasLeft) <= 10 &&
                                                         Math.Abs(CanvasTop - bomb.BombCanvasTop) <= 10 &&
                                                         bomb.BombId != "" && bomb.BombId != "^" && bomb.BombId != "&"))
                        {
                            var result    = await _runmethod.GetDisarmingProcedure(int.Parse(bomb.BombId));
                            var bombFound = _bombTypeses.Single(b => b.BeepsLevel == int.Parse(bomb.BombId));
                            var bombDisarmingProcedure = Tuple.Create(bombFound.FirstStageDisarming,
                                                                      bombFound.SecondStageDisarming, bombFound.ThirdStageDisarming);
                            bomb.BombId = result.Equals(bombDisarmingProcedure) ? "^" : "&";
                            var info    = new DisarmingInfo
                            {
                                BombType                  = (BombTypes)(bombFound.BeepsLevel - 1),
                                DisarmedStatus            = bomb.BombId,
                                DataManipulationAlgorithm = _disarmedMethod,
                            };
                            DisarmingInfos.Add(info);
                        }

                        CanvasLeft = _x;
                        CanvasTop  = _y;
                        if (_x != _destinationPoint.X || _y != _destinationPoint.Y)
                        {
                            if (_x != _destinationPoint.X)
                            {
                                if (_destinationPoint.X > _x)
                                {
                                    _x++;
                                }
                                else
                                {
                                    _x--;
                                }
                            }

                            if (_y != _destinationPoint.Y)
                            {
                                if (_destinationPoint.Y > _y)
                                {
                                    _y++;
                                }
                                else
                                {
                                    _y--;
                                }
                            }
                        }
                        if (CanvasLeft == _destinationPoint.X && CanvasTop == _destinationPoint.Y)
                        {
                            _lastX = _destinationPoint.X;
                            //Console.WriteLine("xxxxxxx");
                            if (_treePositions.Count != 0)
                            {
                                _destinationPoint.X = _treePositions[0].x;
                                _destinationPoint.Y = _treePositions[0].y;
                                //Console.WriteLine("new point x: " + treePositions[0].x + " y: " + treePositions[0].y);
                                _treePositions.RemoveAt(0);
                                //Console.WriteLine(destinationPoint.X + " " + destinationPoint.Y);
                            }
                            else
                            {
                                if (_started)
                                {
                                    if (_direction == "right")
                                    {
                                        _destinationPoint.X += 50;
                                    }
                                    else
                                    {
                                        _destinationPoint.X -= 50;
                                    }
                                }
                                else
                                {
                                    _started = true;
                                }
                                searchBomb(_destinationPoint.X, _destinationPoint.Y);
                            }
                        }
                    }, null);
                }
            }
        }