Assignment 3 – The Game of Life UNSW Blogs Home UNSW Wikispaces UNSW Website MyUNSW RSS COMP1400 – Programming for Designers Class announcements for Programming for Designers Assignment 3 – The Game of Life Posted by Claude on October 6th, 2014 · Assignments DUE DATE: 11:59pm Sunday 26 October. WARNING: This is a draft only. These specifications will be updated. For this assignment you will write a program that implements Conway’s Game of Life. The board is a rectangular array in which a cell is designated as either live or dead. A few simple rules tell you how to create a new generation (i.e. a new board) based on the old one. Any live cell with fewer than two live neighbours dies, as if caused by under-population. Any live cell with two or three live neighbours lives on to the next generation. Any live cell with more than three live neighbours dies, as if by overcrowding. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. You can see an animation of the game at this web site. Two supporting classes are provided for you to display the game. You don’t have to write any graphics code. Your task will only be to implement the rules above. You will find a project file for the assignment here and an executable sample here. The project has three classes: Canvas, which handles the primitive drawing on the screen; Grid, is a subclass of canvas and handles drawing the board; and Life, which is the file that you must modify to play the Game of Life. It also has the constructor method that plays the game. Do not, under any circumstances, change the other two classes and do not change the Life constructor method! A board is represented as a 2-dimensional boolean array: boolean[][] board = new boolean[numberOfRows][numberOfColumns]; You are required to three methods. Task 1 The first method you must write is to create a new board with a random number of cells set to true. The chances of a cell being alive (i.e. true) should be 10%. private boolean[][] newBoard(int height, int width) The method has two parameters: the width and height of the board. It must return a 2-dimensional boolean array in which approximately 10% of the cells are set to true (i.e. alive). Task 2 The second method you must write is to count the live neighbours of a cell. private int countNeighbours(boolean[][] board, int row, int col) Given a board (i.e. a 2D boolean array) and a row and column position, count the number of immediately surrounding cells that contain the value true. The table below shows the index values of the neighbours of the cell where i is the row number and j is the column number (starting from zero). i-1, j-1 i-1, j i-1, j+1 i, j-1 i, j i, j+1 i+1, j-1 i+1, j i+1, j+1 Your method should visit each of the surrounding cells and accumulate a count of the cells that contain true, i.e, the cell is live. Note that you do not count the cell itself. If a cell is on the edge of the array (i.e. some of its neighbours are out of bounds), only count the cells that are within the array. Task 3 The third method you must write is: private boolean[][] nextGeneration(boolean[][] board1) The only parameter to the method is a board (i.e. a 2D boolean array). For each cell in the array (i.e. for each column position in each row), apply the four reproduction rules, given above, to create a new board representing the next generation. To do this, you must declare a new array that is the same size as the old one. As you apply the rules to a cell in the old array, you update the corresponding cell in the new array. That is, you must not change the original array. WARNING: The Game of Life is a popular programming exercise and you will find many versions of it on the web. While you may use these to get an idea of how to write your own program, your code must be your own. Plagiarism is not allowed and will be heavily penalised. Submission instructions You will submit your assignment to the Give automated marked system. From within your assignment 3 BlueJ project, select Project -> Create Jar File… In the Dialog Box that appears: Set “Main Class” to none Ensure “Include Source” is checked Leave “Include Bluej project files” unchecked Press “Continue” Save the filename as “Assignment3.jar” Open a web browser and go to the give web site Log-in with you Z-Pass Either enter “COMP1400″ in for the course, or select COMP1400 from the drop down menu and press “Search for Assignments”. Select “assignment3″ from the next drop down menu and press “Upload my Assignment” Accept the student declaration Press “Choose File” and select the “Assignment3.jar” file that you saved in step 4 Press “Submit my Files” Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines: ================================================
Checking your submission...
Checking for Life.java
Life.java Compiled Successfully
Compiling against supplied file Canvas.java
Canvas.java Compiled Successfully
Compiling against supplied file Grid.java
Grid.java Compiled Successfully
All files are OK
================================================ If the page doesn’t load properly, that is OK just submit the assignment file again. If you don’t get the above output check the output to see what went wrong and resubmit. Submission notes: You can submit as many times as you wish, even after the deadline. Only your last submission will be marked. Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work. If you have any problems with submission, email the class account Email to friend Stay updated Tags: No Comments so far ↓ There are no comments yet...Kick things off by filling out the form below. You must log in to post a comment. Pages Course Outline for Semester 2, 2014 For Tutors Lab Times Lecture Notes and Example Files Software Weekly Quizzes Search Categories Announcements Assignments Lab Lectures Uncategorized Links BlueJ web site Submit/Collect Assignments View Marks Staff Claude Sammut (Lecturer) Timothy Wiley (Admin/Tutor) Troy Lenger (Tutor) Sam Ipsen (Tutor) Meta Log in Entries feed Comments feed WordPress.org UNSW Blogs User Tools Username and Password: Lost your password? COMP1400 – Programming for Designers Terms of Use Privacy Policy Copyright and Disclaimer Accessibility Acknowledgements UNSW Sydney NSW 2052 Australia Telephone +61 2 9385 1000 UNSW CRICOS Provider Code 00098G ABN 57 195 873 179 Design by jokay