![]() ![]() You defined depth as 3, but, you're only using 2 strings (one for the alive-or-dead, and the second for the neighbours-count). Timer1.Interval = Convert.ToInt32(1000 / GenXSec.Value) Private void GenXSec_ValueChanged(object sender, EventArgs e) Control how many generations in each second by changing the value NextGen() //Hace que transcurra una generación Private void NextGenBttn_Click(object sender, EventArgs e) You can pass generations manually by pressing Next Gen Button Private void ResetBttn_Click(object sender, EventArgs e)ĬellGrid = "dead" // Kill all cells Its actually one of the first things I coded for Windows Phone. If (StartBtn.Text = "Start" | StartBtn.Text = "Resume") Its not super complex to code and its a good exercise for those interested in 2D graphics. Private void StartBtn_Click(object sender, EventArgs e) When pressing the Start button, generations will start passing automatically Private void timer1_Tick(object sender, EventArgs e) Each tick of the timer will be a generation Each generation that passes updates the grid following the rules Panel1.Size = new Size(cellWidth * columns, cellHeight * rows) Public void Form1_Load(object sender, EventArgs e) Add the Panel and Populate with the cells Panel Panel1 = new Panel() // A panel where the cells will be laid out String cellGrid = new string // This is the array that will hold the cell's information Int cellHeight = 20 // Height of the cells which will also be used to determine position Int cellWidth = 20 // With of the cells which will also be used to determine positions Static int depth = 3 // Depth of the Grid Static int rows = 20 // Rows the Grid will have Static int columns = 30 // Columns the Grid will have I'll basically use an array to store data and buttons to represent the cells Some parameters to use throughout the program The rules continue to be applied repeatedly to create further generations. The first generation is created by applying the above rules simultaneously to every cell in the seed-births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). ![]() The initial pattern constitutes the seed of the system. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. ![]() Any live cell with more than three live neighbours dies, as if by overcrowding. Any live cell with two or three live neighbours lives on to the next generation. Any live cell with fewer than two live neighbours dies, as if caused by under-population. At each step in time, the following transitions occur: Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Mostly I want to know if my code is readable, clean, understandable, etc. This is my first project, a 'Minimum Viable Product' implementation of Conway's Game of Life in C#. I want to learn how to write clean code from the start. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |