示例#1
0
        public void CancelPlans(Location ant, params PlanType[] plans)
        {
            foreach (var plan in plans)
            {
                switch (plan)
                {
                case PlanType.Move:
                    MovePlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;

                case PlanType.Attack:
                    AttackPlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;

                case PlanType.Food:
                    FoodPlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;

                case PlanType.Hill:
                    FoodPlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;

                case PlanType.NewBorn:
                    NewBornPlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;

                case PlanType.Explore:
                    ExplorePlans.RemoveAll(x => x.Ant.EqualTo(ant));
                    break;
                }
            }
        }
示例#2
0
        //public void ClearPlans()
        //{
        //    AttackPlans.Clear();
        //    FoodPlans.Clear();
        //    MovePlans.Clear();
        //    //NewBornPlans.Clear();
        //    MyFreeAnts.Clear();
        //}

        public void CancelOtherPlansForAnt(Location ant)
        {
            FoodPlans.RemoveAll(x => x.Ant.EqualTo(ant));
            AttackPlans.RemoveAll(x => x.Ant.EqualTo(ant));
            MovePlans.RemoveAll(x => x.Ant.EqualTo(ant));
            NewBornPlans.RemoveAll(x => x.Ant.EqualTo(ant));
            ExplorePlans.RemoveAll(x => x.Ant.EqualTo(ant));
        }
示例#3
0
        public bool HasPlanAnt(Location ant, params PlanType[] plans)
        {
            foreach (var plan in plans)
            {
                switch (plan)
                {
                case PlanType.Move:
                    if (MovePlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Attack:
                    if (AttackPlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Food:
                    if (FoodPlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Hill:
                    if (FoodPlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.NewBorn:
                    if (NewBornPlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Explore:
                    if (ExplorePlans.Exists(x => x.Ant.EqualTo(ant)))
                    {
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
示例#4
0
        public bool HasPlanDest(Location dest, params PlanType[] plans)
        {
            foreach (var plan in plans)
            {
                switch (plan)
                {
                case PlanType.Move:
                    if (MovePlans.Exists(x => x.Dest.EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Attack:
                    if (AttackPlans.Exists(x => x.NextStep.EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Food:
                    if (FoodPlans.Exists(x => x.GetFinalMoveLoc().EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Hill:
                    if (FoodPlans.Exists(x => x.GetFinalMoveLoc().EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.NewBorn:
                    if (NewBornPlans.Exists(x => x.GetFinalMoveLoc().EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;

                case PlanType.Explore:
                    if (ExplorePlans.Exists(x => x.GetFinalMoveLoc().EqualTo(dest)))
                    {
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
示例#5
0
        public bool HasPlanAnt(Location ant)
        {
            bool food = FoodPlans.Exists(x => x.Ant.EqualTo(ant));

            if (food)
            {
                return(true);
            }

            bool move = MovePlans.Exists(x => x.Ant.EqualTo(ant));

            if (move)
            {
                return(true);
            }

            bool attack = AttackPlans.Exists(x => x.Ant.EqualTo(ant));

            if (attack)
            {
                return(true);
            }

            var born = NewBornPlans.Exists(x => x.Ant.EqualTo(ant));

            if (born)
            {
                return(true);
            }

            var exp = ExplorePlans.Exists(x => x.Ant.EqualTo(ant));

            if (exp)
            {
                return(true);
            }

            // has plan
            return(false);
        }
示例#6
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));
            }
        }