Assignment 2 UNSW Blogs Home UNSW Wikispaces UNSW Website MyUNSW RSS COMP1400 – Programming for Designers Class announcements for Programming for Designers Assignment 2 Posted by malcolmr on August 23rd, 2012 · Assignments NOTE: This assignment is due by midnight Friday Sunday Sept 16 (the end of week 8). [Corrected] 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. We will not build a graphical display like that one (although that animation is written in Java too). Instead, we will print each generation to the console For example, .............................. .............................. .............................. .............................. .............................. .............................. .............................. .............................. ..***......................... ....*......................... ..*........................... .............................. You will find a project file for the assignment here. It contains methods for reading in an initial board, like the one above. This is stored in the README.TXT file that is in the project folder. You can change this and experiment with different starting patterns. Try as many arrangements as you can to test your code thoroughly. Task 1 The project also has the main method that plays that game. You are required to write three methods. This simplest one is to print the board. Note that you MUST print it out exactly as above. A board is represented as a 2-dimensional boolean array: boolean[][] board = new boolean[numberOfRows][numberOfColumns]; Your print method is called as follows: public static void printBoard(boolean[][] board) The method should print each row of the array on separate lines with a ‘.’ representing a false cell and a ‘*’ representing true. Task 2 The second method you must write is to count the live neighbours of a cell. public static 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: public static 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 From within your assignment 2 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 “Assignment2.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 and press “Search for Assignments”. Select “Assignment2″ from the next drop down menu and press “Upload my Assignment” Accept the student declaration Press “Choose File” and select the “Assignment2.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 Live.java Compiled Sucessfully 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. Include exact details of any error messages you get. 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