NimAI is a web application that allows the user to challenge a reinforcement learning agent to a game of Nim. Before playing, the user can decide how much practice the AI is getting in order to learn a good policy.
A deployed version hosted on Heroku can be found here.
Please click here for a high-level explanation of how the reinforcement learning part works.
There should be a recent Python version (3.x) installed on your computer.
Moreover, we recommend using a common web browser like Chrome or Firefox.
First, navigate to the local directory you would like to place the project code in. Then, clone the NimAI repository.
cd <PATH_TO_DIRECTORY>
git clone https://github.com/JokusPokus/Nim_AI.git
Create a virtual environment. The first command is only required if the virtualenv package is not yet installed on your machine.
pip install virtualenv
virtualenv venv
Activate the virtual environment.
source venv/bin/activate
Alternatively, you can use your preferred Python IDE and select the venv there. This project was created using PyCharm.
Next, install all required packages.
pip install -r requirements.txt
To run the application locally, you need to execute some commands based on the OS you are using.
Windows:
set FLASK_APP=application.py
flask run
Linux / macOS:
export FLASK_APP=application
flask run
You may also wish to install the app in your virtual environment. Make sure to navigate to the Nim_AI root directory and execute:
pip install -e .
The main file controling the routing is application.py
.
Some views are rendered server-side using HTML templates and sent to the client. However, for the game playing part, a dynamic AJAX infrastructure is used to manipulate the UI client-side based on the AI moves.
These moves, in turn, are determined by calling Python functions (see nimAI.py
and nim_gameplay.py
) and passed to the client via JSON objects.
To keep track of session data, we use the flask_session
package, which stores information like the session-level high score in a dictionary-like object.
Consider this general overview:
- Python 3.7.4
- Flask 1.1.2
- Werkzeug 1.0.1
- Jakob Schmitt (Machine Learning, Backend, Frontend)
- Irina Bayova (Design, Styles, Frontend)
Parts of the reinforcement learning code were taken from the great online course CS50's Introduction to Artificial Intelligence, in particular from unit 4 on learning.