AI Lab08
AI Lab08
ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI
LAB MANUAL – 08
Lab Objective:
● To implement genetic algorithm in python
Hardware/Software required:
Hardware: Desktop/ Notebook Computer
Software Tool: Python 3.10.0
Lab Description:
Minimax is a decision rule used in decision theory, game theory, statistics and philosophy for
minimizing the possible loss for a worst case (maximum loss) scenario. When dealing with
gains, it is referred to as "maximin"—to maximize the minimum gain.
Use: Originally formulated for two-player zero-sum game theory, covering both the cases where
players take alternate moves and those where they make simultaneous moves, it has also been
extended to more complex games and to general decision-making in the presence of uncertainty.
class Node:
def __init__(self,val):
self.left = None
self.right = None
self.data = val
Alpha–beta pruning is a search algorithm that seeks to decrease the number of nodes that are
evaluated by the minimax algorithm in its search tree. It is an adversarial search algorithm used
commonly for machine playing of two-player games (Tic-tac-toe, Chess, Go, etc.). It stops
completely evaluating a move when at least one possibility has been found that proves the move
to be worse than a previously examined move. Such moves need not be evaluated further. When
applied to a standard minimax tree, it returns the same move as minimax would, but prunes
away branches that cannot possibly influence the final decision.
The pseudocode for the minimax with alpha-beta pruning is:
if maximizingPlayer
v := -∞
for each child of node
v := max(v, alphabeta(child, depth + 1, α, β, FALSE))
α := max(α, v)
if β ≤ α
break (* β cut-off *)
return v
else
v := +∞
for each child of node
v := min(v, alphabeta(child, depth +1, α, β, TRUE))
β := min(β, v)
if β ≤ α
break (* α cut-off *)
return v
Note: We are not covering the case in which only terminal values are given so we’ll have to find
the values of nodes at the runtime.
Lab Tasks:
1. Implement minimax algorithm for Tree 1 to find the MinMAx value of the given node,
Import the time module and calculate the total time taken by your minimax algorithm.
Tree 1