Question

 

Write a Python Program to implement the Min-Max Algorithm.

17 Feb 2026
Answer :
Word Count : 904
The Min-Max Algorithm is a decision-making algorithm used in game theory, particularly in two-player, zero-sum games. It is typically used in adversarial search, where two players take turns making moves, and each player's goal is to either maximize their chances of winning (for one player) or minimize the chances of the opponent winning (for the other player). The algorithm evaluates all possible moves by simulating each of the moves to their fullest extent, assuming both players play optimally. In this Python program, we will implement the Min-Max Algorithm for a simple game of Tic-Tac-Toe, where the computer will make its moves using the Min-Max algorithm to maximize its chances of winning, while the user will make their moves manually. The game assumes a player plays 'X' and the computer plays 'O'. The board is represented by a 3x3 matrix, and the computer will select the best possible move using the Min-Max strategy. Here is a Python implementation of the Min-Max Algorithm for Tic-Tac-Toe: ```python import math # Constants to represent the players PLAYER_X = 'X' PLAYER_O = 'O' EMPTY = ' ' # Function to check if the current player has won def check_winner(board, player): # Check rows, columns, and diagonals for i in range(3): if all([cell == player for cell in board[i]]): # Check row return True if all([board[j][i] == player for j in range(3)]): ________ ______ _____ ________ _____ _________ ____ ___ ___ ________ ________ _______.
_______ ______ _______ ____ _______ __________ __________ ____ ____ _____ _______ _______.
_____ _____ _____ _______ _____ __________ _____.
_____ _____ ___ _______ _______ ___ ___.
_________ __________ ______ ______ ____ ___ ___.
__________ ________ __________ _______ ___ _________ ___ ___.
______ _____ _________ _________ __________ _______ ___ _______ ________ ___ _________ _________.
___ _________ ____ ____ _____ _____.
___ _________ ____ _______ _______ _______.
___ _______ __________ ____ _______ __________ _________ _______ _________.
_______ ______ __________ _____ _____ ________ __________ ___ ___.
_____ ____ ______ ___ _____ _____ _____ ________ _________ ______.
_________ ________ __________ _______ _____ _________ _________ _____ __________ _____ __________.
_______ ____ ______ _____ _____ _________ ______ _________.
_____ ______ ___ _________ _____ ___ ___ ________.
___ _________ __________ _____ __________ ___.
____ ____ __________ ______ _____ _____ ______.
_________ ___ ____ _____ ________ ____.
_________ ____ _______ ___ __________.
_____ _______ _________ ___ _____ ___ ___ _______ ___ ________ _____ ______.
_____ _____ ____ _____ _____ __________ _______ ________ ____ _____ ______.
_____ _________ _____ __________ ______ ________ ________ _____ ________ __________ ______.
_____ ___ _________ ___ _________ _____ ______ ___ ________.
______ _________ ______ ___ ___ _________ _____ ________ _______ _____ _______.
___ ______ ______ __________ _________ ___.
______ _________ ______ _____ ____ ___.
________ _____ ____ ____ ___ _____ ___ ___ ____ _____ ______.
_______ ____ _______ ___ _______.
_____ _____ ____ ___ _____ __________ ___ ___ _______ __________.
____ ________ ____ _______ ________ ______ ________ __________.
__________ ______ _____ __________ ___ ___ ______ ____.
____ ______ ________ _____ _________ _____ __________ ________ _____ ________ __________.
_____ __________ _____ _________ _________ _________ ___ _______ ______ _____.
___ ________ _____ _____ ____ _____ ________ __________ ____ ___.
________ ___ ______ _________ __________ _______ ____ ___ ________ _______ _______.
__________ _________ _____ ____ ______ __________ __________ _______ _____.
___ _______ __________ _____ _____ ______ ________ ___ _______ _____ ______.
____ _________ ______ _________ ________ ___ _____.
______ _______ ____ ______ _____ __________ ______ ________.
______ _______ _____ _____ _________ ___ ________ __________ __________ ________ ______ ______.
__________ ______ ____ ________ ____ ____ ____ ____.
__________ _____ _______ ___ __________ ________ ____ ___ ______ __________ _________ ___.
____ ________ _________ ________ __________ ________ __________.
_______ _____ __________ __________ _____ _____ _______ ____ ________ __________ _________ ______.
______ ___ _________ ______ _______ _______ ____ _________ ___ ___ _____ _____.
______ ________ ___ ____ _______ ________ _________.
________ _______ _________ __________ _____ ______ ___.
_______ _______ _____ _____ ___ _______ _________ _____ ______ _________ ____ __________.
__________ __________ ____ ____ __________ ________ __________ ____ _____ ________.
________ ______ ____ _________ _____ ______ ___ ________ __________ ____ _________.
______ ________ ____ ______ ____ ____ _______ ____ _____ ___ __________ ___.
______ ______ _______ ____ ______ ______.
_________ _______ ________ __________ ________ ___ _____ _________ _____ ___.
___ ________ _______ ________ ______.
_________ ___ _________ __________ ___.
___ ____ _______ _____ __________.
___ _______ ________ _________ _____ _______.
__________ ________ ___ _______ ___ _______ _______ ______ ______ _______.
________ __________ ______ ____ __________ ________ ___ _______.
____ ____ ____ _____ ______ __________ ______ ________ _____ ____.
_______ _______ ______ ________ _______.
__________ __________ ______ ____ ___ ____ __________ ________.
_________ ___ _______ __________ __________ ______.
_________ ___ _________ __________ _______ ___ ______ ________ ______.
___ ________ _______ __________ ______ _____ _______ ______.
_______ ____ ____ __________ ____ ____ ________ __________ _______ ___ ________.
__________ _____ _______ _____ ________ ____ ______ ______ _________.
_________ ______ ___ _______ __________ __________.
______ ____ _______ ________ ___ ____ ______ _________ ___ __________ _________ _____.
___ _____ ___ _____ __________.
_______ __________ ___ ___ _________ ________ __________.
____ ______ _____ _____ _______.
___ _____ __________ ___ _________.
___ ______ _________ __________ __________ ________ ___ _____ _______ ___.
______ _____ ________ ____ ______ ________ _____.
______ ______ ____ ______ _________ ________.
____ _________ ____ _______ ____ ______ ______ _____.
_____ ___ _____ _____ ________ _______ ________ ________ _________ _____ ___.
_____ _____ __________ ____ ____ __________ _______ ___ _______ __________.
______ _____.
Get Full Answer on WhatsApp
IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance  Write a Python Program to implement the Min-Max Algorithm.
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→