Inspiration
I wanted to create a simple game that both challenged myself and was a fun solo project. I found Conway's Game of Life as a way to practice my ability to create AI.
What it does
Conway's Game of Life is unique because it is a zero-player game. Once given an input of "cells", the game will simulate generations of the cells, sometimes creating infinite loops or making the cells go extinct by having each cell interact with its Moore Neighborhood. The rules are as follows: 1. If a cell has less than 2 neighbors, it dies of isolation. 2. If a cell has more than 3 neighbors, it dies of overcrowding. 3. If a cell has exactly 2 or 3 neighbors, it survives. 4. If an unoccupied space has exactly 3 neighbors, it becomes populated with a cell.
How I built it
Each individual cell is contained within a 2D Array, which is displayed on a JFrame. Each cell has MouseListener event that allows the user to toggle the cell state to either "Alive" or "Dead" if the game has not started.
Every single in-game tick, the game will check every cell and mark it if it needs to be updated. It then will update all marked cells to the correct state.
The game "ends" when either all of your cells die or the cells are put in an infinite loop. From there, you can reset the game or clear the board and start from scratch.
Challenges I ran into
I had trouble creating a grid to make it easier for user to see cell locations. I ended up making a separate extension class of JComponent that simply drew the grid and added that to the JFrame.
Another problem I had was with creating the AI of the cells. If I simply updated the cells as I looped through, a cell might be updated more than once, causing it to be dead when it should be alive and vice versa. I solved this by updating cells only after checking through all of them.
Accomplishments that I'm proud of
I managed to create this game starting from absolutely nothing. No platform or anything, just plain old Eclipse. The only prerequisite is that I knew the rules of the game. I'm also impressed that I managed to spend six hours straight creating it.
I'm also proud of the fact that I did not need an external source, such as StackOverflow, to solve my problems. I used the Java API, but other than that, I used trial and error and debugging to solve my problems.
What I learned
I learned more about creating visuals in Java as well as learned how to create better AI.
What's next for Conway's Game of Life
I am thinking of making an option for cells to have a chance to "mutate" into different versions, such as cells that cannot die and continue to spread (like cancer) or cells that consume other cells (like a macrophage). These cells would have different colors than normal cells.
Log in or sign up for Devpost to join the conversation.