Ejemplo n.º 1
0
        private void startBtn_Click(object sender, EventArgs e)
        {
            t = Convert.ToInt32(tBox.Text);

            for (int k = 0; k < t; k++)
            {
                for (int i = 0; i < gameBoard.GetLength(0); i++)
                {
                    for (int j = 0; j < gameBoard.GetLength(1); j++)
                    {
                        int cellCount;
                        if (MooreRadioBtn.Checked == true)
                        {
                            if (i != 0 && j != 0 && i != gameBoard.GetLength(0) - 1 && j != gameBoard.GetLength(1) - 1)
                            {
                                cellCount = CA.CheckInnerBoardCellsMoore(pomBoard, i, j);
                            }
                            else
                            {
                                cellCount = CA.CheckBorderBoardCellsMoore(pomBoard, i, j);
                            }
                        }
                        else
                        {
                            if (i != 0 && j != 0 && i != gameBoard.GetLength(0) - 1 && j != gameBoard.GetLength(1) - 1)
                            {
                                cellCount = CA.CheckInnerBoardCellsNeumann(pomBoard, i, j);
                            }
                            else
                            {
                                cellCount = CA.CheckBorderBoardCellsNeumann(pomBoard, i, j);
                            }
                        }

                        if (cellCount == 3)
                        {
                            gameBoard[i, j] = 1;
                        }
                        else if (cellCount == 2 && gameBoard[i, j] == 1)
                        {
                            gameBoard[i, j] = 1;
                        }
                        else if (cellCount < 2 || cellCount > 3)
                        {
                            gameBoard[i, j] = 0;
                        }
                    }
                }
                gameBox.Refresh();
                MakeChart();
                chartCells.Update();
                var equal = pomBoard.Rank == gameBoard.Rank && Enumerable.Range(0, pomBoard.Rank).All(dimension => pomBoard.GetLength(dimension) == gameBoard.GetLength(dimension)) && pomBoard.Cast <int>().SequenceEqual(gameBoard.Cast <int>());
                if (equal)
                {
                    break;
                }
                pomBoard = (int[, ])gameBoard.Clone();
                if (stepSpeedBox.SelectedIndex == 1)
                {
                    Thread.Sleep(30);
                }
                else if (stepSpeedBox.SelectedIndex == 2)
                {
                    Thread.Sleep(100);
                }
            }
            deadPercent.Clear();
            alivePercent.Clear();
        }