mines: Minesweeper simulation using neural networks

[ ai, game, program ] [ Propose Tags ] [ Report a vulnerability ]

A simulation of AI controlled minesweepers using neural networks and genetic algorithms. The minesweepers learn to sweep mines themselves and their movements are recorded in an SVG file.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1
Dependencies base, directory (>=1.0.0.0), mtl (>=1.1.0.0), random (>=1.0.0.0) [details]
License LicenseRef-OtherLicense
Copyright Antti Salonen 2008
Author Antti Salonen
Maintainer ajsalonen@gmail.com
Category Game, AI
Home page http://finder.homelinux.org/haskell/Mines
Uploaded by AnttiSalonen at 2008-08-13T14:28:47Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables mines
Downloads 1409 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2017-01-03 [all 8 reports]

Readme for mines-0.1

[back to package description]
Mines 0.1
---------

Building with Cabal:

$ runhaskell Setup.hs configure --user --prefix=$HOME
$ runhaskell Setup.hs build
$ runhaskell Setup.hs install

Use:

This part isn't too difficult. Run the program (called mines) from wherever
you installed it and wait until you get some results. The output may give
some hints on how well the sweepers are doing. Every 10 generations an SVG
file is generated in ~/.mines (or Documents and Settings/user/Application 
Data/mines on Windows) that shows you how a minesweeper moved in the
previous generation.

It may take a few hundred generations before they actually get smart. When
they're smart enough for you, ctrl+c will exit.

Configuration:

To configure the program, you need to tweak the values in the beginning
of Mines.hs and recompile. Changing settings like the size of the map or
number of minesweepers makes the simulation run faster or slower and also
affects the speed the minesweepers learn. The current values work pretty well,
but feel free to experiment.

Neural networks:

The minesweepers have a 4-3-3-2 neural network, where the inputs are the 
direction of the minesweeper (x and y) and the vector to the nearest mine
(x and y). The outputs are the angle where to turn (relative to current
minesweeper direction) and the velocity for moving (which is not used
in the code in this release).

To use the neural networks in NN.hs, you only need the functions newNeuralNet
and updateNeuralNet. newNeuralNet takes a list of layers (such as [4,3,3,2])
as well as minimum and maximum values for weights (floats) as parameters,
updateNeuralNet takes a weighting function (such as sigmoid or (*1)), list
of weights as input and a neural net as a parameter and returns the list
of outputs.

Genetic algorithms:

To train the neural networks you need genetic algorithms that can be found
at GA.hs. You can use getWeights in NN.hs to get a list of weights that
are the genes for the genetic algorithms, functions crossOver, mutate, 
mixGenes and pickRoulette for choosing the parents and creating the children
and putWeights to apply the new weights to the new networks.

Todo:

The types for weights in neural networks as well as for genes in genetic
algorithms are hard coded at the moment (Float). Making that application
dependent would be good.

More info:

For questions, you can reach me at ajsalonen@gmail.com. I've written about
the program in my blog, you can find the text at 
http://codeflow.wordpress.com/2008/08/03/about-ai-and-neural-networks/
Feel free to improve the code.

The minesweepers were inspired by an article by Mat Buckland on neural
networks, available at http://www.ai-junkie.com/ann/evolved/nnt1.html

Licensed with MIT, see LICENSE for details. Copyright 2008 Antti Salonen.