Concrete States – Alive and Dead classes.It contains an abstract method GetType which returns the type for each State. Abstract State – This is the abstract class for our State.It also has properties - Row, Column – defining its position in the Universe. Cell – The Context class of our State Pattern.Universe – Two dimension universe with cells as its content.Since the rule of the game depends on the number of neighbors around each cell in the universe, our logic will be based on indentifying neighbors for each cell and finding their states. It has a context class which deals with the decision of evaluating and handling the States. In our case, we will have two concrete Children States – Alive, Dead. It has an abstract State class with multiple children concrete State classes. The class diagram for State Design is shown above. In our problem, this would be ideal to use. The State Pattern is useful when we have to deal with States and handle change in states. The rules continue to be applied repeatedly to create further generations. The first generation is created by applying the above rules simultaneously to every cell in the seed-births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The initial pattern constitutes the seed of the system. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.Any live cell with more than three live neighbors dies, as if by overcrowding.Any live cell with two or three live neighbors’ lives on to the next generation. Any live cell with fewer than two live neighbors dies, as if caused by under-population.At each step in time, the following transitions occur: Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. The "game" is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. Also, my PC at that time did not have minesweeper for some reason, and I missed it very much.The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. For full detailed instructions, I believe there's a readme file in there.Īnd minesweeper is pretty standard, I was just bored one day and decided to recreate it in Java. To make it more realistic, I believe there's an 80% chance of the eradication/copulation of a new cell working, although if you double click on a single cell it will be 100%. Oh yea, and I forgot to mention you can left click and right click to add and delete cells. Try loading the gosper_glider_gun as an example. The game is quite interesting, me and my friends spend a long time watching black and white patterns on our computer screen grow, as well as trying different configurations to see what kind of life forms you can get. I use the standard rules that Conway originally proposed, however you can change these by modifying code in the advance method (inside the Colony.java file), and the size of the game can be specified in the constructor (I left a little comment on specifics of the parameters). Just run the Main.java file in the src folder for both programsĬonway's game of life is a simulation proposed by Conway, and has some interesting mathematical patterns, feel free to look inside the code and change things up a little to experiment. Hey guys, just thought I'd like to submit some programs I made back in my ICS class. Posted: Wed 6:07 pm Post subject: Conway's Game of Life and Minesweeper Wiki Blog Search Turing Chat Room Members
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |