Introduction to Machine Learning Unit-3 for II MECH
Chess engine presentation
1.
2. Guided By
Dr Nishant Shrivastava
Head of Department
Presented By
Tanushree Sharma
(8818103001)
Amit Verma
(8818103004)
3. CONTENT
3
Objective
Scope
Building Blocks of Chess Engine
Introduction
Flow Charts
Tools and Techniques
Home Page
Board Representation
Move Generation Implementation
AI Algorithms
Integration of AI Algorithms
Future Enhancement
4. The objective is to checkmate the
opponent’s king by placing it under an
unavoidable threat of capture.
4
5. The scope of our project is
limited for two players to play
chess as real in computer.
And a player also able to play
with computer according to the
intelligence we gave it.
5
6. Building Blocks of Chess
Chess
Board
Possible
Moves
Move
Choose
Animate
Move
Update
7. 7
Chess is a game played between two
opponents on opposite sides of a
board containing 64 squares of
alternating colors.
Each player has 16 pieces: 2 rooks, 1
king, 1 queen, 2 bishops, 2 knights
and 8 pawns.
8. Tools & Techniques
8
Python 3 It is a General-purpose dynamic programming language
which provides the high-level readability and it is interpreted. In our
project we use python for calculate the players's move.
Pygame Pygame is a Python framework for game programming. We
use pygame in our project for creating, updating and handling GUI.
10. 10
Start User's Move
Move is
Legal
Move Generator
Move Evaluation
Best Move
Stale/Chec
k mate
End
Playing Steps (AI)
True
End
True
False
Stale/Chec
k mate
True
Fals
e
False
13. Move Generation
13
After representation of board we shift to the move
generator. Each piece in chess has its own list of
moves, therefore for each piece is necessary to
write a specific function to generate the moves.
Here are snapshots of chess piece's move
from are code.
20. we should introduce two things to computer for making the
game Intelligent which will make the game to do optimal
moves
A technique to choose the move to make amongest all legal
possibilities, so that it can choose a move instead of being
forced to pick one at random.
A way to compare moves and positions, so that it makes
intelligent choices. 20
22. Mini-Max Algorithm
22
The Mini-max algorithm is a way to find an optimal move in a two player game.
Mini-max algorithm is a recursive or backtracking algorithm which is used in decision-
making and game theory. It provides an optimal move for the player assuming that
opponent is also playing optimally.
The minimax algorithm performs a depth-first search algorithm for the exploration of the
complete game tree.
The minimax algorithm proceeds all the way down to the terminal node of the tree, then
backtrack the tree as the recursion
23. Properties of Mini-Max algorithm:
23
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).
24. Working of Mini-max
24
Minimax: Assume that both White and Black plays
the best moves. We maximizes White’s score
Perform a depth-first search and evaluate the leaf
nodes
Choose child node with highest value if it is White to
move
Choose child node with lowest value if it is Black to
move
Branching factor is 40 in a typical chess position
26. Pseudocode
26
function minimax(node, depth, maximizingPlayer) is
if depth = 0 or node is a terminal node then
return the heuristic value of node
if maximizingPlayer then
value := −∞
for each child of node do
value := max(value, minimax(child, depth − 1, FALSE))
return value
else (* minimizing player *)
value := +∞
for each child of node do
value := min(value, minimax(child, depth − 1, TRUE))
return value
27. Pruning Techniques
27
The complexity of
mini-max algorithm
for d ply ahead is
O(b*b*…*b)
= O(b^d).
With a branching
factor (b) of 40 it is
crucial to be able to
prune the search
tree.
28. Alpha-Beta Pruning
28
Alpha-Beta Pruning is a way of finding the minimum solution.
Alpha-beta pruning is a modified version of the minimax algorithm. It is an optimization technique for the minimax 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.
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 +∞.
29. Alpha-Beta Pruning
29
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.
If Beta is less than Alpha, then the position will never occur assuming best play
If search tree is evaluated left to right, then we can skip the greyed- out sub trees
31. Pseudocode
31
function alphabeta(node, depth, α, β, maximizingPlayer) is
if depth = 0 or node is a terminal node then
return the heuristic value of node
if maximizingPlayer then
value := −∞
for each child of node do
value := max(value, alphabeta(child, depth − 1, α, β, FALSE))
α := max(α, value)
if α ≥ β then
break (* β cutoff *)
return value
else
value := +∞
for each child of node do
value := min(value, alphabeta(child, depth − 1, α, β, TRUE))
β := min(β, value)
if β ≤ α then
break (* α cutoff *)
return value