Aiml Unit-2
Aiml Unit-2
•Perfect information: A game with the perfect information is that in which agents can look into the complete board. Agents have
all the information about the game, and they can see each other moves also. Examples are Chess, Checkers, Go, etc.
•Imperfect information: If in a game agents do not have all information about the game and not aware with what's going on,
such type of games are called the game with imperfect information, such as tic-tac-toe, Battleship, blind, Bridge, etc.
•Deterministic games: Deterministic games are those games which follow a strict pattern and set of rules for the games, and
there is no randomness associated with them. Examples are chess, Checkers, Go, tic-tac-toe, etc.
•Non-deterministic games: Non-deterministic are those games which have various unpredictable events and has a factor of
chance or luck. This factor of chance or luck is introduced by either dice or cards. These are random, and each action response is
not fixed. Such games are also called as stochastic games.
Example: Backgammon, Monopoly, Poker, etc.
Formalization of the problem:
A game can be defined as a type of search in AI which can be formalized of the following
elements:
That was the complete workflow of the minimax two player game.
Properties of Mini-Max algorithm:
•Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist), in
the finite search tree.
•Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.
•Time complexity- As it performs DFS for the game-tree, so the time complexity of Min-
Max algorithm is O(bm), where b is branching factor of the game-tree, and m is the
maximum depth of the tree.
•Space Complexity- Space complexity of Mini-max algorithm is also similar to DFS
which is O(bm).
Limitation of the minimax Algorithm:
The main drawback of the minimax algorithm is that it gets really slow for complex
games such as Chess, go, etc. This type of games has a huge branching factor, and the
player has lots of choices to decide. This limitation of the minimax algorithm can be
improved from alpha-beta pruning which we have discussed in the next topic.
Heuristic Alpha-Beta Tree Search Algorithm:
The Heuristic Alpha-Beta Tree Search algorithm is a recursive algorithm that explores the
game tree to find the best move for the AI agent. It uses alpha-beta pruning to discard
branches that are guaranteed to be worse than previously explored branches. This
optimization significantly reduces the number of nodes to explore, making the algorithm
more efficient. A heuristic evaluation function is used to estimate the value of each game
state and prioritize exploring more promising branches.
Alpha-Beta Pruning
•Alpha-beta pruning is a modified version of the minimax algorithm. It is an optimization technique for the minimax
algorithm.
•As we have seen in the minimax search algorithm that the number of game states it has to examine are exponential
in depth of the tree. Since we cannot eliminate the exponent, but we can cut it to half. Hence there is a technique by
which without checking each node of the game tree we can compute the correct minimax decision, and this technique
is called pruning. This involves two threshold parameter Alpha and beta for future expansion, so it is called alpha-
beta pruning. It is also called as Alpha-Beta Algorithm.
•Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only prune the tree leaves but also
entire sub-tree.
•The two-parameter can be defined as:
• 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 -∞.
• 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 +∞.
•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.
1.function minimax(node, depth, alpha, beta, maximizingPlayer) is
2.if depth ==0 or node is a terminal node then Pseudo-code for Alpha-beta Pruning:
3.return static evaluation of node
4.if MaximizingPlayer then // for Maximizer Player
5. maxEva= -infinity
6. for each child of node do
7. eva= minimax(child, depth-1, alpha, beta, False)
8. maxEva= max(maxEva, eva)
9. alpha= max(alpha, maxEva)
10. if beta<=alpha
11. break
12. return maxEva
13.else // for Minimizer player
14. minEva= +infinity
15. for each child of node do
16. eva= minimax(child, depth-1, alpha, beta, true)
17. minEva= min(minEva, eva)
18. beta= min(beta, eva)
19. if beta<=alpha
20. break
21. return minEva
Working of Alpha-Beta Pruning:
Let's take an example of two-player search tree to understand the working of Alpha-beta pruning
Step 1: At the first step the, Max player will start first move from node A where α= -∞ and β= +∞, these value of alpha and beta
passed down to node B where again α= -∞ and β= +∞, and Node B passes the same value to its child D.
Step 2: At Node D, the value of α will be calculated as its turn for Max. The value of α is compared with firstly 2 and then 3, and
the max (2, 3) = 3 will be the value of α at node D and node value will also 3.
Step 3: Now algorithm backtrack to node B, where the value of β will change as this is a turn of Min, Now β= +∞, will compare
with the available subsequent nodes value, i.e. min (∞, 3) = 3, hence at node B now α= -∞, and β= 3.
2. Memory Requirements:
- Storing the entire game tree in memory may not be feasible for complex games. The memory requirements for
large game trees can be prohibitive, especially when dealing with limited computational resources.
- Example: In games like Go, where the board size is large, storing the entire game tree in memory becomes
challenging. The sheer number of possible positions and moves requires significant memory resources.
Limitations of Game Search Algorithms
Go Game image
Limitations of Game Search Algorithms
3. Time Constraints:
- Real-time constraints can be challenging for certain game scenarios. In applications where quick decisions are required,
exhaustive search may not be possible, and algorithms need to balance between exploration and exploitation efficiently.
- Example: In real-time strategy games, decisions need to be made quickly. Algorithms like minimax with alpha-beta pruning
may not explore the entire tree within the time constraints, leading to suboptimal decisions.
4. Incomplete Information:
- Game search algorithms assume complete knowledge of the game state. In real-world scenarios, information might be
incomplete or uncertain, making it challenging to accurately evaluate and predict future states.
- Example: In card games like poker, players don't have complete information about the opponent's cards. Game search
algorithms that assume complete knowledge may struggle in such scenarios.
5. Heuristic Quality:
- The effectiveness of heuristic evaluation functions directly impacts the performance of game-playing algorithms. Designing a
good heuristic that accurately reflects the game's dynamics is challenging and may require domain-specific knowledge.
- Example: In the game of checkers, designing a heuristic that accurately captures the positional advantage can be challenging. A
poorly designed heuristic may lead to suboptimal move selection.
Limitations of Game Search Algorithms
Limitations of Game Search Algorithms
6. **Limited Horizon Effect:**
- Algorithms with a fixed depth limit may suffer from the horizon effect, where they fail to see critical moves or strategies
beyond their search depth. This can lead to suboptimal decision-making.
- *Example:* In a real-time strategy game, if the search depth is limited, the algorithm may fail to see potential threats or
opportunities beyond a certain horizon, leading to suboptimal decisions.
7. **Non-Optimal Moves:**
- Game search algorithms might not always find the optimal move due to limitations in the search space exploration.
Suboptimal moves may be chosen if the search is cut off prematurely or if the evaluation function does not capture the true value
of a state.
- *Example:* In the game of Tic-Tac-Toe, if a search algorithm has a limited depth, it may not find the optimal move, allowing the
opponent to force a draw or win.
8. **Adversarial Nature:**
- Game search algorithms assume that opponents play optimally or near-optimally. In reality, opponents may exhibit suboptimal
behavior, randomness, or strategic patterns that the algorithm may not anticipate.
- *Example:* In games like poker, opponents may bluff or deviate from optimal strategies. Algorithms assuming optimal
opponents may struggle to adapt to unpredictable opponent behavior.
Limitations of Game Search Algorithms
9. **Dynamic Environments:**
- Game search algorithms may struggle in dynamic or changing environments where the optimal strategy evolves over time.
Adapting to unforeseen changes in the game dynamics can be challenging.
- *Example:* In a dynamic strategy game where the environment changes over time, algorithms may have difficulty adapting to
new conditions, as they are designed based on a static view of the game.
3) Mutation Operator: The key idea is to insert random genes in offspring to maintain the diversity in the population to avoid
premature convergence. For example –
3) Mutation Operator: The key idea is to insert random genes in offspring to maintain the diversity in the population to avoid
premature convergence. For example –
The whole algorithm can be summarized as –