Ken-Soft

Software and the World


John Conway’s Game of Life + Mutation (C/C++)

Posted under C/C++, General Development, Mathematics, Programming, Simulation, Software Development by Kenny on Tuesday 22 December 2009 at 7:37 am

Bookmark and Share

I’ve always been interested in AI, evolution simulations, and other interesting problems. But I will never forget one of my all time favorite classics, John Conway’s Game of Life..
This simulation implements a few just a few simple rules, yet relatively complex structures emerge.
The rules are:
1. Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2. Any live cell with more than three live neighbors dies, as if by overcrowding.
3. Any live cell with two or three live neighbors lives on to the next generation.
4. Any dead cell with exactly three live neighbors becomes a live cell.

Below are some of the patterns that I found and thought were interesting:

Game of Life Simple Patterns Game of Life Complex Patterns

After watching many trails I noticed one thing immediately; The simulation always eventually “dies down”, or reaches some equilibrium state and it is usually comprised of a bunch of simple structures. So I decided to add a mutation factor to the simulation such that upon mutation, A living cell dies and a dead cell comes to life. This significantly increased the life of the simulation. In fact with the right mutation rate the simulation will continue endlessly.

In my quick little simulation I also introduced a “wrap around” feature so that structures can move infinitely in any direction.

The demo is written in C and uses the SDL Library for drawing the points and is in 640×480 resolution. The source can be downloaded here.
To Compile:
g++ main.cpp -o LIFE -lSDL
To Run:
./LIFE

Every thing from mutation rate to cell generation at startup is configurable. Read the ReadMe.txt file included to see what’s configurable.

Screenshots:

Life Screenshot Life Screenshot Life Screenshot Changed Rule

Notice that the 3rd Image is a result of changing rule 4 to ” Any dead cell with two or three live neighbors becomes a live cell.” (I made this typo when first writing the program and was surprised by the result :)) Try changing the rules and see what results you find.
I hope to release a more complex version in the future.

Share on Facebook

Neural Network (Back-Error Propagation) C++

Posted under Artificial Intelligence, C/C++, General Development, Neural Networks, Programming, Software Development by Kenny on Sunday 20 December 2009 at 4:42 am

Bookmark and Share

Here is yet another simple Neural Network that implements Back-Error Propagation as a form of Reinforced Learning.
The entire project is written in C++ and requires no special libraries to compile and run.
main.cpp contains code to train both a 2 and 3-input Logical AND gate.
The zipped source code can be downloaded here
A Linux executable is already compiled and included in the zip, but feel free to recompile it. A Code::Blocks Project file is also included.

To Compile
g++ *.cpp -o NeuralNetwork
It will output an executable name “NeuralNetwork”
To Run
open a terminal and type:
./NeuralNetwork
Sample Output
Neural Network Connections Inited
Trained in 10000 trails within an error of 1.03127e-05
0 & 0 = 4.63117e-05
0 & 1 = 0.00349833
1 & 0 = 0.00290835
1 & 1 = 0.995469
Train Logical AND 2 Inputs Demo End
Neural Network Connections Inited
Training...
Trained in 5584 trails within an error of 9.99977e-06
0 & 0 & 0 = 3.62242e-05
0 & 0 & 1 = 0.00194301
0 & 1 & 0 = 0.000102096
0 & 1 & 1 = 0.00344352
1 & 0 & 0 = 0.000142368
1 & 0 & 1 = 0.00333881
1 & 1 & 0 = 0.0035418
1 & 1 & 1 = 0.993633
Logical AND 3 Inputs Demo End

Resources:
About Neural Networks (English)
About Neural Networks (Japanese/日本語)
Java Implementation of a Neural Network

Share on Facebook

Graph 3D (Vector Rotation Source Included) C++

Posted under C/C++, General Development, Mathematics, Programming, Software Development by Kenny on Saturday 19 December 2009 at 4:17 am

Bookmark and Share

This program implements my simple Vector3D.h source to draw simple graphs using SDL. While it’s not terribly advanced, it should be pretty fun to tinker with. To learn more about 3D rotations including the mathematics and more source (Java) examples, view my previous post –> 3D Rotation Matrix - Graph3D.
The source code and linux executables can be downloaded here.
If you don’t want the Graph utility the single Vector3D.h file can be downloaded here.

Below is a few of the graphs that I created. All of which can be found in main.cpp (there is a section in the code where you can uncomment the function that you want to graph!)

3D  graph 3D  graph 3D  graph 3D  graph
3D  graph 3D  graph 3D  graph 3D  graph
3D  graph 3D  graph 3D  graph 3D  graph
3D  graph 3D  graph 3D  graph 3D  graph
3D  graph 3D  graph 3D  graph 3D  graph
Share on Facebook

Copyright © 2009 www.Ken-Soft.com