Skip to content

Juskocode/min-max-algo-aplications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

min-max-algo-applications

Some game theory applications of the min/max algorithm

Tic-Tac-Toe 💢


Click to expand

Welcome to the Nightfall Tic-Tac-Toe project! This implementation of the classic Tic-Tac-Toe game features a unique nightfall theme and utilizes the Minimax algorithm with alpha-beta pruning to create a challenging AI opponent.

Features

  • Nightfall Theme: Enjoy a visually appealing nightfall theme that enhances the gaming experience.
  • AI Difficulty Selection: Use the scroll bar to choose the difficulty level of the AI bot. Adjust the maximum depth of the Minimax algorithm to make the game more or less challenging.
  • Game Statistics Layer: View essential game statistics, including explored nodes, to understand the AI's decision-making process.

Game Mechanics

This implementation utilizes the Minimax algorithm with alpha-beta pruning to optimize decision-making for the AI player. The AI evaluates potential moves based on the current game state and chooses the best possible outcome, providing an engaging challenge for players.

Screenshots & GIFs

Below are images and GIFs showcasing the gameplay:

Game Screenshot

Game Screenshot

Gameplay GIF

Gameplay GIF

Installation

To run this project locally, follow these steps:

  1. Clone the repository:
    git clone https://github.com/yourusername/nightfall-tictactoe.git
    
  2. Run html

🥇: Some details of Mini-Max algo for this use case


Click to expand

How the Minimax Algorithm Works

The Minimax algorithm is a recursive decision-making algorithm used in game theory and artificial intelligence for two-player games, like Tic-Tac-Toe. It provides a systematic way to evaluate the possible moves in a game and predict the outcomes based on optimal play by both players. Here’s how it works:

Basic Concept

  1. Game Tree: The algorithm constructs a game tree that represents all possible moves from the current game state. Each node in the tree corresponds to a game state, with branches representing possible moves.

  2. Maximizing and Minimizing Players: The player who is about to make a move (let's call them Max) tries to maximize their chances of winning, while the opponent (Min) attempts to minimize Max’s chances. The algorithm evaluates these moves by assigning a score to each terminal node (win, lose, or draw).

  3. Score Assignment:

    • Win for Max: +1
    • Win for Min: -1
    • Draw: 0

Minimax Process

  1. Recursive Evaluation: Starting from the current game state, the algorithm recursively explores all possible moves. For each possible move, it generates a new game state and calls itself again to evaluate that state.

  2. Backtracking: Once it reaches terminal nodes (where the game ends), it backtracks and assigns scores to each node based on the scores of its children:

    • If it's Max's turn, it selects the child node with the maximum score.
    • If it's Min's turn, it selects the child node with the minimum score.

Alpha-Beta Pruning

Alpha-beta pruning is an optimization technique used to reduce the number of nodes that the Minimax algorithm needs to evaluate, improving its efficiency:

  • Alpha: The best score that the maximizer (Max) currently can guarantee at that level or above.
  • Beta: The best score that the minimizer (Min) currently can guarantee at that level or above.

Pruning Process

  1. As the algorithm explores the game tree, it keeps track of the alpha and beta values.
  2. If it finds a node that cannot possibly influence the final decision (i.e., a situation where Max can guarantee a better score than what Min can guarantee), it "prunes" that branch of the tree and does not evaluate it further. This helps in skipping unnecessary computations.

Conclusion

By utilizing the Minimax algorithm with alpha-beta pruning, the Nightfall Tic-Tac-Toe game achieves a highly efficient and competitive AI opponent, making it an engaging experience for players. The AI evaluates moves strategically, ensuring that players face a significant challenge while enjoying the game.



About

Some game theory applications of the min/max algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published