nationoreo.blogg.se

Conway game of life question
Conway game of life question












conway game of life question
  1. #Conway game of life question movie#
  2. #Conway game of life question code#

PCols = eCol - sCol + 1 % Reset pattern column size to fitīoard(sRow:eRow, sCol:eCol) = pattern(1:pRows, 1:pCols) % Put on board end PRows = eRow - sRow + 1 % Reset pattern row size to fit = size(pattern) % Get pattern number of rows and columns % Only put pattern on the board if the starting position is on the board if sRow < bRows & sCol < bCols % Is pattern on board at all? % Calculate start and ending position of pattern on the boardĮRow = min(sRow + pRows - 1, bRows) %Take as many rows as fitĮCol = min(sCol + pCols - 1, bCols) %Take as many columns as fit % Figure out how much of pattern to put on = size(board) % Get board number of rows and columns SCol = 97 % Column of upper left pattern corner SRow = 95 % Row of upper left pattern corner You should see a Figure Window with a picture of the board: EXAMPLE 3: Put rectangular pattern on a board (throw away part over edge) Image(~board) % Reverse board to display 1's in blackĪxis image % Images are square and have origin in upper left EXAMPLE 2: Display the board as an image with the origin in upper leftĬreate a new cell in which you type and execute: theTitle = '10x10 pattern on 100x100 board' Ĭolormap(gray(2)) % Black for 0's, white for 1's

#Conway game of life question code#

This code creates a 100 x 100 board of 0's with a 10x10 square of 1's placed starting at (20, 5). You should see pattern, board, sRow, sCol, pRows, pCols, eRow, and eCol variables in your Workspace. = size(pattern) % Get the size of the patternĮRow = sRow + pRows - 1 % Row of lower right pattern cornerĮCol = sCol + pCols - 1 % Column of lower right pattern cornerīoard(sRow:eRow, sCol:eCol) = pattern % Put pattern on board SCol = 5 % Column of upper left pattern corner SRow = 20 % Row of upper left pattern corner Create a TwoDimensionalArrayScript script file in your TwoDimensionalArrays directory.ĮXAMPLE 1: Put rectangular pattern on a board (assuming it fits)Ĭreate a new cell in which you type and execute: pattern = true(10, 10) % Create a 10 x 10 patternīoard = false(100, 100) % Create a 100 x 100 board.Create a TwoDimensionalArrays directory on your V: drive and make it your current directory.EXAMPLE 23: Call the showLife function to animate a game of life.EXAMPLE 22: Develop a showLife function based on EXAMPLE 21.EXAMPLE 21: The glider moving on a 50x50 board.EXAMPLE 20: Call updateBoard to move the glider using rules of life.EXAMPLE 19: Setup a board with a glider to test updateBoard.EXAMPLE 18: Develop an updateBoard function based on EXAMPLE 17.EXAMPLE 17: Implement a step in the game of life.EXAMPLE 16: Call getLiveNeighbors to analyze several positions on a board.EXAMPLE 15: Develop a getLiveNeighbors function based on EXAMPLE 14.EXAMPLE 14: Find number of live neighbors of a cell board(r, c).EXAMPLE 13: Call the isLive function to test different board positions.EXAMPLE 12: Develop an isLive function based on EXAMPLE 11.EXAMPLE 11: Find out whether cell board(r, c) is live (true) on the board.EXAMPLE 10: Call orBoardPattern to initialize a board.EXAMPLE 9: Create an orBoardPattern function to logical OR a board pattern.EXAMPLE 8: Display a board with multiple patterns.

#Conway game of life question movie#

  • EXAMPLE 7: Make a movie of a pattern moving on a board.
  • EXAMPLE 6: Call addBoardPattern to add a 10x5 rectangle to a board.
  • EXAMPLE 5: Develop a addBoardPattern function based on EXAMPLE 3.
  • EXAMPLE 4: Display the board of EXAMPLE 3, where part of pattern is lost.
  • conway game of life question

    EXAMPLE 3: Put rectangular pattern on a board (throw away part over edge).EXAMPLE 2: Display the board as an image with the origin in upper left.EXAMPLE 1: Put rectangular pattern on a board (assuming it fits).

    conway game of life question

    We are going to implement life using an array with fixed boundaries.įor a nice discussion about the game of life as well as many potential patterns that you might try for Lab 10, please see the wikipedia article Contents Ordinarily, life is played on an infinite board. The game has been shown to have the power of a universal Turing machine, which means that it is capable of computing anything that can be formulated as an algorithm. From a theoretical point of view life is interesting for many reasons. The game was introduced in the "Mathematical Games" column of the October 1970 issue of Scientific American and gave birth to the research area of cellular automata, as well as to many ideas about self-organization and evolution.

  • A cell with exactly three live neighbours cells will have a live cell at the next step (birth).
  • A live cell with two or three live neighbours lives (stable condition).
  • A live cell with more than three live neighbours dies (overcrowding).
  • A live cell with fewer than two live neighbours dies (underpopulation).













  • Conway game of life question