Skip to content

Latest commit

 

History

History
142 lines (85 loc) · 10.5 KB

README.md

File metadata and controls

142 lines (85 loc) · 10.5 KB

[ Table of Contents ]

[ About the Project ]

INTRO

This project features a user-friendly UI that allows players to engage with classic AI algorithms or pit them against each other in the famed Kaggle Connect-X competition setting. It includes:

  1. Interactive UI: Play the Connect X game directly or watch AI algorithms compete.
  2. Multiple AI Algorithms: Dive into a variety of classic AI algorithms used in competitive gaming, including one that was entered into Kaggle's Connect-X competition and achieved a notable 16th place ranking.
Screenshot 2024-06-10 at 12 31 44
  1. Custom Agent Development: Follow an easy-to-understand guide to develop your own AI agent, visually test it, and compete against existing algorithms.
  2. Deployment Instructions: Comprehensive deployment guidelines are provided for those looking to host this as a web application.
Screenshot 2024-06-06 at 18 12 42

BUILT WITH

Node Docker vscode

KAGGLE SUBMISSION

Check the Kaggle Submission

[ To Everyone ]

TRY IT OUT

[ To Developers ]

This web application provides a comprehensive platform for testing and interacting with various AI agents developed for the ConnectX game. Built with a React frontend and a Python Flask backend, this platform offers a visually engaging interface that allows users to easily interact with and evaluate the performance of different game AI agents.

LOCAL SETUP

DOCKER SETUP

Setup the whole application in a docker container

  • run docker-compose up --build

OR SETUP SEPARATELY

Run the frontend and backend applications separately

  • Setup the Frontend React Application

    • To Frontend Testing Application Directory cd FRONT
    • To install required modules npm install
    • Run Frontend Testing Application npm start
    • Heading to the Application http://localhost:3000/
  • Setup the Backend Flask Application

    • To Backend File Server Directory cd BACK
    • (Optional) Create a python venv for this flask application python -m venv [VENV_NAME] (Windows)
    • (Optional) Run the python venv [VENV_NAME]\Scripts\activate (Windows)
    • To install required dependencies pip install -r requirements.txt
    • Run Backend File Server python BACK.py
    • Server will running on http://localhost:5000/ in development mode

CURRENT IMPLEMENTED AGENTS

RANDOM

This agent's strategy is straightforward: it selects its moves purely at random from the set of available columns. This means it doesn't follow any tactical approach or attempt to block the opponent's moves. While this agent may not provide challenging gameplay for human players or sophisticated AI opponents, it serves as a useful baseline for testing the game mechanics and for comparing the performance of more advanced agents developed later in the project.

GREEDY

The Greedy Agent in the ConnectX game employs a more strategic approach than the Random Agent. It selects its moves based on a scoring system it evaluates for each possible move, always choosing the one with the highest score. The default scoring mechanism involves calculating the move that enables the longest possible connection of tokens. This includes considering both the current move's potential to extend a line of consecutive tokens and the surrounding growable space up to the required "inarow" length. If a move directly leads to a win, it is assigned an infinite score, symbolizing an immediate game-winning opportunity. Conversely, if a move would allow the opponent to win on their next turn, it receives a negative infinite score to avoid such scenarios. This method helps the Greedy Agent to make decisions that maximize its chances of winning while blocking potential threats from the opponent.

MIN_MAX

The Minimax Agent in the ConnectX game utilizes the classic minimax algorithm, a decision-making tool used in game theory and artificial intelligence to minimize the possible loss for a worst-case scenario. This agent adopts the same scoring system as described for the Greedy Agent, evaluating each potential move based on the ability to create the longest connections and considering the implications of each move in terms of immediate wins or losses.

The essence of the minimax approach is to look several moves ahead, calculating the best move by assuming that the opponent also plays optimally. At each decision point, the algorithm simulates both the player's and the opponent's moves, assessing the maximum benefit the player can achieve while minimizing the opponent's best possible response. This recursive evaluation continues until a terminal state (win, loss, or draw) is reached or until a specified depth limit is achieved, making it a powerful method for strategic planning in ConnectX.

SAVK_MINMAX

MONTE CARLO (USED IN KAGGLE CONNECT-X COMPETITION)

The Monte Carlo Agent in the ConnectX game leverages the Monte Carlo Tree Search (MCTS) algorithm, a probabilistic model widely used in AI for making optimal decisions in problem spaces with a high degree of complexity. This agent performs 384 simulations for each possible move to statistically determine the most promising move based on the outcomes of these simulations.

In each simulation, the agent plays out random moves from the current state to the end of the game. The results of these simulations are then aggregated to estimate the likelihood of winning for each potential move. Moves that frequently lead to winning outcomes in the simulations are prioritized, while less successful moves are considered less favorable. This method allows the Monte Carlo Agent to make informed decisions even in the face of uncertain or highly variable game scenarios, effectively balancing exploration of new moves with the exploitation of known successful strategies.

To enhance the Monte Carlo Agent's decision-making process in the ConnectX game, we can refine its scoring system to account more explicitly for immediate game outcomes:

1. Immediate Win Detection: If a simulation reveals that a move directly leads to a win on the agent's next turn, that move is assigned a score of 1. This indicates a guaranteed victory, and such moves are given the highest priority.

2. Immediate Loss Prevention: Conversely, if a move would allow the opponent to win on their next turn, the move is scored as 0. This discourages the agent from making moves that would lead directly to a loss, ensuring defensive strategies are considered.

3. Probabilistic Scoring: For all other scenarios where the move does not immediately result in a win or prevent a loss, the score is calculated based on the probability of winning derived from the simulations. These scores range between 0 and 1, with higher scores reflecting a greater likelihood of winning as observed in the simulated play-outs. This probabilistic approach allows the agent to assess the potential long-term benefits of each move, not just the immediate outcomes.

By adopting this scoring system, the Monte Carlo Agent can make more nuanced decisions that effectively balance between securing immediate advantages and strategically positioning for future game states. This method helps in optimizing both offensive and defensive plays, making the agent robust against a variety of opponent strategies.

IMPLEMENT AND TEST YOUR OWN AGENT

DEPLOYMENT PROCESS

1. Build Local Project into Docker images and push to Docker hub, Notice that [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO] and [VERSION NUMBER] needs to be replaced.

  • docker buildx create --use

  • To Frontend React Application Dir cd FRONT

  • Build the Frontend React App in linux/amd64 ENV and push to docker hub docker buildx build --platform linux/amd64 -t [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO]:v[VERSION_NUMBER] --push .

  • To Backend Python Flask Application Dir cd BACK

  • Build the Backend Python Flask Application in linux/amd64 ENV and push to docker hub docker buildx build --platform linux/amd64 -t [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO]:v[VERSION_NUMBER] --push .

2. After Server started, you should login into your docker account, pull your docker hub repo and build start the docker images.

  • To login your docker account docker login

  • To pull Both frontend and backend Applications docker pull [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO]:v[VERSION_NUMBER]

  • To run the Frontend React Application docker run -d -p 3000:3000 --name connect-x-frontend [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO]:v[VERSION_NUMBER]

  • To run the Backend Python Flask Application docker run -d -p 5000:5000 --name connect-x-backend [YOUR_DOCKER_USERNAME/DOCKER_HUB_REPO]:v[VERSION_NUMBER]

  • Check Both Docker Containers are running docker ps