Adver
Adver
Adver
Game Playing is an important domain of artificial intelligence. Games don’t require much
knowledge; the only knowledge we need to provide is the rules, legal moves and the conditions
of winning or losing the game.
Both players try to win the game. So, both of them try to make the best move possible at each
turn. Searching techniques like BFS(Breadth First Search) are not accurate for this as the
branching factor is very high, so searching will take a lot of time. So, we need another search
procedures that improve –
1. Alpha: The best (highest-value) choice we have found so far at any point along the
path of Maximizer. The initial value of alpha is -∞.
2. Beta: The best (lowest-value) choice we have found so far at any point along the
path of Minimizer. The initial value of beta is +∞.
2. The Alpha-beta pruning to a standard minimax algorithm returns the same move as the
standard algorithm does, but it removes all the nodes which are not really affecting the final
decision but making algorithm slow. Hence by pruning these nodes, it makes the algorithm
fast.
α>=β
Key points about alpha-beta pruning:
o
The Max player will only update the value of alpha.
o
The Min player will only update the value of beta.
o
While backtracking the tree, the node values will be passed to upper nodes instead of
values of alpha and beta.
o
We will only pass the alpha, beta values to the child nodes.
Lab Task
Artificially Intelligent TIC-TAC-TOE Game
Tic-tac-toe (also known as noughts and crosses or Xs and Os) for two players, X and O, who
take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their
marks in a horizontal, vertical, or diagonal row wins the game.
The sample tic tac toe board of order 3 by 3 is shown in the figure below. Suppose player 1 had
chosen X and player 2 has chosen 0.
Problem Statement
You need to implement Min-Max Algorithm to search optimal solution for each player in Tic-
Tac-Toe game. (Algorithm is given at the end for your reference)
Rules of Game :
The simple rules to play the game are:
Two players can play the game. Each player will choose either 0 or X.
The winning of a player is dependent on the consecutive 0s or Xs (in either row or
column or Diagonal ).
Each player will play alternately. There is no biasness towards or against any player.
The game will stop when either player has won.
If no player has won and all the board cells are occupied, the game has been drawn.
Functions:
1- def alpha_beta_pruining(board): Returns the optimal action for the current player on
the board.
2- def minimax(board): Returns the optimal action for the current player on the
board.