{"id":778,"date":"2014-10-06T12:02:16","date_gmt":"2014-10-06T01:02:16","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=778"},"modified":"2014-10-16T10:02:29","modified_gmt":"2014-10-15T23:02:29","slug":"assignment-3-the-game-of-life-draft-only","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2014\/10\/assignment-3-the-game-of-life-draft-only\/","title":{"rendered":"Assignment 3 &#8211; The Game of Life"},"content":{"rendered":"<p><strong>DUE DATE: 11:59pm Sunday 26 October.<\/strong><\/p>\n<p><strong>WARNING: This is a draft only. These specifications will be updated.<\/strong><\/p>\n<p>For this assignment you will write a program that implements Conway\u2019s\u00a0<em>Game of Life<\/em>. The board is a rectangular array in which a cell is designated as either\u00a0<strong>live<\/strong> or\u00a0<strong>dead<\/strong>. A few simple rules tell you how to create a new generation (i.e. a new board) based on the old one.<\/p>\n<ol>\n<li>Any live cell with fewer than two live neighbours dies, as if caused by under-population.<\/li>\n<li>Any live cell with two or three live neighbours lives on to the next generation.<\/li>\n<li>Any live cell with more than three live neighbours dies, as if by overcrowding.<\/li>\n<li>Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.<\/li>\n<\/ol>\n<p>You can see an animation of the game at\u00a0<a title=\"Game of Life\" href=\"http:\/\/www.bitstorm.org\/gameoflife\/\" target=\"_blank\">this web site<\/a>. Two supporting classes are provided for you to display the game. You don&#8217;t have to write any graphics code. Your task will only be to implement the rules above.<\/p>\n<p>You will find a project file for the assignment\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/14s2\/assignments\/Assignment3.zip\">here<\/a> and an executable sample <a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/14s2\/assignments\/Life%20(sample%20solution).zip\">here<\/a>.<\/p>\n<p>The project has three classes: C<strong>anvas<\/strong>, which handles the primitive drawing on the screen; <strong>Grid,<\/strong> is a subclass of canvas and handles drawing the board; and <strong>Life<\/strong>, which is the file that you must modify to play the Game of Life. It also has the constructor method that plays the game. <strong><em>Do not, under any circumstances, change the other two classes and do not change the Life constructor method!<\/em><\/strong><\/p>\n<p>A board is represented as a 2-dimensional boolean array:<\/p>\n<p><code>boolean[][] board = new boolean[numberOfRows][numberOfColumns];<\/code><\/p>\n<p><strong>You are required to three methods.<\/strong><\/p>\n<p><strong>Task 1<\/strong><\/p>\n<p>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%.<\/p>\n<p><code>private boolean[][] newBoard(int height, int width)<\/code><\/p>\n<p>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).<\/p>\n<p><strong>Task 2<\/strong><\/p>\n<p>The second method you must write is to count the live neighbours of a cell.<\/p>\n<p><code>private int countNeighbours(boolean[][] board, int row, int col)<br \/>\n<\/code><\/p>\n<p>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\u00a0<em>i<\/em> is the row number and\u00a0<em>j<\/em> is the column number (starting from zero).<\/p>\n<table border=\"1\" cellpadding=\"10\">\n<tbody>\n<tr valign=\"middle\">\n<td>i-1, j-1<\/td>\n<td>i-1, j<\/td>\n<td>i-1, j+1<\/td>\n<\/tr>\n<tr valign=\"middle\">\n<td>i, j-1<\/td>\n<td>i, j<\/td>\n<td>i, j+1<\/td>\n<\/tr>\n<tr valign=\"middle\">\n<td>i+1, j-1<\/td>\n<td>i+1, j<\/td>\n<td>i+1, j+1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Your method should visit each of the surrounding cells and accumulate a count of the cells that contain\u00a0<strong>true<\/strong>, 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.<\/p>\n<p><strong>Task 3<\/strong><\/p>\n<p>The third method you must write is:<\/p>\n<p><code>private boolean[][] nextGeneration(boolean[][] board1)<br \/>\n<\/code><\/p>\n<p>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.<\/p>\n<p><strong>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.<\/strong><\/p>\n<h3>Submission instructions<\/h3>\n<p>You will submit your assignment to the Give automated marked system.<\/p>\n<ol>\n<li>From within your assignment 3 BlueJ project, select Project -&gt; Create Jar File\u2026<\/li>\n<li>In the Dialog Box that appears:\n<ol type=\"a\">\n<li>Set \u201cMain Class\u201d to none<\/li>\n<li>Ensure \u201cInclude Source\u201d is checked<\/li>\n<li>Leave \u201cInclude Bluej project files\u201d unchecked<\/li>\n<\/ol>\n<\/li>\n<li>Press \u201cContinue\u201d<\/li>\n<li>Save the filename as \u201cAssignment3.jar\u201d<\/li>\n<li>Open a web browser and go to\u00a0<a href=\"https:\/\/cgi.cse.unsw.edu.au\/~give\/Student\/give.php\">the give web site<\/a><\/li>\n<li>Log-in with you Z-Pass<\/li>\n<li>Either enter \u201cCOMP1400\u2033 in for the course, or select COMP1400 from the drop down menu and press \u201cSearch for Assignments\u201d.<\/li>\n<li>Select \u201cassignment3\u2033 from the next drop down menu and press \u201cUpload my Assignment\u201d<\/li>\n<li>Accept the student declaration<\/li>\n<li>Press \u201cChoose File\u201d and select the \u201cAssignment3.jar\u201d file that you saved in step 4<\/li>\n<li>Press \u201cSubmit my Files\u201d<\/li>\n<li>Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:\n<pre>================================================\r\nChecking your submission...\r\n\r\nChecking for Life.java\r\n    Life.java Compiled Successfully\r\nCompiling against supplied file Canvas.java\r\n    Canvas.java Compiled Successfully\r\nCompiling against supplied file Grid.java\r\n    Grid.java Compiled Successfully\r\n\r\nAll files are OK\r\n================================================<\/pre>\n<\/li>\n<li>If the page doesn\u2019t load properly, that is OK just submit the assignment file again.<\/li>\n<li>If you don\u2019t get the above output check the output to see what went wrong and resubmit.<\/li>\n<\/ol>\n<p>Submission notes:<\/p>\n<ol>\n<li>You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.<\/li>\n<li>Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.<\/li>\n<li>If you have any problems with submission, email\u00a0<a href=\"mailto:is1609@cse.unsw.edu.au\">the class account<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s\u00a0Game of Life. The board is a rectangular array in which a cell is designated as either\u00a0live or\u00a0dead. A few simple rules tell you how to create a [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[468],"tags":[],"class_list":["post-778","post","type-post","status-publish","format-standard","hentry","category-assignments"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=778"}],"version-history":[{"count":13,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/778\/revisions"}],"predecessor-version":[{"id":781,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/778\/revisions\/781"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}