Пример #1
0
        private int GetLifeValue(GamePiece piece)
        {
            int retVal    = 0;
            int neighbors = 0;
            int x         = piece.coordinates.xIndex;
            int y         = piece.coordinates.yIndex;

            if (x - 1 >= 0)
            {
                if (((GamePiece)(this.hashtable[(x - 1).ToString() + y.ToString()])).isAlive == 1)
                {
                    neighbors += 1;
                }
                if (y - 1 >= 0)
                {
                    if (((GamePiece)(this.hashtable[(x - 1).ToString() + (y - 1).ToString()])).isAlive == 1)
                    {
                        neighbors += 1;
                    }
                }
                if (y + 1 < 5)
                {
                    if (((GamePiece)(this.hashtable[(x - 1).ToString() + (y + 1).ToString()])).isAlive == 1)
                    {
                        neighbors += 1;
                    }
                }
            }
            if (x + 1 < 5)
            {
                if (((GamePiece)(this.hashtable[(x + 1).ToString() + y.ToString()])).isAlive == 1)
                {
                    neighbors += 1;
                }
                if (y - 1 >= 0)
                {
                    if (((GamePiece)(this.hashtable[(x + 1).ToString() + (y - 1).ToString()])).isAlive == 1)
                    {
                        neighbors += 1;
                    }
                }
                if (y + 1 < 5)
                {
                    if (((GamePiece)(this.hashtable[(x + 1).ToString() + (y + 1).ToString()])).isAlive == 1)
                    {
                        neighbors += 1;
                    }
                }
            }
            if (y - 1 >= 0)
            {
                if (((GamePiece)(this.hashtable[(x).ToString() + (y - 1).ToString()])).isAlive == 1)
                {
                    neighbors += 1;
                }
            }
            if (y + 1 < 5)
            {
                if (((GamePiece)(this.hashtable[(x).ToString() + (y + 1).ToString()])).isAlive == 1)
                {
                    neighbors += 1;
                }
            }

            if ((neighbors == 2 || neighbors == 3) && piece.isAlive == 1)
            {
                retVal = 1;
            }
            else if (neighbors == 3 && piece.isAlive == 0)
            {
                retVal = 1;
            }
            return(retVal);
        }
Пример #2
0
 public GameBoard()
 {
     piece00 = new GamePiece()
     {
         coordinates = new Coordinates(0, 0), isAlive = 0
     };
     piece01 = new GamePiece()
     {
         coordinates = new Coordinates(0, 1), isAlive = 1
     };
     piece02 = new GamePiece()
     {
         coordinates = new Coordinates(0, 2), isAlive = 1
     };
     piece03 = new GamePiece()
     {
         coordinates = new Coordinates(0, 3), isAlive = 0
     };
     piece04 = new GamePiece()
     {
         coordinates = new Coordinates(0, 4), isAlive = 1
     };
     piece10 = new GamePiece()
     {
         coordinates = new Coordinates(1, 0), isAlive = 1
     };
     piece11 = new GamePiece()
     {
         coordinates = new Coordinates(1, 1), isAlive = 0
     };
     piece12 = new GamePiece()
     {
         coordinates = new Coordinates(1, 2), isAlive = 1
     };
     piece13 = new GamePiece()
     {
         coordinates = new Coordinates(1, 3), isAlive = 1
     };
     piece14 = new GamePiece()
     {
         coordinates = new Coordinates(1, 4), isAlive = 0
     };
     piece20 = new GamePiece()
     {
         coordinates = new Coordinates(2, 0), isAlive = 0
     };
     piece21 = new GamePiece()
     {
         coordinates = new Coordinates(2, 1), isAlive = 0
     };
     piece22 = new GamePiece()
     {
         coordinates = new Coordinates(2, 2), isAlive = 0
     };
     piece23 = new GamePiece()
     {
         coordinates = new Coordinates(2, 3), isAlive = 0
     };
     piece24 = new GamePiece()
     {
         coordinates = new Coordinates(2, 4), isAlive = 0
     };
     piece30 = new GamePiece()
     {
         coordinates = new Coordinates(3, 0), isAlive = 0
     };
     piece31 = new GamePiece()
     {
         coordinates = new Coordinates(3, 1), isAlive = 1
     };
     piece32 = new GamePiece()
     {
         coordinates = new Coordinates(3, 2), isAlive = 0
     };
     piece33 = new GamePiece()
     {
         coordinates = new Coordinates(3, 3), isAlive = 0
     };
     piece34 = new GamePiece()
     {
         coordinates = new Coordinates(3, 4), isAlive = 0
     };
     piece40 = new GamePiece()
     {
         coordinates = new Coordinates(4, 0), isAlive = 0
     };
     piece41 = new GamePiece()
     {
         coordinates = new Coordinates(4, 1), isAlive = 1
     };
     piece42 = new GamePiece()
     {
         coordinates = new Coordinates(4, 2), isAlive = 1
     };
     piece43 = new GamePiece()
     {
         coordinates = new Coordinates(4, 3), isAlive = 0
     };
     piece44 = new GamePiece()
     {
         coordinates = new Coordinates(4, 4), isAlive = 1
     };
     hashtable = new Hashtable();
     hashtable.Add(piece00.coordinates.xIndex.ToString() + piece00.coordinates.yIndex.ToString(), piece00);
     hashtable.Add(piece01.coordinates.xIndex.ToString() + piece01.coordinates.yIndex.ToString(), piece01);
     hashtable.Add(piece02.coordinates.xIndex.ToString() + piece02.coordinates.yIndex.ToString(), piece02);
     hashtable.Add(piece03.coordinates.xIndex.ToString() + piece03.coordinates.yIndex.ToString(), piece03);
     hashtable.Add(piece04.coordinates.xIndex.ToString() + piece04.coordinates.yIndex.ToString(), piece04);
     hashtable.Add(piece10.coordinates.xIndex.ToString() + piece10.coordinates.yIndex.ToString(), piece10);
     hashtable.Add(piece11.coordinates.xIndex.ToString() + piece11.coordinates.yIndex.ToString(), piece11);
     hashtable.Add(piece12.coordinates.xIndex.ToString() + piece12.coordinates.yIndex.ToString(), piece12);
     hashtable.Add(piece13.coordinates.xIndex.ToString() + piece13.coordinates.yIndex.ToString(), piece13);
     hashtable.Add(piece14.coordinates.xIndex.ToString() + piece14.coordinates.yIndex.ToString(), piece14);
     hashtable.Add(piece20.coordinates.xIndex.ToString() + piece20.coordinates.yIndex.ToString(), piece20);
     hashtable.Add(piece21.coordinates.xIndex.ToString() + piece21.coordinates.yIndex.ToString(), piece21);
     hashtable.Add(piece22.coordinates.xIndex.ToString() + piece22.coordinates.yIndex.ToString(), piece22);
     hashtable.Add(piece23.coordinates.xIndex.ToString() + piece23.coordinates.yIndex.ToString(), piece23);
     hashtable.Add(piece24.coordinates.xIndex.ToString() + piece24.coordinates.yIndex.ToString(), piece24);
     hashtable.Add(piece30.coordinates.xIndex.ToString() + piece30.coordinates.yIndex.ToString(), piece30);
     hashtable.Add(piece31.coordinates.xIndex.ToString() + piece31.coordinates.yIndex.ToString(), piece31);
     hashtable.Add(piece32.coordinates.xIndex.ToString() + piece32.coordinates.yIndex.ToString(), piece32);
     hashtable.Add(piece33.coordinates.xIndex.ToString() + piece33.coordinates.yIndex.ToString(), piece33);
     hashtable.Add(piece34.coordinates.xIndex.ToString() + piece34.coordinates.yIndex.ToString(), piece34);
     hashtable.Add(piece40.coordinates.xIndex.ToString() + piece40.coordinates.yIndex.ToString(), piece40);
     hashtable.Add(piece41.coordinates.xIndex.ToString() + piece41.coordinates.yIndex.ToString(), piece41);
     hashtable.Add(piece42.coordinates.xIndex.ToString() + piece42.coordinates.yIndex.ToString(), piece42);
     hashtable.Add(piece43.coordinates.xIndex.ToString() + piece43.coordinates.yIndex.ToString(), piece43);
     hashtable.Add(piece44.coordinates.xIndex.ToString() + piece44.coordinates.yIndex.ToString(), piece44);
 }