0% found this document useful (0 votes)
15 views3 pages

Wa0000

The document outlines the implementation of the Min-Max algorithm, which is used in game theory and artificial intelligence to determine optimal moves in two-player games. It details the steps involved in generating a game tree, evaluating terminal states, propagating utility values, and selecting the optimal move, along with its properties and applications in game AI and decision-making. A code snippet is provided to illustrate the algorithm's implementation, concluding with the successful execution of the Min-Max algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Wa0000

The document outlines the implementation of the Min-Max algorithm, which is used in game theory and artificial intelligence to determine optimal moves in two-player games. It details the steps involved in generating a game tree, evaluating terminal states, propagating utility values, and selecting the optimal move, along with its properties and applications in game AI and decision-making. A code snippet is provided to illustrate the algorithm's implementation, concluding with the successful execution of the Min-Max algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Roll No:

Experiment No. 6

AIM: Implementation of Min-Max algorithm.

THEORY:
● Min-Max algorithm:
The Min Max algorithm is a decision-making algorithm used in the field of game theory
and artificial intelligence. It is used to determine the optimal move for a player in a two-
player game by considering all possible outcomes of the game. The algorithm helps in
selecting the move that minimizes the maximum possible loss. The Min Max algorithm has
many applications in game AI, decision-making, and optimization.

● Algorithm:
Step 1: Generate the Game Tree
Objective: Create a tree structure representing all possible moves from the current
game state.
Details: Each node represents a game state, and each edge represents a possible move.
Step 2: Evaluate Terminal States
Objective: Assign utility values to the terminal nodes of the game tree.
Details: These values represent the outcome of the game (win, lose, or draw).
Step 3: Propagate Utility Values Upwards
Objective: Starting from the terminal nodes, propagate the utility values upwards
through the tree.
Details: For each non-terminal node:
If it's the maximizing player's turn, select the maximum value from the child nodes.
If it's the minimizing player's turn, select the minimum value from the child nodes.
Step 4: Select Optimal Move
Objective: At the root of the game tree, the maximizing player selects the move
that leads to the highest utility value.

● Properties of Min-Max Algorithm:


1. Complete- Min-Max algorithm is Complete. It will definitely find a solution (if
exist), in the finite search tree.
2. Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.
3. Time complexity- As it performs DFS for the game-tree, so the time complexity of
Min-Max algorithm is O(bm), where b is the branching factor of the game-tree, and
m is the maximum depth of the tree.
4. Space Complexity- Space complexity of Min-max algorithm is also similar to DFS
which is O(bm).

● Applications of the MinMax Algorithm:


1. Game AI: Game AI uses the MiniMax algorithm quite frequently. Game designers
use the algorithm to build AI opponents that are capable of playing poker, tic-tac-
toe, and chess at a high level. Even in complex games with enormous search spaces,
the AI can make the best decisions by using the MinMax algorithm.
2. Decision-Making: The MinMax algorithm can also be utilized in decision-making
processes, such as financial planning and resource allocation. Decision-makers can
make better choices and limit losses by using this algorithm.

● Code:
import math def minimax(node,

is_maximizing, tree):

if node not in tree:


return node

if is_maximizing:
best_value = -math.inf
for child in tree[node]:
best_value = max(best_value, minimax(child, False, tree))
return best_value
else:
best_value = math.inf
for child in tree[node]:
best_value = min(best_value, minimax(child, True, tree))
return best_value

def get_tree(): tree = {} num_nodes = int(input("Enter


number of internal nodes: ")) for _ in range(num_nodes):
node = input("Enter node name: ") children = input(f"Enter children of
{node} separated by spaces: ").split() tree[node] = [int(child) if
child.isdigit() else child for child in children]
return tree

tree = get_tree()

root =
input("Enter root

node: ")

# Run Minimax on the root node


optimal_value = minimax(root, True, tree)
print("Optimal value:", optimal_value)

● Output:

CONCLUSION : Thus I successfully implemented the Min-Max algorithm .

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy