Sunteți pe pagina 1din 4

----------------------------------------------------------------------------------------------(The program should be in Python (3.

x), please write comments when appropriate) Your program should simulate the game of life Background ---------The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.[1] The "game" is a zero-player game, meaning that its evolution is determined by it s initial state, requiring no further input. One interacts with the Game of Life by creating an i nitial configuration and observing how it evolves. Rules ----The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, or (in other words, a matrix) each of which is in one of two possible states, al ive or dead. You have a choice of either working with a fixed size matrix of 10x10 or to acce pt a parameter: n that will determine the size of the matrix (nxn) Every cell interacts with its eight (or less) neighbours, which are the cells th at are horizontally, vertically, or diagonally adjacent. At each step in time, the following transiti ons occur: Any live cell -population. Any live cell on. Any live cell ng. Any dead cell y reproduction. with fewer than two live neighbors dies, as if caused by under with two or three live neighbors lives on to the next generati with more than three live neighbours dies, as if by overcrowdi with exactly three live neighbors becomes a live cell, as if b

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed births and deaths occur sim ultaneously, and the discrete moment at which this happens is sometimes called a tick (in oth er words, each generation is a pure function of the preceding one). This rule allows to scan th e matrix in any order and get the same result (as opposed to what I had mentioned in class). The rules continue to be applied repeatedly to create further generations.

Objective --------The program prompts the user for board size (optional, if not given, 10 is selec ted), it then prompts the user for a sequence of coordinates in the format: (a,b,c,d,e,f) - ev ery two adjacent numbers are a pair of coordinates. The left is the row and the right is the column (or the left is which sub-list, and the right which element of that sub-list) The program checks the validity, ensuring we have even number of values and all within the board and it prints: either: Bad input (if any of the coordinate was illegal, or odd number of coordinates) or How many generations to simulate? The program then simulates the game according to the above 4 rules, using an ast erisk to denote a 'live' cell, or space for a 'dead' cell, and prints generation 0 (draws the bo ard) as the initial state, and subsequent generations with the title of the generatio n number. So for every generation the program prints the generation number and underneath, draws the board representing the live and dead inhabitants of the community. Here is an example: ------------------PGM says: Welcome to the game of LIFE. Please let me know what board size, hit <enter> fo r default of 10: User enters: 5 <enter> PGM says: Please seed the live cells of the board as a set of coordinates (a,b,c,d,...) : User enters: (3,) <enter> PGM says: Illegal set. Please seed the live cells of the board as a set of coordinates (a,b,c,d,...) : User enters: (1,1,2,1,2,2,0,3,3,3,3,4,4,3) <enter> PGM says: ok, What's the next cell? User enters: (0,3) <enter> PGM says: ok, What's the next cell?

User enters: (3,3) <enter> PGM says: ok, What's the next cell? User enters: end <enter> PGM says: How many generations would you like me to simulate? User enters: 3 <enter> Output: Generation 0 - The initial state of the game of life is: +---+---+---+---+---+ * +---+---+---+---+---+ * +---+---+---+---+---+ * * +---+---+---+---+---+ * * +---+---+---+---+---+ * +---+---+---+---+---+ Generation 1 +---+---+---+---+---+ +---+---+---+---+---+ * +---+---+---+---+---+ * * * +---+---+---+---+---+ * * +---+---+---+---+---+ * * +---+---+---+---+---+ Generation 2 +---+---+---+---+---+ +---+---+---+---+---+ * +---+---+---+---+---+ * * * +---+---+---+---+---+ +---+---+---+---+---+ * * +---+---+---+---+---+

Generation 3 +---+---+---+---+---+ +---+---+---+---+---+ * +---+---+---+---+---+ * +---+---+---+---+---+ * +---+---+---+---+---+ +---+---+---+---+---+

Simulation ended.

S-ar putea să vă placă și