Ejemplo n.º 1
0
 public void AddFreeAntChecked(Location ant, params PlanType[] plans)
 {
     // check if it has already a plan
     if (!HasPlanAnt(ant, plans))
     {
         MyFreeAnts.Add(ant);
     }
 }
Ejemplo n.º 2
0
 public void AddFreeAntChecked(Location ant)
 {
     // check if it has already a plan
     if (!HasPlanAnt(ant,
                     PlanType.Move,
                     PlanType.Attack,
                     PlanType.Food,
                     PlanType.Hill,
                     PlanType.Explore))
     {
         MyFreeAnts.Add(ant);
     }
 }
Ejemplo n.º 3
0
        public void RemoveInvalidPlans()
        {
            MovePlans.Clear();
            MyFreeAnts.Clear();
            //NewBornPlans.Clear();

            for (int i = ExplorePlans.Count - 1; i >= 0; i--)
            {
                var explorer = ExplorePlans[i];

                if (explorer.PathCurrent != null)
                {
                    if (explorer.PathCurrent.Value.X != explorer.Ant.ColX || explorer.PathCurrent.Value.Y != explorer.Ant.RowY)
                    {
                        ExplorePlans.RemoveAt(i);
                        continue;
                    }
                }

                // not available deleted
                if (!GameState.MyAnts.Exists(x => x.EqualTo(explorer.Ant)))
                {
                    ExplorePlans.RemoveAt(i);
                    continue;
                }
            }

            for (int i = NewBornPlans.Count - 1; i >= 0; i--)
            {
                var newBorn = NewBornPlans[i];

                if (newBorn.PathCurrent != null)
                {
                    if (newBorn.PathCurrent.Value.X != newBorn.Ant.ColX || newBorn.PathCurrent.Value.Y != newBorn.Ant.RowY)
                    {
                        NewBornPlans.RemoveAt(i);
                        continue;
                    }
                }
            }

            for (int i = FoodPlans.Count - 1; i >= 0; i--)
            {
                var food = FoodPlans[i];

                if (food.PathCurrent != null)
                {
                    if (food.PathCurrent.Value.X != food.Ant.ColX || food.PathCurrent.Value.Y != food.Ant.RowY)
                    {
                        FoodPlans.RemoveAt(i);
                        continue;
                    }
                }

                // not available deleted
                if (!GameState.MyAnts.Exists(x => x.EqualTo(food.Ant)))
                {
                    FoodPlans.RemoveAt(i);
                    continue;
                }

                try
                {
                    if (GameState[food.Ant] != Tile.AntMine)
                    {
                        FoodPlans.RemoveAt(i);
                        continue;
                    }
                }
                catch (Exception)
                {
                    FoodPlans.RemoveAt(i);
                    continue;
                }

                try
                {
                    var dest = GameState[food.GetFinalMoveLoc()];
                    if (dest != Tile.Food && dest != Tile.HillEnemy)
                    {
                        FoodPlans.RemoveAt(i);
                        continue;
                    }
                }
                catch (Exception)
                {
                    FoodPlans.RemoveAt(i);
                    continue;
                }
            }

            foreach (var deadTile in GameState.DeadTiles)
            {
                var antIndex = FoodPlans.FirstIndexOf(x => x.Ant.EqualTo(deadTile));
                if (antIndex >= 0)
                {
                    FoodPlans.RemoveAt(antIndex);
                }
                AttackPlans.RemoveFirst(x => x.Ant.EqualTo(deadTile));
                AttackPlans.RemoveFirst(x => x.Enemy.EqualTo(deadTile));
            }
        }