Search Algorithms Part 2
Search Algorithms Part 2
Search Part II
Created @October 14, 2024 8:42 PM
Tags
Random-Trace Pathfinding
Description:
Limitations:
1. Search Part II 1
It may only pick from a few paths, despite the existence of many possible
routes from the start to the goal.
A type of best-first search where nodes are selected for expansion based
on an evaluation function f(n).
Evaluation Function:
f(n) is viewed as a cost estimate; the node with the lowest evaluation is
expanded first.
Heuristic Function:
h(n) = estimated cost of the cheapest path from the state at node n to
the goal state.
Functionality:
The algorithm attempts to expand the node that appears closest to the
goal, under the assumption that this will lead to a solution more quickly.
1. Search Part II 2
Some algorithms may be misled and fail to find a path.
Those that always find the most optimal path are referred to as optimal
algorithms.
Resource Usage:
A* Search Algorithm
Characteristics
Optimality Conditions:
Admissible Heuristic: h(n) never overestimates the true cost to reach the
goal.
Consistent Heuristic: For every node n and successor n' with step cost
c:
h(n) = h(n′ ) + c
Overview
A* combines features of Best-First Search and Dijkstra’s Algorithm. Both of
these are derivatives of the Breadth-First Algorithm.
Pathfinding Process
Open List: Keeps track of paths that still need processing.
Steps:
1. Search Part II 3
1. Start with the open list containing the initial state.
4. Expand the node, generating new states and adding them to the open list.
Advantages
A* is complete and guarantees to find a solution if one exists, regardless of the
map's complexity.
The algorithm balances the costs of reaching nodes and the estimated cost to
the goal, providing a more directed search compared to others.
Drawbacks:
Does not prioritize direction toward the goal, making it inefficient in terms
of CPU cycles.
2. Best-First Search
Approach: Uses heuristics to expand nodes that appear closest to the goal.
Limitations:
1. Search Part II 4
While faster than BFS, it may not always find the optimal path, as it
focuses solely on getting close to the goal.
3. Dijkstra’s Algorithm
Approach: Similar to BFS, but it expands the cheapest node first.
Data Structure: Also uses a priority queue but based on path costs.
Benefits:
Guarantees the optimal solution by keeping track of the path cost to each
node.
Drawbacks:
Minimax Algorithm
Definition
A strategy used in two-player games where one player (Max) aims to
maximize their score while the opponent (Min) aims to minimize it.
1. Search Part II 5
2. Value Assignment: Each terminal state is assigned a value (-1, 0, or +1).
3. Alternating Turns: The maximizing player asks what the minimizing player
would do to minimize the score and vice versa, leading to a recursive
evaluation of possible states.
4. State Values: After evaluating, the maximizing player chooses the action
leading to the highest value.
Pseudocode
Function Max-Value(state):
if Terminal(state):
return Utility(state)
v = -∞
for action in Actions(state):
v = Max(v, Min-Value(Result(state, action)))
return v
Function Min-Value(state):
if Terminal(state):
return Utility(state)
v = ∞
for action in Actions(state):
v = Min(v, Max-Value(Result(state, action)))
return v
Alpha-Beta Pruning
Definition
An optimization technique for the Minimax algorithm that reduces the number
of nodes evaluated.
Mechanism
Alpha Value: The best score that the maximizing player can guarantee.
1. Search Part II 6
Beta Value: The best score that the minimizing player can guarantee.
When the maximizing player finds a move that is worse than the previously
examined options, further exploration of that branch is unnecessary.
Example
If a maximizing player has an action valued at 4 and discovers another action
that leads to a minimum value of 3, they can prune other branches since they
have already established a better option (4).
Depth-Limited Minimax
Overview
In games like Tic-Tac-Toe (255,168 possible games) and Chess (10²⁹⁰⁰⁰
possible games), generating all hypothetical games to terminal conditions can
be computationally expensive or infeasible.
Approach
Limits the depth of the search to a predefined number of moves before
stopping.
Uses an evaluation function to estimate the utility of the game from a given
state instead of reaching terminal states.
Utility Function
Evaluates the board configuration based on the pieces and their positions.
Returns a positive or negative value indicating the favorability of the state for
either player.
Classification of Games
Adversarial Search
Game Definition: The complete set of rules that describes a game.
1. Search Part II 7
Play: An instance of the game.
Rational Behavior: Players are assumed to optimize their payoffs, being aware
that other players are doing the same.
Classification of Games
Criteria for Classification
1. Number of Players:
Simultaneous Game: Players make decisions at the same time (e.g., Rock-
Paper-Scissors).
3. Random Moves:
Perfect Information: Every player knows all previous moves (e.g., Chess).
5. Zero-Sum Games:
The total payoff to all players equals zero; one player's gain is another's
loss (e.g., Poker, Chess).
1. Search Part II 8
Simultaneous Games
Characteristics
In simultaneous games, each player has only one move, and all moves are
made simultaneously.
Players may have different roles and options for moves, and each player has
finitely many options.
For Player II, the payoff is the negative of Player I's payoff, i.e., \(-A_{ij}\).
Player I wins if the sum is odd, while Player II wins if the sum is even.
1 (Player I) 2 -3
2 (Player I) -3 4
1. Search Part II 9
Here, each entry \( A_{ij} \) represents Player I's payoff. For instance:
If both players choose 1, the sum is 2 (even), so Player II wins, and the payoff
for Player I is -2.
If Player I chooses 1 and Player II chooses 2, the sum is 3 (odd), and Player I
wins 3
solution
Choices:
Payoff:
The loser pays the winner an amount equal to the product of the
numbers chosen.
\[
A = \begin{bmatrix}
-2 & 3 \\
1. Search Part II 10
3 & -4 \\
\end{bmatrix}
\]
1. Search Part II 11
So, Player I should choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).
\[
3 + 4 = 7q + 5q
\]
\[
7 = 12q \implies q = \frac{7}{12}
\]
So, Player II should choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).
1. Search Part II 12
\[
E = (-2)(\frac{7}{12})(\frac{7}{12}) + 3(\frac{7}{12})(\frac{5}{12}) +
3(\frac{5}{12})(\frac{7}{12}) + (-4)(\frac{5}{12})(\frac{5}{12})
\]
Simplifying step-by-step:
\[
E = -\frac{98}{144} + \frac{105}{144} + \frac{105}{144} - \frac{100}{144}
\]
Combine the terms:
\[
E = \frac{-98 + 105 + 105 - 100}{144} = \frac{12}{144} = \frac{1}{12}
\]
The game is not fair. Player I has an advantage since the expected value
indicates that Player I can expect to win \( \frac{1}{12} \) dollars per game.
Optimal Strategies:
Player II: Choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).
Summary
Player I can guarantee an average win of \( \frac{1}{12} \) each time the
game is played, making it advantageous for Player I. Thus, even with
optimal strategies employed, Player II cannot avoid losses entirely.
This is the complete solution to the Odd-or-Even game problem with the
modifications specified! Let me know if you have any questions or need
further clarification.
1. Search Part II 13
Solving the Game: Saddle Points and Minimax Strategy
Saddle Points
A saddle point in a payoff matrix is an entry \( A_{ij} \) that satisfies:
The value of the game is equal to that saddle point, meaning both players
have an optimal strategy by choosing the corresponding row and column.
Example
Consider a payoff matrix:
Column 1 Column 2
Row 1 1 3
Row 2 2 2
Therefore, the value of the game is 2. The optimal strategy for Player I is to
choose Row 2, and for Player II to choose Column 2.
No Saddle Point
When there is no saddle point in the matrix, the game does not have a
straightforward solution through pure strategies.
1. Search Part II 14
In such cases, mixed strategies or equalizing strategies can be used:
Mixed Strategies
Pure vs. Mixed Strategies
Pure Strategy: A player consistently chooses the same move.
For example, if Player I's optimal mixed strategy is to choose "1" with
7
probability 12 and "2" with /eq then Player I is using a mixed strategy.
A=[ ]
a b
c d
1. Determine Probabilities:
Strict Domination: If one row's values are always less than or equal to another
row's values, the dominated row can be removed.
1. Search Part II 15
Pruning the Matrix
To simplify the analysis, dominated rows or columns can be removed, ideally
reducing the matrix to a simpler form, such as a 2x2 matrix.
Removing dominated strategies does not change the value of the game,
although it may affect the set of optimal strategies.
Example: Simplification
1. Original Payoff Matrix:
3 2 5
A= 1 4 3
0 3 6
If the first row is dominated by the second row, remove the first row.
2. Reduced Matrix:
1 4 3
A=[ ]
0 3 6
Player I can guarantee at least \( V \), and Player II can limit their loss to at
most \( V \), using optimal strategies.
Interpretation
1. Search Part II 16
If \( V = 0 \): The game is fair.
1. Search Part II 17