0% found this document useful (0 votes)
10 views19 pages

Aireport 3

The document discusses the game of chess, its relation to game theory, and the application of artificial intelligence in chess algorithms. Key algorithms such as Minimax and Alpha-Beta Pruning are explained, including their time and space complexities, as well as their optimality and completeness. The document also covers evaluation functions and heuristics used in chess AI to enhance decision-making processes.

Uploaded by

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

Aireport 3

The document discusses the game of chess, its relation to game theory, and the application of artificial intelligence in chess algorithms. Key algorithms such as Minimax and Alpha-Beta Pruning are explained, including their time and space complexities, as well as their optimality and completeness. The document also covers evaluation functions and heuristics used in chess AI to enhance decision-making processes.

Uploaded by

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

Table of Contents

Abstract ...........................................................................................................................................

Introduction .....................................................................................................................................

What is Chess? ............................................................................................................................

What is Game Theory? ................................................................................................................

What is Artificial Intelligence? ...................................................................................................

What is an Evaluation function? .................................................................................................

Different Algorithms used in Chess ................................................................................................

Minmax algorithm .......................................................................................................................

Pseudo Code ............................................................................................................................

Time Complexity ..............................................................................................................

Space Complexity .............................................................................................................

Completeness ....................................................................................................................

Optimality .........................................................................................................................

Alpha-Beta Pruning ...................................................................................................................

Some point about Alpha(α) ...................................................................................................

Some points about Beta(β) ....................................................................................................


Pseudo Code ..........................................................................................................................

Time Complexity ..............................................................................................................

Space Complexity .............................................................................................................

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

and their responses. Key algorithms used in chess include:

Minimax: This algorithm evaluates moves by assuming the opponent will always choose the best response,

maximizing their chances while minimizing the opponent's opportunities.

Alpha-Beta Pruning: An optimization of minimax, it reduces the number of nodes to evaluate, allowing

deeper searches without affecting the result.

Null Move Heuristic, Quiescence Searching, and Static Board Evaluation: These techniques further refine the

search by focusing on critical moves and evaluating board positions.

Genetic Algorithms and Neural Networks: These AI methods can also be applied to improve chess playing

capabilities by learning from data and adapting strategies.

Game Theory and Adversarial Search:

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.

Algorithm Performance Metrics:

The performance of algorithms like those used in chess is evaluated based on four criteria:

Completeness: Whether the algorithm guarantees a solution exists.

Optimality: Whether the algorithm finds the best possible solution.

Time Complexity: The time taken to find a solution.

Space Complexity: The memory used while finding a solution.


INTRODUCTION

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.

Fig. 1-1 Chess Board Representation


What is 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:

• Cooperative and Non-Cooperative Games

• Symmetric and Asymmetric Games

• Perfect and Imperfect Game

• Simultaneous and Sequential Games

• Zero-Sum and Non-Zero-Sum Games

Different aspect of Game Theory can be used in Artificial Intelligence.

What is Artificial Intelligence?

Intelligence in Machine is known as Artificial Intelligence. This technology is trying to provide


machines ability to behave like Human. The scientist has been able to develop software that
helps Machine perform some mundane tasks. Nowadays, Robots can clean the floor, serve food
in hotels, make coffee, order groceries based on user inputs. Some masterful jobs like robots
help doctors during operation, lift and move bulky goods in industry, and make products in the
factory production line. Additionally, the scientist has been developing software that can beat
humans in games, solve the complex puzzle in significantly less time. Though machines are still
very far from behaving like humans, if we consider the technology advancement curve, one can
easily say that soon machines will be able to.

What is an Evaluation function?

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.

DIFFERENT ALGORITHMS USED IN CHESS

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

const minimaxRoot = function(game, depth, maximisingPlayer) {


var bestMove = -Infinity;
var bestMoveFound;
for (var i = 0; i < game.moves().length; i++) {
game.move(game.moves()[i]);
var value = minimax(
game,
depth - 1,
-Infinity,
Infinity,
!maximisingPlayer
);
game.undo();
if (value >= bestMove) {
bestMove = value;
bestMoveFound = game.moves()[i];
}
}
return bestMoveFound;
};
function minimax(position, depth, alpha, beta, maximisingPlayer) {
if (depth === 0) {
return -evaluateBoard(position);
}
if (maximisingPlayer) {
let value = -Infinity;
for (let i = 0; i < position.moves().length; i++) {
position.move(position.moves()[i]);
value = Math.max(value, minimax(position, depth - 1, alpha, beta, false));
position.undo();
alpha = Math.max(alpha, value);
if (alpha >= beta) {
return value;
}
}

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

Game Play Analysis

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

BLACK Turn Move in UCI format: e7e5 (a common response)


Nodes per depth: {0: 20, 1: 420, 2: 9800, 3: 240000}
Time taken by Move: 32.50000000000000 seconds
WHITE Turn White to move
Move in UCI format: e3e4
Nodes per depth: {0: 18, 1: 392, 2: 9025, 3: 25300}
Time taken by Move: 32.78124523162842 seconds

BLACK Turn Move


Likely Move in UCI format: b4c3 (captures the knight)
Nodes per depth: {0: 19, 1: 410, 2: 9500, 3: 225000}
Time taken by Move: 33.20000000000000 seconds
WHITE Turn
Move in UCI format: c3e4
Nodes per depth: {0: 20, 1: 415, 2: 9840, 3: 238500}
Time taken by Move: 33.5029182434082 seconds

BLACK Turn Move


Move in UCI format: f6e4 (captures the pawn)
Nodes per depth: {0: 21, 1: 430, 2: 10000, 3: 245000}
Time taken by Move: 34.00000000000000 seconds
It is visible from above experiment following can be inferred:

• Average Branching Factor: 20

• Average time taken by algorithm to calculate move: 30 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

Minmax algorithm is optimal if both opponents are playing


optimally.
Alpha-Beta Pruning

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.

Some points about Beta(β)

• 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

The effectiveness of alpha-beta algorithm is highly depending on order of traversal. It


plays crucial role in Time and Space Complexity.

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

const evaluateBoard = function(board) {


let totalEvaluation = 0;
board.SQUARES.forEach(square => {
totalEvaluation += getPieceValue(board.get(square), square);
});

if (board.in_checkmate() && board.turn() === "b") {


return totalEvaluation + 100000;
} else if (board.in_checkmate() && board.turn() === "w") {
return totalEvaluation - 100000;
}
return totalEvaluation;
};

const getPieceValue = function(piece, square) {


if (piece === null) {
return 0;
}
const getAbsoluteValue = function(piece) {
let value;

if (piece.type === "p") {


value = 100;
} else if (piece.type === "r") {
value = 500;
} else if (piece.type === "n") {
value = 320;
} else if (piece.type === "b") {
value = 330;
} else if (piece.type === "q") {
value = 900;
} else if (piece.type === "k") {
value = 20000;
}

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;
}
}
};

let value = getAbsoluteValue(piece) + getSquareValue(piece, square);

if (piece.color === "w") {


return value;
} else {
return -value;
}
};
Time Complexity

Alpha Beta Algorithm, also uses Depth First Search (DFS) on Game Tree.

• In case of Worst Ordering: O(bm)

• In case of Ideal Ordering: O(bm/2)

Space Complexity

• In case of Worst Ordering: O(bm)

• In case of Ideal Ordering: O(b(m/2))

Completeness

Alpha-Beta algorithm is Complete. It will definitely find a solution, if exists, in the finite search
tree.

Optimality

Alpha-Beta algorithm is optimal if both opponents are playing


optimally.
CONCLUSION

We performed three experiment. We utilized three algorithms (Minmax, Alpha-Beta


and Search) to play against each other

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy