JokusPokus / Nim_AI

Web application for an intelligent Nim player based on reinforcement learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NimAI

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.

Getting started

Prerequisites

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.

Setting up an environment

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 .

Architecture Overview

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:

Built with

  • Python 3.7.4
  • Flask 1.1.2
  • Werkzeug 1.0.1

Authors

  • Jakob Schmitt (Machine Learning, Backend, Frontend)
  • Irina Bayova (Design, Styles, Frontend)

Acknowledgements

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.

About

Web application for an intelligent Nim player based on reinforcement learning


Languages

Language:JavaScript 55.3%Language:Python 16.6%Language:HTML 15.7%Language:CSS 12.4%