0% found this document useful (0 votes)
16 views

Ai-Unit 3

The document provides information about game playing and constraint satisfaction problems (CSP) in artificial intelligence. It discusses adversarial search, game theory concepts like zero-sum games and game trees. It also covers constraint satisfaction problems and their components - variables, domains, and constraints. Minimax algorithm is used for optimal decision making in games by maximizing rewards for the player and minimizing it for the opponent. Stochastic games introduce chance elements using dice or cards. CSPs are solved by assigning values to variables in a consistent way without violating any constraints.

Uploaded by

maharajan241jf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Ai-Unit 3

The document provides information about game playing and constraint satisfaction problems (CSP) in artificial intelligence. It discusses adversarial search, game theory concepts like zero-sum games and game trees. It also covers constraint satisfaction problems and their components - variables, domains, and constraints. Minimax algorithm is used for optimal decision making in games by maximizing rewards for the player and minimizing it for the opponent. Stochastic games introduce chance elements using dice or cards. CSPs are solved by assigning values to variables in a consistent way without violating any constraints.

Uploaded by

maharajan241jf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 67

AL3391-ARTIFICIAL INTELLIGENCE

UNIT - III (GAME PLAYING AND CSP)

Prepared by,

C.Usharani, AP/AD
Ramco Institute of Technology,
Rajapalayam-626117.
GAME PLAYING

• Game theory is basically a branch of mathematics that is used


to typical strategic interaction between different players
(agents), all of which are equally rational, in a context with
predefined rules and outcomes
• Every player or agent is a rational entity who is selfish and
tries to maximize the reward to be obtained using a particular
strategy.
• Hence, a GAME can be defined as a set of players, actions,
strategies, and a final playoff for which all the players are
competing
Adversarial Search
• Adversarial search is a search, where we examine the
problem which arises when we try to plan ahead of the
world and other agents are planning against us.
• The environment with more than one agent is termed as multi-
agent environment, in which each agent is an opponent of
other agent and playing against each other. Each agent needs
to consider the action of other agent and effect of that action
on their performance.
• So, Searches in which two or more players with conflicting
goals are trying to explore the same search space for the
solution, are called adversarial searches, often known as
Games.
Types of Games in AI

 Zero-Sum and Non-Zero Sum Games


 Simultaneous and Sequential Games
 Imperfect Information and Perfect Information Games
 Asymmetric and Symmetric Games
 Co-operative and Non-Co-operative Games
• Zero-Sum and Non-Zero Sum Games: In non-zero-sum games,
there are multiple players and all of them have the option to gain a
benefit due to any move by another player. In zero-sum games,
however, if one player earns something, the other players are bound
to lose a key playoff.

• Simultaneous and Sequential Games: Sequential games are the


more popular games where every player is aware of the movement
of another player. Eg: BOARD GAMES
• Simultaneous games are more difficult as in them, the players are
involved in a concurrent game.
• Imperfect Information and Perfect Information Games: In a perfect
information game, every player is aware of the movement of the other
player and is also aware of the various strategies that the other player
might be applying to win the ultimate playoff. Eg: CHESS
• In imperfect information games, however, no player is aware of what the
other is up to. Eg:CARDS are an amazing example of Imperfect
information games
• Asymmetric and Symmetric Games: Asymmetric games are those win in
which each player has a different and usually conflicting final goal.
Symmetric games are those in which all players have the same ultimate
goal but the strategy being used by each is completely different.
• Co-operative and Non-Co-operative Games: In non-co-operative games,
every player plays for himself while in co-operative games, players form
alliances in order to achieve the final goal.
Formalization of the problem

• A game can be defined as a type of search in AI which can be formalized of


the following elements:

Initial state: It specifies how the game is set up at the start.


Player(s): It specifies which player has moved in the state space.
Action(s): It returns the set of legal moves in state space.
Result(s, a): It is the transition model, which specifies the result of moves in the
state space.
Terminal-Test(s): Terminal test is true if the game is over, else it is false at any case.
The state where the game ends is called terminal states.
Utility(s, p): A utility function gives the final numeric value for a game that ends in
terminal states s for player p. It is also called payoff function. For Chess, the
outcomes are a win, loss, or draw and its payoff values are +1, 0, ½. And for tic-tac-
toe, utility values are +1, -1, and 0.
Game tree

• A game tree is a tree where nodes of the tree are the game states and
Edges of the tree are the moves by players. Game tree involves
initial state, actions function, and result Function.
• Example: Tic-Tac-Toe game tree:
• The following figure is showing part of the game-tree for tic-tac-toe
game. Following are some key points of the game:
• There are two players MAX and MIN.
• Players have an alternate turn and start with MAX.
• MAX maximizes the result of the game tree
• MIN minimizes the result.
Explanation:
• From the initial state, MAX has 9 possible moves as he starts first.
MAX place x and MIN place o, and both player plays alternatively
until we reach a leaf node where one player has three in a row or all
squares are filled.
• Both players will compute each node, minimax, the minimax value
which is the best achievable utility against an optimal adversary.
• Suppose both the players are well aware of the tic-tac-toe and
playing the best play. Each player is doing his best to prevent
another one from winning. MIN is acting against Max in the game.
• So in the game tree, we have a layer of Max, a layer of MIN, and
each layer is called as Ply. Max place x, then MIN puts o to prevent
Max from winning, and this game continues until the terminal node.
• In this either MIN wins, MAX wins, or it's a draw. This game-tree is
the whole search space of possibilities that MIN and MAX are
playing tic-tac-toe and taking turns alternately.
• Hence adversarial Search for the minimax procedure works as follows:
• It aims to find the optimal strategy for MAX to win the game.
• It follows the approach of Depth-first search.
• In the game tree, optimal leaf node could appear at any depth of the tree.
• Propagate the minimax values up to the tree until the terminal node
discovered.
• In a given game tree, the optimal strategy can be determined from the
minimax value of each node, which can be written as MINIMAX(n). MAX
prefer to move to a state of maximum value and MIN prefer to move to a
state of minimum value then:
Optimal Decisions in Games

Let us start with games with two players, whom we’ll refer to as MAX and
MIN for obvious reasons. MAX is the first to move, and then they take turns
until the game is finished. At the conclusion of the game, the victorious player
receives points, while the loser receives penalties. A game can be formalized
as a type of search problem that has the following elements:
initial state
Player
Actions
Result
Terminal-Test
Utility
• The game tree for tic-tac-toe is relatively short, with just 9! = 362,880
terminal nodes.
• However, because there are over 1040 nodes in chess, the game tree is
better viewed as a theoretical construct that cannot be realized in the actual
world
Optimal decision in Multiplayer Games
MINI MAX ALGORITHM IN AI
stochastic games.

• 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.
• There are 36 different ways to roll two dice, each equally likely, yet there are only 21 distinct
rolls because a 6–5 is the same as a 5–6. P (1–1) = 1/36 because each of the six doubles (1–1
through 6–6) has a probability of 1/36. Each of the other 15 rolls has a 1/18 chance of
happening.
• We compute the expected value for chance
nodes, which is the sum of all outcomes,
weighted by the probability of each chance
action.
CSP
Constraint satisfaction is a technique where a problem is solved when its
values satisfy certain constraints or rules of the problem. Such type of
technique leads to a deeper understanding of the problem structure as well as
its complexity.

Constraint satisfaction depends on three components,


X: It is a set of variables.
D: It is a set of domains where the variables reside. There
is a specific domain for each variable.
C: It is a set of constraints which are followed by the set
of variables.

The constraint value consists of a pair of {scope, rel}.


scope - tuple of variables which participate in the constraint
rel – It is a relation which includes a list of values which the variables can
take to satisfy the constraints of the problem.
• The requirements to solve a constraint satisfaction problem (CSP) is:
state-space
The notion of the solution.
• A state in state-space is defined by assigning values to some or all
variables such as {X1=v1, X2=v2, and so on…}.

An assignment of values to a variable can be done in three ways:


Consistent or Legal Assignment: An assignment which does not violate any
constraint or rule is called Consistent or legal assignment.
Complete Assignment: An assignment where every variable is assigned with
a value, and the solution to the CSP remains consistent. Such assignment is
known as Complete assignment.
Partial Assignment: An assignment which assigns values to some of the
variables only. Such type of assignments are called Partial assignments.
Types of Domains
There are following two types of domains which are used by the variables :

Discrete Domain: It is an infinite domain which can have one state for
multiple variables. For example, a start state can be allocated infinite times for
each variable.

Eg: only 3 colors in Map coloring problem

Finite Domain: It is a finite domain which can have continuous states


describing one domain for one specific variable. It is also called a continuous
domain.
Eg: Weather Sensing problem
Constraint Types in CSP
Unary Constraints: It is the simplest type of constraints that restricts
the value of a single variable.
Binary Constraints: It is the constraint type which relates two
variables. A value x2 will contain a value which lies between x1 and
x3.
Global Constraints: It is the constraint type which involves an
arbitrary number of variables.
Linear Constraints: These type of constraints are commonly used in
linear programming where each variable containing an integer value
exists in linear form only.
Non-linear Constraints: These type of constraints are used in non-
linear programming where each variable (an integer value) exists in a
non-linear form.
Examples
Sudoku Playing: The gameplay where the constraint is that no
number from 0-9 can be repeated in the same row or column.
n-queen problem: In n-queen problem, the constraint is that no
queen should be placed either diagonally, in the same row or
column.
Crossword: In crossword problem, the constraint is that there
should be the correct formation of the words, and it should be
meaningful.
Cryptarithmetic Problem: This problem has one most
important constraint that is, we cannot assign a different digit to
the same character. All digits should contain a unique
alphabet. Solve SEND+MORE=MONEY
Constraint Propagation

• In CSP, We can search for a solution and also we can assign


the value to the variable.
• We can perform a special type of inference called constraint
propagation.
• Constraint propagation is a special type of inference which
helps in reducing the legal number of values for the variables.
The idea behind constraint propagation is local consistency.
• variables are treated as nodes, and each binary constraint is
treated as an arc in the given problem.
4 types:
Node consistency
Arc Consistency
Path consistency
K consistency
Node Consistency: A single variable is said to be
node consistent if all the values in the variable’s
domain satisfy the unary constraints on the
variables.
Arc Consistency: A variable is arc consistent if
every value in its domain satisfies the binary
constraints of the variables.

Refer AC3 algorithm in Text book (Fig 6.3)


• Path Consistency: When the evaluation of a set of two
variable with respect to a third variable can be extended over
another variable, satisfying all the binary constraints. It is
similar to arc consistency.

k-consistency: This type of consistency is used to define


the notion of stronger forms of propagation.
Backtracking search for CSP

Backtracking search: A depth-first search that chooses values


for one variable at a time and backtracks when a variable has no
legal values left to assign.

Backtracking algorithm repeatedly chooses


an unassigned variable, and then tries all values in the domain of
that variable in turn, trying to find a solution. If an inconsistency
is detected, then BACKTRACK returns failure.

Backtracking search, a form of depth-first


search, is commonly used for solving CSPs
Local search for CSP
• Local search algorithms for CSPs use a complete-state
formulation: the initial state assigns a value to every variable,
and the search change the value of one variable at a time.

• The min-conflicts heuristic: In choosing a new value for a


variable, select the value that results in the minimum number
of conflicts with other variables.
Structure of CSP
Tree Decomposition
Sub division of Map colouring algorithm

You might also like