Skip to content

My AI course final project. Develop an AI agent that utilizes both mini-max and reinforcement learning algorithms to play Connect-4. The game is playable in a web-based GUI environment.

License

Notifications You must be signed in to change notification settings

ILoveBacteria/connect-4

Repository files navigation

Connect-4

License: MIT Issues Forks Stars Watchers Last commit python version npm version Workflow Workflow wiki GitHub tag GitHub release GitHub repo size Docker

connect-4-gif

Table of Contents

Description

This is my AI course final project. I implemented a connect-4 game with a GUI and a simple AI. The AI uses the minimax algorithm with alpha-beta pruning to find the best move and reinforcement learning.

Read the wiki for more information about the project and How implemented the heuristic function and the Q-Learning.

How To Run The Project

Docker

How to run the Docker image

$ docker run -p 5000:5000  ilovebacteria/connect-4:latest

Enviroment Variables

  • HOST_ADDR: The host address. (default 127.0.0.1)
  • DEBUG: The flask debug mode. (default False)

Manual

  1. You have to install Python and pipenv and npm.

  2. Clone the repository.

  3. Open the terminal in the project folder and run these commands to install dependencies.

    pipenv install
    npm install
  4. Run this npm command to build the project.

    npm run build
  5. Run this pipenv command to run the Flask server.

    pipenv run server
  6. Open the browser and go to http://localhost:5000/.

Train the AI

In the Q-Learning, 2 agents play against each other. At the end of each game, the winning agent will be rewarded with 1000 and the loser agent will be punished with -1000. Both agents will be rewarded 0 if the game ends with a draw.

connect_4 package provides a CLI. You can use it to train the AI. It will create q_table.csv file if it doesn't exist. If it exists, it will load the Q-Table from it and continue training.

The Q-Table has 4 columns. The first 3 columns are the state of the board and action, and the last column is the Q-Value.

pipenv run python -m connect_4 train --count-games 10

What technologies and libraries I used

About

My AI course final project. Develop an AI agent that utilizes both mini-max and reinforcement learning algorithms to play Connect-4. The game is playable in a web-based GUI environment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages