Cs217 PC Search in Chess Week7 17feb25
Cs217 PC Search in Chess Week7 17feb25
Machine Learning
(associated lab: CS240)
Pushpak Bhattacharyya
CSE Dept.,
IIT Bombay
Week7 of 17feb25, Predicate Calculus,
Search in Chess
Main points covered: week6 of
10feb25
Important pointes associated with FFNN BP
Local Minima
Momentum Factor
Symmetry Breaking
Hilbert's formalization of propositional calculus
1. Elements are propositions : Capital letters
2. Operator is only one : (called implies)
3. Special symbol F (called 'false')
4. Two other symbols : '(' and ')'
5. Well formed formula is constructed according to the grammar
WFF P|F|WFFWFF
6. Inference rule : only one
Given AB and
A
write B
known as MODUS PONENS
7. Axioms : Starting structures
A1: ( A ( B A))
A2: (( A ( B C )) (( A B) ( A C )))
A3 ((( A F ) F ) A)
├ is read as 'derives'
Given
A1 A1
A2 A2
A3 A3
. .
. .
. .
. .
An An-1
B An B
Picture 1 Picture 2
Soundness, Completeness &
Consistency
Soundness
Syntactic Semantic
World World
---------- ----------
Valuation,
Theorems,
Tautology
Proofs
Completeness
* *
Consistency
The System should not be able to
able to derive
F
End of main points
Predicate calculus
Insight into resolution
Resolution - Refutation
man(x) → mortal(x)
Convert to clausal form
~man(shakespeare) \/ mortal(x)
Clauses in the knowledge base
~man(shakespeare) \/ mortal(x)
man(shakespeare)
mortal(shakespeare)
Resolution – Refutation contd
Negate the goal
~man(shakespeare)
Get a pair of resolvents
~ mortal ( shakespeare) ~ man( x) mortal ( x)
Re solvent1 Re solvent2
Re solute
Search in resolution
Heuristics for Resolution Search
Goal Supported Strategy
Always start with the negated goal
Set of support strategy
Always one of the resolvents is the most recently
produced resolute
Inferencing in Predicate Calculus
Forward chaining
Given P, P Q , to infer Q
P, match L.H.S of
Assert Q from R.H.S
Backward chaining
Q, Match R.H.S of P Q
assert P
Check if P exists
Resolution – Refutation
Negate goal
Convert all pieces of knowledge into clausal form (disjunction of
literals)
See if contradiction indicated by null clause can be derived
1. P
2. P Q converted to ~ P Q
3. ~Q
Draw the resolution tree (actually an inverted
tree). Every node is a clausal form and
branches are intermediate inference steps.
~Q ~ PQ
~P P
Theoretical basis of Resolution
Resolution is proof by contradiction
resolvent1 .AND. resolvent2 => resolute is a
tautology
PQ P Q
Q
Tautologiness of Resolution
Using Semantic Tree (assume the RHS
of is false)
( P Q)^ (P Q)
Q
Contradiction
PQ
P Q
P Q
P Q
Theoretical basis of Resolution
(cont …)
Monotone Inference
Size of Knowledge Base goes on increasing
as we proceed with resolution process
since intermediate resolvents added to the
knowledge base
Non-monotone Inference
Size of Knowledge Base does not increase
Human beings use non-monotone
inference
Back to Himalayan Club
Himalayan Club example
Rules
Example contd.
Let mc denote mountain climber and sk denotes skier.
Knowledge representation in the given problem is as follows:
1. member(A)
2. member(B)
3. member(C)
4. ∀x[member(x) → (mc(x) ∨ sk(x))]
5. ∀x[mc(x) → ~like(x,rain)]
6. ∀x[sk(x) → like(x, snow)]
7. ∀x[like(B, x) → ~like(A, x)]
8. ∀x[~like(B, x) → like(A, x)]
9. like(A, rain)
10. like(A, snow)
11. Question: ∃x[member(x) ∧ mc(x) ∧ ~sk(x)]
We have to infer the 11th expression from the given 10.
Done through Resolution Refutation.
Club example: Inferencing
1. member(A)
2. member(B)
3. member(C)
4. x[member ( x) (mc( x) sk ( x))]
– Can be written as
[member ( x) (mc( x) sk ( x))]
– ~ member ( x) mc( x) sk ( x)
5. x[ sk ( x) lk ( x, snow)]
– ~ sk ( x) lk ( x, snow)
6. x[mc( x) ~ lk ( x, rain)]
– ~ mc( x) ~ lk ( x, rain)
7. x[like( A, x) ~ lk ( B, x)]
– ~ like( A, x) ~ lk ( B, x)
8. x[~ lk ( A, x) lk ( B, x)]
– lk ( A, x) lk ( B, x)
9. lk ( A, rain)
10. lk ( A, snow)
11. x[member ( x) mc( x) ~ sk ( x)]
– Negate– x[~ member ( x) ~ mc( x) sk ( x)]
Now standardize the variables apart which
results in the following
1. member(A)
2. member(B)
3. member(C)
4. ~ member ( x1) mc( x1) sk ( x1)
5. ~ sk ( x 2) lk ( x 2, snow)
6. ~ mc( x3) ~ lk ( x3, rain)
7. ~ like( A, x 4) ~ lk ( B, x 4)
8. lk ( A, x5) lk ( B, x5)
9. lk ( A, rain)
10. lk ( A, snow)
11. ~ member ( x 6) ~ mc( x 6) sk ( x 6)
~ like( A, x 4) ~ lk ( B, x 4) lk ( A, snow) 10
7
12 ~ lk ( B, snow) ~ sk ( x 2) lk ( x 2, snow) 5
11
~ member ( x 6) ~ mc( x 6) sk ( x 6) mc(B) 15
16 ~ member ( B) sk ( B) ~ sk ( B) 13
shakespeare is a man
man(shakespeare)
Sentence
Subject Predicate
Subject Predicate
Generalizing,
3 place predicate
Example: x gives y to z give(x,y,z)
4 place predicate
Example: x gives y to z through w give(x,y,z,w)
Double causative in Hindi giving
rise to higher place predicates
जॉन ने खाना खाया
John ne khana khaya
John <CM> food ate
John ate food
eat(John, food)
P : D n {T , F }
f : Dn D
president(India) : Droupadi Murmu
Constants & Variables : Zero-order objects
Predicates & Functions : First-order
objects
Universal Quantifier
Existential Quantifier
man(x) → mortal(x)
Dropping the quantifier, implicitly Universal
quantification assumed
man(shakespeare)
Goal mortal(shakespeare)
Found in one step
x = shakespeare, unification
Backward Chaining
man(x) → mortal(x)
Goal mortal(shakespeare)
x = shakespeare
Travel back over and hit the fact asserted
man(shakespeare)
Wh-Questions and Knowledge
what
where
Factoid / Declarative
who
when
which
how procedural
why Reasoning
Fixing Predicates
Natural Sentences
<Subject> <verb> <object>
Verb(subject,object)
predicate(subject)
Examples
Ram is a boy
Boy(Ram)?
Is_a(Ram,boy)?
Interpretation:1
D=N (natural numbers)
a = 0 and b = 1
x∈N
P(x) stands for x > 0
g(m,n) stands for (m x n)
h(x) stands for (x – 1)
Above interpretation defines Factorial
Examples (contd.)
Interpretation:2
D={strings)
a=b=λ
P(x) stands for “x is a non empty string”
g(m, n) stands for “append head of m
to n”
h(x) stands for tail(x)
Above interpretation defines “reversing a string”
Search inside Chess!
IIT Bombay
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 1 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
Games as Search Problems
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 2 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
State Space Representation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 3 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
Operators in Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 4 / 38
A Simple Game with Two Players
A B C
A1 A2 A3 C1 C2
C11 C12
C21 C22
C221 C222
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 5 / 38
Chess as a Search Problem
State space:
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Position of all pieces
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Position of all pieces
Turn indicator
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Position of all pieces
Turn indicator
Castling rights, en passant possibilities
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Position of all pieces
Turn indicator
Castling rights, en passant possibilities
Initial state: Standard chess setup
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess as a Search Problem
State space:
8×8 board configuration
Position of all pieces
Turn indicator
Castling rights, en passant possibilities
Initial state: Standard chess setup
Goal states: Checkmate positions
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 6 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Chess Operators
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 7 / 38
Example
Consider the game of chess with the following configuration of the board.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 8 / 38
Example
Consider the game of chess with the following configuration of the board.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 8 / 38
Example
Consider the game of chess with the following configuration of the board.
Now Black player makes a move (Bc8 → Bg4) indicating an action and
taking to a new game state.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 9 / 38
Example
Consider the game of chess with the following configuration of the board.
Now Black player makes a move (Bc8 → Bg4) indicating an action and
taking to a new game state.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 9 / 38
Example
Consider the game of chess with the following configuration of the board.
Now Black player makes a move (Bc8 → Bg4) indicating an action and
taking to a new game state.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 9 / 38
Snippet of Game Graph of chess
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 10 / 38
Question
How will we solve a game?
What do you mean by solving?
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 11 / 38
Solving a Game
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 12 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Search and Games
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 13 / 38
Can we getting a winning strategy from
the path found by our search algorithm?
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 14 / 38
Limitations of Search
For most games the state space is enoromously large. For chess
∼ 1040 nodes - practically impossible to search.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 15 / 38
Limitations of Search
For most games the state space is enoromously large. For chess
∼ 1040 nodes - practically impossible to search.
Search might not give us a strategy to solve a game. We can rather
focus on simpler problems!
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 15 / 38
Limitations of Search
For most games the state space is enoromously large. For chess
∼ 1040 nodes - practically impossible to search.
Search might not give us a strategy to solve a game. We can rather
focus on simpler problems!
A* excels on simplified subproblems or variants:
1 Knight’s Shortest Path Problem
2 Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 15 / 38
Knight’s Shortest Path Problem
Objective: Find the minimum number of moves for a knight to travel
from a start square to a target square on an 8 × 8 chessboard.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 16 / 38
Knight’s Shortest Path Problem
Objective: Find the minimum number of moves for a knight to travel
from a start square to a target square on an 8 × 8 chessboard.
State Space:
S = {(i, j) | 1 ≤ i, j ≤ 8}
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 16 / 38
Knight’s Shortest Path Problem
Objective: Find the minimum number of moves for a knight to travel
from a start square to a target square on an 8 × 8 chessboard.
State Space:
S = {(i, j) | 1 ≤ i, j ≤ 8}
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 16 / 38
Knight’s Shortest Path Problem
Objective: Find the minimum number of moves for a knight to travel
from a start square to a target square on an 8 × 8 chessboard.
State Space:
S = {(i, j) | 1 ≤ i, j ≤ 8}
Target
Start
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 17 / 38
Knight’s Shortest Path - Possible Moves
Knight’s Shortest Path - Possible Moves
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 18 / 38
Knight’s Shortest Path - Shortest Path
Knight’s Shortest Path - Shortest Path
Knight’s Shortest Path - Shortest Path
Knight’s Shortest Path - Shortest Path
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 19 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 20 / 38
Endgame Tablebase Approximation
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 21 / 38
Endgame Tablebase Approximation
where:
d(n, edge) is the distance of the Black king from the nearest edge.
Mobility(Bk ) is the number of legal moves available to the Black king.
M is a bonus term if the White king is supporting the queen effectively
which can be the manhattan distance between them for example.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 21 / 38
Endgame Tablebase Approximation
where:
d(n, edge) is the distance of the Black king from the nearest edge.
Mobility(Bk ) is the number of legal moves available to the Black king.
M is a bonus term if the White king is supporting the queen effectively
which can be the manhattan distance between them for example.
Heuristic Rationale:
Encourages restricting the Black king’s movement.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 21 / 38
Endgame Tablebase Approximation
where:
d(n, edge) is the distance of the Black king from the nearest edge.
Mobility(Bk ) is the number of legal moves available to the Black king.
M is a bonus term if the White king is supporting the queen effectively
which can be the manhattan distance between them for example.
Heuristic Rationale:
Encourages restricting the Black king’s movement.
Drives the Black king toward a checkmate-friendly position.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 21 / 38
Endgame Tablebase Approximation
where:
d(n, edge) is the distance of the Black king from the nearest edge.
Mobility(Bk ) is the number of legal moves available to the Black king.
M is a bonus term if the White king is supporting the queen effectively
which can be the manhattan distance between them for example.
Heuristic Rationale:
Encourages restricting the Black king’s movement.
Drives the Black king toward a checkmate-friendly position.
Optimizes coordination between White’s king and queen.
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 21 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 22 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 23 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 24 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 25 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 26 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 27 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 28 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 29 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 30 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 31 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 32 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 33 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 34 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 35 / 38
Endgame Tablebase Approximation
Black King
Queen
White King
Checkmate!
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 36 / 38
How else will solve a game?
Minimax Algorithm
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 37 / 38
How else will solve a game?
Minimax Algorithm
Alpha-Beta Pruning
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 37 / 38
How else will solve a game?
Minimax Algorithm
Alpha-Beta Pruning
Can we change the structure of graph?
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 37 / 38
How else will solve a game?
Minimax Algorithm
Alpha-Beta Pruning
Can we change the structure of graph?
Neural Networks
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 37 / 38
Thank You...
Dion Reji & Soham Dahane (IIT Bombay) Search inside Chess! February 18, 2025 38 / 38