Grid: The grid of bacterial cells could be stored in a 2-dimensional array, but arrays in C lack some features and are generally difficult for new students to use. For example, the following text might be the contents of a file simple.txt, a 5x9 grid with 3 initially live cells: 5 ← number of rows tall The input files will exist in the same working directory as your program. The input file might contain additional lines of information after the grid lines, such as comments by its author or even junk/garbage data any such content should be ignored by your program. Each grid character will be either a '-' (minus sign) for an empty dead cell, or an 'X' (uppercase X) for a living cell. The next lines of the file will contain the grid itself, a set of characters of size r x c with a line break (\n) after each row. In each input file, the first two lines will contain integers r and c representing the number of rows and columns in the grid, respectively. You may also assume that the input file name typed by the user does not contain any spaces. The behavior of your program in such a case is not defined in this spec it can crash, it can terminate, etc. You do not need to write any code to handle a misformatted file. If it does exist, you may assume that all of its contents are valid. When your program reads the grid file, you should re-prompt the user if the file specified does not exist. The grid of bacteria in your program gets its initial state from one of a set of provided input text files, which follow a particular format. This is called a "stable" pattern or a "still life". The pattern at right does not change on each iteration, because each cell has exactly three living neighbors. The two patterns should alternate forever: Any changes (births or deaths) in a given generation k start to have effect on other neighboring cells in generation k 1.Ĭheck your understanding of the game rules by looking at the following example. When you are computing a new generation, new births/deaths in that generation don't impact other cells in that generation. The births and deaths that transform one generation to the next all take effect simultaneously. If there was a cell in that location, it dies of overcrowding. If it currently contains a cell, the cell remains.Ī location with four or more neighbors will be empty in the next generation. If it was unoccupied before, a new cell is born. A location with three neighbors will contain a cell in the next generation.If it had a cell, it still contains a cell. A location with two neighbors is stable.A location that has zero or one neighbors will be empty in the next generation.The simulation starts with an initial pattern of cells on the grid and computes successive generations of cells according to the following rules: 24 Breadth First Search and Depth First Search.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |