Skip to content

Connect4AI is a two-player game where you can play against a computer that uses the minimax algorithm to choose its moves. The game is developed in Python3 using Pygame, and features a GUI for an enhanced user experience. The game can help with improving strategic thinking, and is a great example of how to implement a game AI using the minimax algo

License

m3hrab/Connect4AI

Repository files navigation

Connect4AI - Play Connect4 with a Minimax AI

This is a Connect4 game implementation where you can play against a computer that uses the minimax algorithm to choose its moves.

How to Play

  1. Clone the repository to your local machine.
  2. Open a terminal window and navigate to the cloned repository.
  3. Run python3 main.py to start the game.
  4. Follow the prompts in the terminal to choose whether you want to play as Player 1 or Player 2, and to choose the depth of the minimax algorithm (i.e., the number of moves ahead the computer should consider).
  5. Play the game by typing the column number (1-7) where you want to drop your piece.
  6. The game ends when one player connects four pieces in a row, or the board is filled with no winner.

How the Minimax AI Works

The minimax algorithm is a recursive algorithm that searches through the game tree to find the best move for the current player. Each node in the tree represents a possible game state, and the algorithm assigns a score to each node based on the value of the terminal node that it leads to (i.e., a win, loss, or draw).

The algorithm works as follows:

  1. If the current node is a terminal node (i.e., the game has ended), return the score.
  2. If the current node is a maximizing node (i.e., it is the computer's turn), return the maximum score of its child nodes.
  3. If the current node is a minimizing node (i.e., it is the player's turn), return the minimum score of its child nodes.

By recursively applying this algorithm to each possible move, the computer can determine the best move to make based on the current state of the game.

Contributors

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Connect4AI is a two-player game where you can play against a computer that uses the minimax algorithm to choose its moves. The game is developed in Python3 using Pygame, and features a GUI for an enhanced user experience. The game can help with improving strategic thinking, and is a great example of how to implement a game AI using the minimax algo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages