COMP1100
Programming As Problem solving Technical Report
Name: Jie LIU
Laboratory time: Tuesday 13.00-15.00
Uni ID: u6768636
Table of Content
Introduction 2
Content 2
Testing 3
Reflection 4
the program was to parse how game of life invented by Conway works through functional programming we learned in this course. This report show three main sections to introduce the whole programming: Overview introductory of the program, Main Content and Reflection.
Introduction
Based on the rule of game of life, the purpose of designing this program to show whole steps of game about how it works by using functional programming. It works with several functions and each of them corporate with other achieving total goal of Conway game. Then there are some contents of program designing with assumptions, testing and reflections when working on a project.
Content
To briefly and conceptually present each function does. Firstly, data Conway function is types of cells used in Conway’s game of life that totally have two survival status: Alive and Dead. Additionally the purpose of cycleConway function shows cycle of cells life status when function is working. Then renderConway function presents each survival status with matched colors and shapes that will be clearly checked.
Secondly, it is essential to design get function in order to confidently ensure we can successfully get coordinates of cells otherwise it will get nothing when cells are out of grid. Thus, the purpose of allCoords function is presenting lists of cells on the grid and it makes it clear to find next generation status of cells in following steps. Furthermore, with the helper function of allCoord it is to finding lists of coordinates and which makes it clear when cells are on the three conditions of loop based on game of rules.
Thirdly, the most important is to design nextGenConway function in order to generate the whole grid changing based on game of rule. To explain, there are two helper function associated to design this function. Helper1 function is to gain parameters of gridConway and lists of all cells’ coordinates, which will be used to check cell dead or alive. In addition, helper2 function is to check status of survival of other cells’ coordinates in the grid based on counting numbers of cells around each cell. This essential function should corporate with allCoords function and Gridconway function to be well-run. Lastly, evolveConway function is designed to give a presentation of grid when cells evolve for many times.
There are some assumptions that cells are in a exactly long grid which can contains all cells without exceeding its width and height. Otherwise, it will get errors.
Testing
To give some special inputs in the function to ensure the running of program, for example, the coordinate of cell which are (0,0), (1,0) can be inputs to test the function allCoords function, which shows normal operation in the grid. What is more, the coordinates (0,4) and (0,1) are special inputs which adapted in the same allCoords function through the guard. The coordinate of (0,4) will suddenly convert into (0,1) based on the rules of games in the designed program.
Reflection
The first technical issue is confusion of choosing case or guard function when writing functions. It is hard to write case when patterns are not matching therefore it is effective to using guard especially there are several different inputs in the function.
The second technical issue is that how to corporate function with each other and then generate nextGenConway function which is difficult to run correctly. To solve the problem, briefly check the functions written before this steps and then using helper functions which precisely analyze each purposes of steps to generate the whole function of grid, For instance, in nextGen Conway function, it should gain GridConway which presents status of cells in each generation from the last generation. Then it should be split into two helper function to gain list of coordinates matched with status and to gain numbers of cells and their status around each cells on the grid respectively. Therefore, it is easier to identify the cells status changing in each generation.
If I rewrite the program I will use more recursion instead of list all of conditions we considered because it is more efficient to run when using recursion.