Question

Write a Python Program to implement Min-Max Algorithm.

07 Mar 2024
Answer :
Word Count : 467

import math

# Constants for the game
PLAYER_X = 'X'
PLAYER_O = 'O'
EMPTY = ' '

def print_board(board):
    """Function to print the Tic-Tac-Toe board"""
    for row in board:
        print(" | ".join(row))
        print("-" * 5)

def is_winner(board, player):
    """Check if the player has won"""
    win_conditions = [
        # Check rows
        [board[0][0], board[0][1], board[0][2]],
        [board[1][0], board[1][1], board[1][2]],
        [board[2][0], board[2][1], board[2][2]],
        # Check columns
        [board[0][0], board[1][0], board[2][0]],
        [board[0][1], board[1][1], board[2][1]],
        [board[0][2], board[1][2], board[2][2]],
        # Check diagonals
        [board[0][0], board[1][1], board[2][2]],
        [board[0][2], board[1][1], board[2][0]],
    ]
    return [player, player, player] in win_conditions

def is_board_full(board):
    """Check if the board

__________ ______ ____ ___ ___ _________ __________.
________ ______ ________ __________ ______ _____.
____ ______ ______ _________ __________.
_________ _____ ___ _______ ________ _______.
________ ___ ____ ______ ____.
______ ___ _____ ______ __________ ____.
________ _______ ___ ________ ___.
________ _______ __________ _____ __________ ____ __________ ________ _____ ____.
____ _________ ______ __________ _____ ___ _______ __________ __________ _______ _____.
_________ ______ __________ _____ _____ ____ __________.
____ ____ ________ _____ ________ _______ ___ _________ ___ ____ _______ ____.
_____ __________ _______ _________ _______ _________ ___.
___ ________ _____ __________ ___ ______ __________ ___ __________ _______ ___.
________ ____ _____ _________ _________ _________.
______ _______ ______ ___ ______ ________.
___ ____ ___ __________ __________ ____ ________ ___ ____ __________ _________.
____ _____ _________ ______ ________ ______ ____ _________ ___ _________ ___ ____.
_________ ____ ______ __________ ______ ________ _________ ________.
________ ________ __________ _________ ______ ___ _________ ____ _________ _______.
________ ___ ______ ____ __________ ____ ____.
____ ________ ___ __________ ___ _____ _________ ___ ___ __________ ________ _________.
__________ ________ __________ _________ _________ _______ ________ _____.
_________ _____ ___ _____ _________ __________ __________.
_________ ____ _____ ____ ________ ______ ________ ___ _______ _________ _________.
_________ ________ ________ ___ ________ _______ __________ ________ ______ __________ _____.
__________ ___ ____ ______ _________ _________ ___ ____.
_____ ____ ________ __________ ______ ___ ______ ________.
________ _______ ________ ___ __________ _____ ____ ________ ____ ___.
_________ __________ __________ _______ _______ _____ _____ ___ ___ ___ ______.
________ _____ __________ __________ _________ _________ _____.
___ _________ _____ _______ _____ _____ __________ ____.
______ ______ _________ ______ _______ ________ _______.
________ __________ ________ ______ _________.
__________ ______ ____ ______ _____ ________ __________ ___ _____ ___ _______ _______.
________ _____.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCSL 228 2024 - Write a Python Program to implement Min-Max Algorithm. | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→