This is a simple implementation of the Tic Tac Toe game using the Minimax algorithm in Python. The game consists of two Python files: tictactoe.py
and runner.py
.
This file contains the core logic for playing Tic Tac Toe. It defines the game state, player actions, board setup, winning conditions, and the Minimax algorithm for AI decision making.
-
initial_state()
- Returns the starting state of the board.
-
player(board)
- Returns the player (X or O) who has the next turn on the board.
-
actions(board)
- Returns a set of all possible actions (i, j) available on the board.
-
result(board, action)
- Returns the board that results from making a move (i, j) on the board.
-
winner(board)
- Returns the winner of the game (X or O), if there is one.
-
terminal(board)
- Returns
True
if the game is over,False
otherwise.
- Returns
-
utility(board)
- Returns the utility value for the current state: 1 if X has won, -1 if O has won, or 0 for a tie or ongoing game.
-
minimax(board)
- Returns the optimal action for the current player on the board using the Minimax algorithm.
You can use the tictactoe.py
file to play the game or integrate it into other applications.
This file is a graphical user interface for playing Tic Tac Toe against the AI implemented in tictactoe.py
. It uses the Pygame library for rendering the game board and handling user interactions.
- Allows the user to choose to play as X or O.
- Provides a graphical interface for playing the game against the AI.
- Displays game over messages when the game ends.
- Offers an option to play again.
Run runner.py
to play the game with the graphical interface. Follow the on-screen instructions to make your moves and enjoy a game of Tic Tac Toe against the Minimax AI.
- Make sure you have Python and Pygame installed.
- Run
runner.py
to play the game interactively.
Enjoy the game and challenge the AI with your Tic Tac Toe skills!