示例#1
0
        /* Converts a list of Locations to a list of Entities.
         *
         * TODO: Should this method really be static? Maybe all of the methods in this class should be static?
         */
        public static List <Entity> toEntities(Grid g, List <Location> locs)
        {
            List <Entity> Entities = new List <Entity>();

            foreach (Location l in locs)
            {
                Entities.Add(g.Get(l));
            }

            return(Entities);
        }
示例#2
0
 //Fills the Grid with Untouched Cells
 private void PopulateGrid()
 {
     for (int i = 0; (i < Grid.MaxX); i++)
     {
         for (int j = 0; (j < Grid.MaxY); j++)
         {
             Location l = new Location(i, j);
             if ((Grid.Get(l) != this))
             {
                 Grid.Set(new DFScell(Grid, l, this), l);
             }
         }
     }
 }
示例#3
0
        public List <Location> masterAct()
        {
            List <Location> locs = new List <Location>();

            foreach (Location l in Location.GetOrthogonalLocations(Grid))
            {
                if ((Grid.Get(l) == null))
                {
                    locs.Add(l);
                }
            }

            return(locs);
        }
示例#4
0
        private void InitialStepWithNoMinions()
        {
            foreach (Location l in Location.GetOrthogonalLocations(Grid))
            {
                if ((Grid.Get(l) == null))
                {
                    BFSminion m = new BFSminion(Grid, l);
                    Grid.Set(m, l);
                    this.CurrentMinions.Add(m);
                }
            }

            this.Phase++;
            this.Steps++;
        }
示例#5
0
        //ChooseMoveLocations is inherited from Actor

        /* Moves to a new Location, leaving a Touched cell in the old Location.
         * If l == null, then the maze is finished.
         */
        public override bool MakeMove(Location l)
        {
            if ((l == null))
            {
                this.Finish();
                return(true);
            }

            Location storedLoc = this.Location;                         // save current location

            Grid.Get(l).RemoveSelfFromGrid();                           // remove rock in new location
            this.MoveTo(l);                                             // move to new location
            Grid.Set(new DFScell(Grid, storedLoc, 1, this), storedLoc); // place new rock in old location

            return(true);
        }
示例#6
0
        protected override void DoCustomStartWork()
        {
            this.Target = new Location(Grid.MaxX - 1, Grid.MaxY - 1);

            for (int i = 0; i < Grid.MaxX; i++)
            {
                for (int j = 0; j < Grid.MaxY; j++)
                {
                    if (Grid.Get(i, j) == null)
                    {
                        this.MoveFromSideline(i, j);
                        return;
                    }
                }
            }
        }
示例#7
0
 //Searches entire Grid, first changing trapped Untouched cells to Rocks,
 //Then removes all remaining cells that are not Rocks.
 private void RemoveJunkFromGrid()
 {
     for (int i = 0; i < Grid.MaxX; i++)
     {
         for (int j = 0; j < Grid.MaxY; j++)
         {
             Entity e = Grid.Get(new Location(i, j));
             if ((e is DFScell))
             {
                 this.RemoveUntouchedCellsInsideRocks(e);
                 if (((DFScell)(e)).State != DFScell.Rock || ((DFScell)(e)).Salted)
                 {
                     e.RemoveSelfFromGrid();
                 }
             }
         }
     }
 }
示例#8
0
 private void DrawGrid()
 {
     MazeWorld.Grid g = Maze;
     for (int i = 0; i < g.MaxX; i++)
     {
         for (int j = 0; j < g.MaxY; j++)
         {
             Vector3Int pos = new Vector3Int(i, j, 0);
             Entity     e   = g.Get(i, j);
             if (e != null)
             {
                 UnityEngine.Color c = ColorMap.ConvertColor(e.Color);
                 tileMap.SetColor(pos, c);
             }
             else
             {
                 // If there is no entity, then set the color to white
                 tileMap.SetColor(pos, UnityEngine.Color.white);
             }
         }
     }
 }
示例#9
0
        /* At each step, all CurrentMinions spawn new Minions in all the open spots adjacent to them.
         * These new RecruitMinions then replace the CurrentMinions, and CurrentMinions become Cells
         * All cells also update their color pattern to reflect distance traveled.
         */
        private void StepWithMinions()
        {
            foreach (BFSminion m in this.CurrentMinions)
            {
                foreach (Location l in m.masterAct())
                {
                    this.addMinion(l);
                }

                Location minionLoc = m.Location;
                BFScell  bCell     = new BFScell(Grid, minionLoc, this);
                Cells.Add(bCell);
            }

            foreach (BFScell b in Cells)
            {
                b.UpdateColors();
            }

            this.killMinions();
            this.Steps++;

            if (this.CurrentMinions.Count() == 0)
            {
                if (!(Grid.Get(Target) is BFSminion || Grid.Get(Target) is BFScell))
                {
                    Grid.Reset();
                    CurrentMinions.Clear();
                    RecruitMinions.Clear();
                    Cells.Clear();
                    Phase = 1;
                    Steps = 0;
                    return;
                }
                this.Phase++;
                Grid.Remove(Location);
                MoveTo(Target);
            }
        }
示例#10
0
 public List <Location> getFullLocations(Grid g, List <Location> locs)
 {
     locs.RemoveAll(l => g.Get(l) == null);
     return(locs);
 }