Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The task of this project was to make a simulation of conway's game of life using arrays. An array stores data, be it objects or primitives, in a grid with addresses for each entry. This allows you to loop through data and keep track of particular entries. Arrays are perfect for conway's game of life because all the game needs is a grid for the computer to look at, interpret, and construct a new grid out of.

The most interesting part of this project for me was making the getNeighbors method in my Landscape class. Here I had to loop through each cell of a source grid, and generate a list of the cells adjacent to each. I had to first find the looping parameters for each cell to pick the correct box of neighbors, and then make an if statement to catch the list making part before it tried to add a cell that didn't exist, i.e. one that is out of bounds of the grid. Here I had to remind myself of the rules of logic and how those operators are represented in java.

Another interesting part was creating a grid of live cells based on a target density. With a target density between 0 and 1, I picked a random number in that range for each cell, and if that random number was greater than the planned density, the cell was dead. If the random was less than the density, the cell was alive.

Ultimately my game of life gave results like this :

I also added command line support so the user could specify the number of iterations and the initial density of live cells.

  • No labels