Game of Life — Command Line App

Yesterday I finished up my first iteration of my Game of Life app, and made it so that it can run in the command line.

Here’s the link with running instructions:

When TDDing the command line app, I used my same FakeGrid object that I’d created when I was working on the generations, and this was very helpful, as I was able to estimate where things would be.

I decided to set a loop to update generations, and end it when the cells had died out. Maybe this is pessimistic way of looking at things, but I thought that happening would be a forgone conclusion. Turns out, it’s actually quite easy for cells to live in, as there just needs to be an independent clump of three, and they will all satisfy the requirement to move on to the next generation.

Ultimately, I needed to find a different way of turning it off, and I decided to prompt the user every five generations to ask if they wanted to see the next five generations. This required getting user input, so added a bit of code I wasn’t planning on including.

One of the other things that I’d noticed when I first run the app was how fast the computer is, within seconds I was on my 20,000th generation, and this doesn’t really give the user a chance to see what is happening.

To slow this down, I used Thread.sleep() for 1000ms (1 second).

private void slowDown() {
try {
} catch (InterruptedException e) {

Thread.sleep() throws an error, so needs to catch the error. I decided to create a method that calls Thread.sleep() and catches the error all at once, so I didn’t need to change too many of my functions.

I’d be very interested in finding a different way to delay the computer, as I don’t think something that throws an error is ideal.

The rest of the day was spent finishing up week 1 and doing week 2 of my Data Structures course, which I’m finding much more challenging than I expected.

I’m going to keep pushing through with it, and hopefully get some other resources so it makes more sense. I think it’s really important to learn, and I have every confidence that I will get it, it just might take a bit more time and effort than I’d expected.