protected Vector2i[] AliveNeighbours(Vector2i v,int amount)
        {
            List<Vector2i> neighbours = new List<Vector2i>();
            switch(neighbour){
                case Neighbour.VonNeumann:
                    neighbours = VonNeumannNeighbours(v);
                    break;
                case Neighbour.Moores:
                    neighbours = MooresNeighbours(v);
                    break;
                case Neighbour.Conway:
                    neighbours = ConwayNeighbours(v);
                    break;
                default:
                    neighbours = VonNeumannNeighbours(v);
                    break;
            }

            for(int i=0;i<neighbours.Count&&i<amount;i++)
                if(board[neighbours[i].x,neighbours[i].y].alive==true)
                    neighbours.RemoveAt(i);
            return neighbours.ToArray();
        }
Beispiel #2
0
 public Vector2i(Vector2i a)
 {
     x = a.x;
     y = a.y;
 }
        protected List<Vector2i> VonNeumannNeighbours(Vector2i v, int d)
        {
            List<Vector2i> neighbours = new List<Vector2i>();

            for(int i=0;i<d;i++){
                neighbours.Add(new Vector2i(v.x,v.y+1+i));
                neighbours.Add(new Vector2i(v.x+1+i,v.y));
                neighbours.Add(new Vector2i(v.x,v.y-1-i));
                neighbours.Add(new Vector2i(v.x-1-i,v.y));
            }

            //Check if the cells are in bounds
            for(int i=0;i<neighbours.Count;++i)
                if(isOutsideBounds(neighbours[i]))
                    neighbours.RemoveAt(i);
            return neighbours;
        }
 public virtual bool CellGen()
 {
     size -= 1; //Drop size to the amount displayed by inspector
     Init ();
     return true;
 }
 protected virtual void SetDead(Vector2i[] targets)
 {
     for(int i=0;i<targets.Length;++i)
         board[targets[i].x,targets[i].y].alive = false;
 }
 protected virtual void SetAlive(Vector2i[] targets)
 {
     for(int i=0;i<targets.Length;++i){
         board[targets[i].x,targets[i].y].alive = true;
     }
 }
 protected Vector2i[] Neighbours(Vector2i v,int amount)
 {
     List<Vector2i> neighbours = new List<Vector2i>();
     switch(neighbour){
         case Neighbour.VonNeumann:
             neighbours = VonNeumannNeighbours(v);
             break;
         case Neighbour.Moores:
             neighbours = MooresNeighbours(v);
             break;
         case Neighbour.Conway:
             neighbours = ConwayNeighbours(v);
             break;
         default:
             neighbours = VonNeumannNeighbours(v);
             break;
     }
     return neighbours.ToArray();
 }
        protected List<Vector2i> MooresNeighbours(Vector2i v)
        {
            List<Vector2i> neighbours = new List<Vector2i>();

            neighbours.Add(new Vector2i(v.x,v.y+1));
            neighbours.Add(new Vector2i(v.x+1,v.y+1));
            neighbours.Add(new Vector2i(v.x+1,v.y));
            neighbours.Add(new Vector2i(v.x+1,v.y-1));
            neighbours.Add(new Vector2i(v.x,v.y-1));
            neighbours.Add(new Vector2i(v.x-1,v.y-1));
            neighbours.Add(new Vector2i(v.x-1,v.y));
            neighbours.Add(new Vector2i(v.x-1,v.y+1));

            //Check if the cells are in bounds
            for(int i=0;i<neighbours.Count;++i)
                if(isOutsideBounds(neighbours[i]))
                    neighbours.RemoveAt(i);
            return neighbours;
        }
 protected bool isOutsideBounds(Vector2i v)
 {
     if(v.x>size.x-1||v.y>size.y-1||v.x<0||v.y<0)
         return true;
     return false;
 }