

All possible values of type long for the world argument of getCell are valid descriptions of a world in TinyLife, therefore no input sanitisation is required for this variable. For example, the method getCell accepts three arguments. This is sometimes called input sanitisation. When writing the body of a method, it is a good idea to check the values provided to the method to make sure they are reasonable. The prototypes of the two methods you will write are in this section are: You saw two example methods last week when you wrote your implementation of PackedLong the methods were called set and get.Ī method has a prototype which describes the types of the arguments which will be provided when the method is invoked, and the type of the result returned when the execution of the method finishes. A method provides a well-defined interface, specifying the values required to perform the computation described by the method, and the type of the result returned (if any). A method is a unit of computation associated with a class in Java. In this section you will write two methods which will be used later in your implementation of TinyLife. Tick submission will rely on the previous week's submission. Make your tick submission difficult because your Leave the PackedLong class in the tick1 package and call it from the tick2 package. Remember to change the package of the PackedLong class to reflect its new location. If you have not yet completed your implementation of PackedLong you will need to complete this first before continuing with this workbook. You will need a copy of PackedLong.java in the same directory as TinyLife.java so that your modifications to TinyLife can make use of the features provided by PackedLong.

Check that your skeleton class works by inserting a Java statement to print out your name and compile and run your program.Ĭopy the file PackedLong.java, which you submitted as part of your work for last week, into the same directory as TinyLife.java. Open a text editor and create a new class called TinyLife inside the package uk.ac.2.Īdd a special "main" method to the class TinyLife. The program that you will create will form your submission for Tick 2. Figure 2, “Bit positions in PackedLong used to store the state of cells in TinyLife” contains a graphical illustration of this specification.Īs you proceed through this workbook, you will fill in key parts of a program which will draw the state of TinyLife as textual characters to your terminal. In this workbook you should use the bits stored by the PackedLong class so that the state of top left cell of the board is stored in the least significant bit, the bottom right cell of the board is stored in the most significant bit, with the cells in between stored, in increasing bit positions, in row order. In order to maintain compatibility with the examples and test cases in this workbook you must use the mapping described here, although in principle there are 64 factorial possible valid mappings to choose from (most of which would be more tedious to implement than the one used here). To use PackedLong to store the state of the world, a mapping from cell location on the game board to the bit location in the variable is required. Similarly, the state of bit i of the variable v of type long can be retrieved and stored in variable b of type boolean using the method call:
#CONWAYS GAME OF LIFE COMMAND LINE OUTPUT UPDATE#
Note in particular the use of the assignment operator to update the value stored in the variable v. You may recall that, given a variable v of type long, the set method of PackedLong class is able to set bit i of v to the value val with the method call: Given this size restriction, this particular implementation of Conway's Game of Life is called TinyLife in this workbook. The limit of 64 boolean values restricts the size of the game board to an eight-by-eight world. We will use these boolean values to represent the liveness of a cell in other words, if the cell is alive then true is stored, and if the cell is dead then false is recorded. The PackedLong class is capable of storing at most 64 boolean values in a variable of type long. In this workbook you will build an implementation of Conway's Game of Life using the PackedLong class you wrote last week.
