Report for Assignment 2 Comp 1100
Student name: Jingping Wang
Lab time: Tue09
Tutors: Joshua Corner Debashin Chakraborty Zoey UID:u7096213
Introduction
A Cellular Automaton is a grid of cells, and a rule that describes how cells change over discrete time steps.
Assumptions
Test Pattern 1 is called a glider. It should run down and to the right, and on an infinite grid, will run forever
Test Pattern 2 is called the Simkin Glider Gun. It runs forever, spitting out gliders above and below.
Program Design
The fist step is to render the cellular automata grids in CodeWorld by implementing cycleConway, toConway, renderConway,Get, allCoords functions. The next step is to make them evolve according to Conway¡¯s rules by implementing nextGenConway ,evolveConway.
toConway
This function helps parseGrid to parse individual characters into cells .It turns a character from a Conway test pattern into a Conway cell.
cycleConway
This function returns the ¡°next¡± type of Conway cell to allow the user to change cells by clicking on them.
renderConway
This function shows how to draw a single cell from the grid according to the rules.
Get
The test program uses this function when it responds to mouse clicks, to pick out the cell that the user is changing.
allCoords
This function return a list of every possible coordinate in a grid of that width and height, in row-major order. The renderer in the test program uses allCoords to decide where to place the Picture of each cell in the grid.
nextGenConway
This function computes the next generation of Conway¡¯s Life according to its rule.
nextGenConway relies on 5 helper functions which are helper2, helper3, helper4, compute, convert.
helper2
This is a helper function of nextGenConway which returns a list that will replace the list in the type Grid c as an output of nextGenConway function and show the states of every single in the next generation.
helper3
This function judges a single cell should alive or not in the next generation according to the rules by calling the compute, convert function.
compute
This is a helper function of compute function.This function computes the number of the alive neighbours of a cell by call helper4 function.
helper4
This is a helper function of compute function.This function will judge a cell alive or not in the next generation and return 1 if the cell is alive to help compute function .
convert
This is a helper function of helper3 function which returns a list eliminating the cells beyond the grid to avoid the situation of the index is too large.
evolveConway
This function evolves the grid a given number of times.
Testing
cycleConway
Enter cycleConway Alive it should return Dead if the function is correct. Enter cycleConway Dead it should return Alive if the function is correct.
Get
If the input is Grid[Dead,Alive,Dead,Dead,Alive,Dead,Alive,Alive,Dead]) (-1,0) it should return Nothing.
If the input is Grid3 3[Dead,Alive,Dead,Dead,Alive,Dead,Alive,Alive,Dead])(1,1)) it should return Just Alive.
allCoords
If the inputs is
(allCoords 3 3 )it should return[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1),
(0,2),(1,2),(2,2)]
nextGenConway
If the input is (Grid 3 3
[Dead,Alive,Dead,Dead,Alive,Dead,Alive,Alive,Dead]))it should return (Grid 3 3 [Dead,Dead,Dead,Dead,Alive,Alive,Alive,Alive,Dead])
evolveConway
If the input is 3 (Grid 3 3 [Dead,Alive,Dead,Dead,Alive,Dead,Alive,Alive,Dead]) It should return (Grid 3 3 [Dead,Alive,Dead,Alive,Dead,Alive,Alive,Dead,Alive]
Reflection
In my work, the nextGenConway functions using too many auxiliary functions makes the code lengthy and some lines of code are too long.