Aireport 3
Aireport 3
Abstract ...........................................................................................................................................
Introduction .....................................................................................................................................
Completeness ....................................................................................................................
Optimality .........................................................................................................................
Completeness ....................................................................................................................
Optimality .........................................................................................................................
Conclusion ....................................................................................................................................
ABSTRACT
Chess is a strategic board game played between two players on an 8x8 matrix, requiring both strategy and tactics
to win. Computers can play chess using game theory, which involves mathematical modeling of player actions
Minimax: This algorithm evaluates moves by assuming the opponent will always choose the best response,
Alpha-Beta Pruning: An optimization of minimax, it reduces the number of nodes to evaluate, allowing
Null Move Heuristic, Quiescence Searching, and Static Board Evaluation: These techniques further refine the
Genetic Algorithms and Neural Networks: These AI methods can also be applied to improve chess playing
Game theory is a mathematical field that analyzes strategic decision-making in competitive situations.
Adversarial search is a key concept, where two players try to outmaneuver each other by planning ahead in the
same search space. This involves using a game tree, where each node represents a game state and edges
represent moves.
Heuristics:
Heuristics are shortcuts that help solve problems more quickly than traditional methods. In chess, they
approximate optimal solutions by evaluating information at each level and deciding which branch to explore
next.
The performance of algorithms like those used in chess is evaluated based on four criteria:
Chess in a quite old game and royal likely to came from Western world of India through
Persia in 6th AD Century. It is a symbol of Intelligence since very beginning.
Claude Shannon in 1950 published a first paper 'Programming a computer for playing
Chess'. It
was the first paper in its league. Then Alan Turing became the first person to develop a
program to play Chess, based on paper in 1951. Then many other joined this league Dietrich
Prinz in 1952, Paul Stein and Mark wells in 1956, John McCarthy in 1956. In 1966 first chess
match was played between computer programs. In 1988, Deep Thought shares a first place
in Software Toolworks Championship.
What is Chess?
Chess is a competitive and recreational board game played between two players. It is played
on 8 by 8 chess board using an abstract strategy. One player plays with black piece and
another player will play using white piece. There are total of 16 pieces with each player, and it
includes 8 pawns, 2 Rooks, 2 Knights, 2 bishops, 1 king and 1 Queen. Player will win the game,
if the opponent King is captured. Game can also end in draw state i.e., nobody wins. Game can
be played using various Game Theory Algorithm. Artificial Intelligence in a one of the
implementations of Game Theory.
Game theory is a branch of mathematics used to model the strategic interaction between
different rational agents in a context with predefined rules and outcome. It can be divided into
5 categories:
Evaluation functions are crucial piece in Algorithm. They are heuristic function that
determines relative value of position. It takes chess board state as an input and return the
estimate about who
is winning and by how much. To write evaluation function, we need to be aware of numeric
value of each pieces in board. Ideally, a bishop and knight are worth three pawn, a rook is
worth five pawn, and queen is worth nine pawn. These relations won't be applicable in real
game. We have to consider the piece position and other piece position.
In this paper we will analyze the different algorithm used in Chess. We will learn
mathematical modelling, steps involved, Time and Space Complexity analysis, Completeness
and Optimality of an algorithm.
Minmax algorithm
The core of Chess playing Chess in minmax. Minmax usually associates Black piece with MAX,
and white piece with MIN, and always evaluates from the white point of view.
The Minmax algorithm is an Adversarial Search algorithm in Game theory. It utilizes game tree
and includes two player MIN and MAX. Both players try to nullify the action of other. Max tries
to maximize the result whereas MIN tries to minimize the result. Both players play
alternatively,
under the assumption that both are playing optimally. Optimal play means both players are
playing as per rule i.e., MIN is minimizing the result and MAX is maximizing the result.
The minmax algorithm utilizes Depth First Search approach to find the result. Additionally, it
also utilizes backtracking and recursion. Algorithm will traverse till terminal node and then
it will backtrack while comparing all child values. It will select the minimum or maximum
value, based on whose turn it is. It will then propagate the value back to their parent.
It uses static evaluation function to determine the value at each leaf node. It takes the
advantage
of Zero-Sum Game.
Pseudo Code
return value;
} else {
let value = Infinity;
for (let i = 0; i < position.moves().length; i++) {
position.move(game.moves()[i]);
value = Math.min(value, minimax(position, depth - 1, alpha, beta, true));
position.undo();
beta = Math.min(beta, value);
if (alpha >= beta) {
return value;
}
}
return value;
}
}
Fig. 1-2 minmax implementation
In this section, we will allow two minmax algorithm to compete against each
other. We will calculate the total time taken by each move and number of nodes
explored per depth. We will only explore till depth = 3 because of system
restriction. We will allow 3 move each for Black and White piece.
WHITE Turn White to move
Move in UCI format: c3e4
Nodes per depth: {0: 21, 1: 441, 2: 10363, 3: 247970}
Time taken by Move: 34.17363452911377 seconds
Time Complexity
Minmax uses Depth First Search (DFS) on Game Tree, hence the time complexity of minmax
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 minmax algorithm is also similar to DFS which is O(bm), where b is
branching factor of the game-tree, and m is the maximum depth of the tree.
Completeness
Minmax algorithm is Complete. It will definitely find a solution, if exists, in the finite search
tree.
Optimality
The minmax algorithm can be optimized by pruning few branches. Pruned branches are the
ones that are not going to affect result. It will improve time-complexity. This version minmax
is knows as minmax with alpha-beta pruning. It is also called as alpha-beta algorithm.
In Alpha-Beta Pruning, there are two values, Alpha and Beta. Below are the few points
to
consider about alpha and beta:
Some point about Alpha(α)
• Alpha is the highest value, that is found along the MAX path.
• Initial value of alpha is negative infinity because alpha value will keep on increasing or
remain same with every move. If we choose some value other than negative infinity,
then
the scenario may occur in which all values of alpha may be less than chosen value. So,
we have to choose lowest possible value, and that is negative infinity.
• Alpha is only updated by MAX player.
• Beta is the lowest value, that is found along the MIN path.
• Initial value of beta is positive infinity because beta value will keep on decreasing or
remain same with every move. If we choose some value other than positive infinity,
then
scenario may occur in which all values of beta may be more than chosen value. So, we
have to choose maximum possible value, and that is positive infinity.
• Beta value is only updated by MIN player.
While backtracking only node value is passed to parent, not the alpha and beta
The Condition for alpha-beta pruning:
value.
α >= β
Move Ordering
Worst Ordering
In some cases, no node or sub-tree is pruned out of Game Tree. In this case, best move occurs
in right sub-tree of Game Tree. This will result in increased Time Complexity.
Ideal Ordering
In this case, maximum number of node and sub-tree is pruned. Best moves occur in left
subtree. It will reduce the Time and Space Complexity.
Pseudo Code
return value;
};
const getSquareValue = function(piece, square) {
if (piece.color === "w") {
if (piece.type === "p") {
let val = pawnSquareTable.find(obj => obj.square.name === square);
return val.wValue;
} else if (piece.type === "r") {
let val = rookSquareTable.find(obj => obj.square.name === square);
return val.wValue;
} else if (piece.type === "n") {
let val = knightSquareTable.find(obj => obj.square.name === square);
return val.wValue;
} else if (piece.type === "b") {
let val = bishopSquareTable.find(obj => obj.square.name === square);
return val.wValue;
} else if (piece.type === "q") {
let val = queenSquareTable.find(obj => obj.square.name === square);
return val.wValue;
} else if (piece.type === "k") {
let val = kingSquareTable.find(obj => obj.square.name === square);
return val.wValue;
}
} else {
if (piece.type === "p") {
let val = pawnSquareTable.find(obj => obj.square.name === square);
return val.bValue;
} else if (piece.type === "r") {
let val = rookSquareTable.find(obj => obj.square.name === square);
return val.bValue;
}
alpha-beta
else if (piece.type === "n") {
let val = knightSquareTable.find(obj => obj.square.name === square);
return val.bValue;
} else if (piece.type === "b") {
let val = bishopSquareTable.find(obj => obj.square.name === square);
return val.bValue;
} else if (piece.type === "q") {
let val = queenSquareTable.find(obj => obj.square.name === square);
return val.bValue;
} else if (piece.type === "k") {
let val = kingSquareTable.find(obj => obj.square.name === square);
return val.bValue;
}
}
};
Alpha Beta Algorithm, also uses Depth First Search (DFS) on Game Tree.
Space Complexity
Completeness
Alpha-Beta algorithm is Complete. It will definitely find a solution, if exists, in the finite search
tree.
Optimality
Below are the few conclusions that can be drawn from experiments:
• Nodes explored per move is reduced by 10 folds in Alpha Beta as compared with
Minmax.
• Time Taken to find best move is also reduced by 10 folds in Alpha Beta as compared
with Minmax.