Skip to content

voloshynm/com.voloshyn.gameoflife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life

A Java implementation of Conway's famous cellular automaton - the Game of Life. This zero-player game demonstrates how complex patterns can emerge from simple rules, creating an engaging simulation of artificial life.

🎮 About the Game

Conway's Game of Life is a cellular automaton devised by mathematician John Horton Conway in 1970. It consists of a grid of cells that can be either alive or dead, with each cell's fate determined by its neighbors according to simple rules. Despite its simplicity, the Game of Life is Turing complete and can simulate complex behaviors.

Game Rules

The universe evolves according to four fundamental rules:

  1. Underpopulation: Any live cell with fewer than two live neighbors dies
  2. Survival: Any live cell with two or three live neighbors survives
  3. Overpopulation: Any live cell with more than three live neighbors dies
  4. Reproduction: Any dead cell with exactly three live neighbors becomes alive

✨ Features

  • Interactive GUI: User-friendly graphical interface for game visualization
  • Real-time Simulation: Watch patterns evolve step by step
  • Pattern Library: Pre-loaded famous patterns (gliders, oscillators, still lifes)
  • Custom Grid Setup: Create your own initial configurations
  • Speed Control: Adjust simulation speed to observe different behaviors
  • Grid Customization: Configurable grid size and cell appearance
  • Pattern Analysis: Track population statistics and generation count

🚀 Quick Start

Prerequisites

  • Java 8 or higher
  • Any Java IDE (IntelliJ IDEA, Eclipse, NetBeans) or command line

Installation & Running

  1. Clone the repository:
git clone https://github.com/voloshynm/com.voloshyn.gameoflife.git
cd com.voloshyn.gameoflife
  1. Compile the project:
javac -d bin src/com/voloshyn/gameoflife/*.java
  1. Run the application:
java -cp bin com.voloshyn.gameoflife.Main

Alternative: IDE Setup

  1. Open the project in your preferred Java IDE
  2. Ensure the source folder is set to src/
  3. Run the main class: com.voloshyn.gameoflife.Main

🎯 How to Use

Basic Controls

Action Description
Click Cell Toggle cell state (alive/dead)
Start/Pause Begin or pause the simulation
Step Advance one generation manually
Clear Reset all cells to dead state
Random Generate random initial pattern

Creating Patterns

  1. Manual Setup: Click individual cells to create your pattern
  2. Load Presets: Choose from classic patterns like:
    • Glider: Moving pattern that travels across the grid
    • Blinker: Simple oscillator that alternates between two states
    • Block: Static pattern that never changes
    • Gosper Glider Gun: Generates an infinite stream of gliders

Simulation Controls

  • Speed Slider: Control how fast generations advance
  • Generation Counter: Track the current generation number
  • Population Display: Monitor live cell count over time
  • Grid Size: Adjust the playing field dimensions

🏗️ Project Structure

com.voloshyn.gameoflife/
├── src/
│   └── com/voloshyn/gameoflife/
│       ├── Main.java              # Application entry point
│       ├── GameOfLife.java        # Core game logic and rules
│       ├── GameBoard.java         # Grid representation and cell management
│       ├── GameGUI.java           # User interface components
│       ├── Cell.java              # Individual cell state and behavior
│       ├── Pattern.java           # Predefined pattern definitions
│       └── Utils.java             # Utility functions and helpers
├── .idea/                         # IntelliJ IDEA configuration
├── com.voloshyn.gameoflife.iml   # IntelliJ module file
└── README.md

🔧 Technical Implementation

Core Components

Game Engine: Implements Conway's rules with efficient neighbor counting algorithms

Grid Management: Dynamic 2D array handling with boundary conditions

Pattern Recognition: Identifies and categorizes common Life patterns

Performance Optimization: Optimized algorithms for large grid simulations

Key Classes

GameOfLife: Central game engine managing state transitions GameBoard: Grid data structure with cell state management
GameGUI: Swing-based user interface with interactive controls Cell: Represents individual cell with state and neighbor information Pattern: Library of famous Game of Life configurations

🎨 Famous Patterns

Static Patterns (Still Lifes)

  • Block: 2×2 square of live cells
  • Beehive: Hexagonal arrangement of 6 cells
  • Loaf: Asymmetric 7-cell pattern

Oscillators

  • Blinker: 3-cell horizontal/vertical alternator
  • Toad: 6-cell period-2 oscillator
  • Beacon: 6-cell period-2 oscillator

Spaceships

  • Glider: 5-cell diagonal traveler
  • Lightweight Spaceship: Faster horizontal traveler

Infinite Growth

  • Gosper Glider Gun: Produces infinite stream of gliders
  • Acorn: Small pattern that grows for 5,206 generations

🧪 Interesting Experiments

Try these fascinating configurations:

  1. Population Dynamics: Start with random 50% density and observe stabilization
  2. Pattern Collisions: Launch gliders at each other to see interaction results
  3. Garden of Eden: Create patterns that cannot arise naturally
  4. Methuselahs: Small patterns that take many generations to stabilize

🤝 Contributing

Contributions are welcome! Here are some ways to help:

Enhancement Ideas

  • Add more predefined patterns
  • Implement pattern import/export functionality
  • Create pattern recognition algorithms
  • Add sound effects and animations
  • Implement toroidal (wraparound) grid option

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📚 Learning Resources

📄 License

This project is open source and available under the MIT License.

👤 Author

Maksym Voloshyn

🙏 Acknowledgments

  • John Horton Conway - Creator of the Game of Life
  • Martin Gardner - Popularized the game in Scientific American
  • The Life Community - Decades of pattern discovery and analysis
  • Java Swing Framework - GUI development platform

"The Game of Life is not just a game, but a fascinating glimpse into how complexity can emerge from simplicity."

Keywords: java cellular-automaton game-of-life conway simulation swing-gui mathematical-recreation artificial-life

About

Mindavalley Application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages