Skip to content

Neural network to play tic tac toe and connect4

Notifications You must be signed in to change notification settings

Alf0nso/NN-Games

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Networks To Solve Simple Games

The purpose of the project is to better understand, how neural networks work from top to bottom. To do that we built a mini library in python to create and train a Multilayer Perceptron on a simple problem. The problem we choose was to approximate a reasonable player of a strategy board game.

Showcase

To see the final results to this moment, you can simply run the file “main.py” where you will be presented with a prompt. This will allow you to choose to play against the two neural networks that where train, or to simulate games between both neural networks and random generated moves.

py main.py

Play around

You can also play around with the code we write by simply using a python prompt or writing on a new python file. Everything we wrote here are simply functions that can be imported and used whenever.

Playing each game is easy, and each one comes with options related to the types of players…

import connect4 as c4
import tic_tac_toe as tic

# To play Tic Tac Toe against the MLP...
tic.play("nn", "p")

# To play Connect Four against the MLP...
c4.play("nn", "p")

There is also the possibility of simulating many games against random opponents to test how well our MLP is doing in the long run.

import connect4 as c4
import tic_tac_toe as tic

# Simulating games for Tic Tac Toe
print("Tic Tac Toe")
tic.simulate_games(1000, "nn", "r")

print()

# Simulating games for Connect Four
print("Connect Four")
c4.simulate_games(1000, "nn", "r")
Tic Tac Toe
Player 1 Wins: 73.5 %
Player 2 Wins: 14.099999999999998 %
Draw: 12.4 %

Connect Four
Player 1 Wins: 69.6 %
Player 2 Wins: 30.2 %
Draw: 0.2 %

There are many more functions to generate, train and use the MLP’s, all of those can be found on the neural_net.py file.

Things to do next

  • [X] Organize all the files in separate folders.
  • [ ] Getting good data of Tic Tac Toe games for testing.
  • [ ] Adapt playing function for the NN to train on the game it just played
  • [ ] Consider looking into reinforcement learning.
  • [ ] Correct default files in Games package
  • [ ] Correct README.org

About

Neural network to play tic tac toe and connect4

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages