22
Chess and AI Chess and AI Group Members Group Members Abhishek Sugandhi 04305016 Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Sanjeet Khaitan 04305018 Gautam Solanki 04305027 Gautam Solanki 04305027

Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Embed Size (px)

Citation preview

Page 1: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Chess and AIChess and AI

Group MembersGroup MembersAbhishek Sugandhi 04305016Abhishek Sugandhi 04305016

Sanjeet Khaitan 04305018Sanjeet Khaitan 04305018

Gautam Solanki 04305027Gautam Solanki 04305027

Page 2: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

What We Need

Some way to represent a chess board in memory.

A technique to choose the move to make amongst all legal possibilities.

A way to compare moves and positions, so that it makes intelligent choices.

Page 3: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Board Representation:Board Representation:

Memory was at much more of a premium Memory was at much more of a premium several decades ago than it is today.several decades ago than it is today.

So early chess programs laid a strong So early chess programs laid a strong foundation for efficient and compact data foundation for efficient and compact data structures.structures.

The most obvious board representation is a The most obvious board representation is a 64 byte array, with one byte representing 64 byte array, with one byte representing one of the 64 squares on the board.one of the 64 squares on the board.

Page 4: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Bit Boards: Bit Boards:

An enhancement to board representation that is An enhancement to board representation that is still prevalent today is the bit board.still prevalent today is the bit board. This is a 64 bit word that holds a binary This is a 64 bit word that holds a binary value for each square value for each square Greatly reduces computation time for the Greatly reduces computation time for the program. program. For example KnightMoves[c2] can be represented For example KnightMoves[c2] can be represented asas 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 11 00 00 00 00 11 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 11 00 00 00

Page 5: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

BitBoards contd.BitBoards contd.

Simialrly WhitePieces can beSimialrly WhitePieces can be 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 11 00 00 00 00 11 00 00 00 11 11 00 11 00 00 00 00 00 00 00 00 00 00 00 00 11 11 00 00

This gives all the positions where This gives all the positions where there are white pieces on the board.there are white pieces on the board.So an AND operation of KightMoves[c2] So an AND operation of KightMoves[c2] and NOT of Whitepieces will give us and NOT of Whitepieces will give us all the White Knight moves from c2.all the White Knight moves from c2.

Page 6: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Searching:Searching:

The most basic search algorithm is The most basic search algorithm is minimax. minimax.

This can be enhanced by alpha beta This can be enhanced by alpha beta pruning, especially when combined with pruning, especially when combined with iterative deepening. iterative deepening.

Page 7: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

MinimaxMinimax

Computer selects move with maximum Computer selects move with maximum benefit and assumes that the opponent will benefit and assumes that the opponent will take move with minimum losstake move with minimum loss

Page 8: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Alpha-Beta PruningAlpha-Beta Pruning

The problem with minimax is that we expand The problem with minimax is that we expand every node down to a certain depth even every node down to a certain depth even though, in certain cases we are wasting our though, in certain cases we are wasting our time. time. To combat this a procedures known as To combat this a procedures known as alpha/beta (it is called this for alpha/beta (it is called this for historical reasons) pruning has been historical reasons) pruning has been developed.developed.

Page 9: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Iterative DeepeningIterative Deepening

In many occasion there is a time limit in which the computer should decide a the move.The idea behind iterative deepening is : begin by searching all moves arising from the position to depth 2, search again to depth 3, and then depth 4 and so on, until you have reached the appropriate depth or the time limit is over.Even if the time limit is over before the appropriate depth is reached we still have some good estimate of a move.

Page 10: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Transposition TableTransposition TableThis is equivalent to a hash table that This is equivalent to a hash table that holds board positions that have already been holds board positions that have already been analyzed in the past to save the work analyzed in the past to save the work already done by the engine. already done by the engine. An “opening book”, which is a database of An “opening book”, which is a database of solid opening moves, is almost always solid opening moves, is almost always included in the transposition table.included in the transposition table.The transposition table also helps out a lot The transposition table also helps out a lot in the end game, where with most pieces off in the end game, where with most pieces off the board, the move tree will generate many the board, the move tree will generate many identical positions through different move identical positions through different move lists. lists. While nearly every modern chess program has While nearly every modern chess program has a transposition table, the one disadvantage a transposition table, the one disadvantage is that it takes up a huge amount of memory. is that it takes up a huge amount of memory. Despite this, the transposition table shows Despite this, the transposition table shows how a little pre-processing can simplify how a little pre-processing can simplify computations during the actual game. computations during the actual game.

Page 11: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Horizon Effect:Horizon Effect:

A problem with these simple algorithms is A problem with these simple algorithms is that the chess program can only scan to a that the chess program can only scan to a certain depth. certain depth. For example, if capturing the opponent’s For example, if capturing the opponent’s queen on ply 7 results in getting queen on ply 7 results in getting checkmated on ply 8, and the program only checkmated on ply 8, and the program only searches 7 plies deep, it will think the searches 7 plies deep, it will think the queen capture is a great move. This is queen capture is a great move. This is known as the “horizon effect”.known as the “horizon effect”.

Page 12: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Quiescence Search:Quiescence Search:

This can be used to avoid Horizon effect.This can be used to avoid Horizon effect.

The whole search process is cotinued The whole search process is cotinued until a “quiet position” is reached. until a “quiet position” is reached.

A “quiet position” is a position where the A “quiet position” is a position where the computer is not captured by any piece of computer is not captured by any piece of the opponent by any further move.the opponent by any further move.

Page 13: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Aspirated Search:Aspirated Search:

This is used to reduce the search time by This is used to reduce the search time by cutting off more nodes.cutting off more nodes.In Alpha-Beta Pruning we take -INFINITY and In Alpha-Beta Pruning we take -INFINITY and +INFINITY as initial value of Alpha and Beta +INFINITY as initial value of Alpha and Beta resp.resp.The idea behind Aspirated Search is to reduce The idea behind Aspirated Search is to reduce the window size of -INFINITY to +INFINITY, to a the window size of -INFINITY to +INFINITY, to a smaller window.smaller window.This technique can be effectively used with This technique can be effectively used with Iterative Deepening.Iterative Deepening.Once we have searched for 2-ply, we get an Once we have searched for 2-ply, we get an approximate value for the result of 3ply search. approximate value for the result of 3ply search. Let the result is A. so when initiating 3 ply Let the result is A. so when initiating 3 ply search we can give alpha and beta values as A-search we can give alpha and beta values as A-Constant and A+Constant resp. Constant and A+Constant resp. This will reduce the search time.This will reduce the search time.

Page 14: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Singular Extensions:Singular Extensions:

Another way to combat the horizon effect Another way to combat the horizon effect and also improve accuracy is to add and also improve accuracy is to add another several ply when a particularly another several ply when a particularly promising move is discovered during promising move is discovered during search. search. This can quickly determine whether the This can quickly determine whether the move’s high valuation is legitimate. move’s high valuation is legitimate. Searching through extra plies like this Searching through extra plies like this can be an expensive operation and was one can be an expensive operation and was one of the main features of IBM’s Deep Blue. of the main features of IBM’s Deep Blue.

Page 15: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Position EvaluationPosition Evaluation

Static evaluation of a board position Static evaluation of a board position depends on several factors. depends on several factors. The most important is Material Balance The most important is Material Balance (Pieces on chess-board).(Pieces on chess-board).Mobility is another factor on which Mobility is another factor on which Position Evaluation dependsPosition Evaluation dependsBoard-Control is another measurable Board-Control is another measurable feature of a positionfeature of a position

Page 16: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Position Evaluation Position Evaluation (Continued):(Continued):

●Material balance is an account of which Material balance is an account of which pieces are on the board for each side. pieces are on the board for each side. ●According to chess literature, a queen may According to chess literature, a queen may be worth 900 points, a rook 500, a bishop be worth 900 points, a rook 500, a bishop 325, a knight 300 and a pawn 100; the king 325, a knight 300 and a pawn 100; the king has infinite value.has infinite value.● Computing material balance is therefore a Computing material balance is therefore a simple matter: a side's material value is simple matter: a side's material value is equal toequal toMB = Sum( Np * Vp )MB = Sum( Np * Vp )

Np is the number of pieces of a Np is the number of pieces of a certain type on the board certain type on the board Vp is that piece's value. Vp is that piece's value.

●If you have more material on the board than If you have more material on the board than your opponent, you are in good shape. your opponent, you are in good shape.

Page 17: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

MobilityMobility

It can be defined by the number of It can be defined by the number of legal moves a player has.legal moves a player has.A player having more mobility is A player having more mobility is considered to be in better shape.considered to be in better shape.

Page 18: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Board ControlBoard Control

Board-Control is another measurable Board-Control is another measurable feature of a position. feature of a position.

It can be defined by whether or not It can be defined by whether or not the king is protected (i.e. by the king is protected (i.e. by castling)castling)how many rooks are on open fileshow many rooks are on open fileshow many central squares on the board how many central squares on the board are being occupied and attacked. are being occupied and attacked. Doubled and tripled pawns (two or Doubled and tripled pawns (two or three pawns in the same file via a three pawns in the same file via a capture) are known to be weak capture) are known to be weak positions positions Isolated pawns (a pawn which doesn’t Isolated pawns (a pawn which doesn’t have another pawn in either of it’s have another pawn in either of it’s bordering files) also denote weak bordering files) also denote weak positions. positions.

Page 19: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Linear Evaluation FunctionsLinear Evaluation FunctionsA linear function of f1, f2, f3 is a A linear function of f1, f2, f3 is a weighted sum of f1, f2, f3....weighted sum of f1, f2, f3....A linear evaluation function isA linear evaluation function is

= w1.f1 + w2.f2 + w3.f3 + ..... wn.fn= w1.f1 + w2.f2 + w3.f3 + ..... wn.fnwhere f1, f2, f3, are the features like board where f1, f2, f3, are the features like board control, mobility etc.control, mobility etc.and w1, w2, w3, are the weightsand w1, w2, w3, are the weightsIdea:Idea:

– more important features get more weightmore important features get more weight

The quality of play will depend directly The quality of play will depend directly on the quality of the evaluation functionon the quality of the evaluation function

to build an evaluation function we have toto build an evaluation function we have to– 1. construct good features (using expert knowledge, 1. construct good features (using expert knowledge,

heuristics)heuristics)– 2. pick good weights (can be learned)2. pick good weights (can be learned)

Page 20: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

ConclusionConclusion

Chess and game tree AI have come a long way Chess and game tree AI have come a long way since when they first began. The best evidence since when they first began. The best evidence of is that the greatest chess player in the world, of is that the greatest chess player in the world, Garry Kasparov, was defeated by a machine that Garry Kasparov, was defeated by a machine that used principles based primarily upon many of the used principles based primarily upon many of the topics discussed in previous slides. topics discussed in previous slides. As computer architecture improves coupled with As computer architecture improves coupled with stronger, more efficient evolving algorithms, we stronger, more efficient evolving algorithms, we can only expect this classical type of brute force, can only expect this classical type of brute force, heuristic AI to become even stronger.heuristic AI to become even stronger.

Page 21: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

ReferencesReferences

•http://www.chessbrain.net/beowulf/theory.html http://www.chessbrain.net/beowulf/theory.html

•http://www.xs4all.nl/~verhelst/chess/search.html http://www.xs4all.nl/~verhelst/chess/search.html •http://www.maths.nott.ac.uk/personal/anw/G13GT1/http://www.maths.nott.ac.uk/personal/anw/G13GT1/compch.html compch.html •http://www.gamedev.net/reference/articles/ http://www.gamedev.net/reference/articles/

Page 22: Chess and AI Group Members Abhishek Sugandhi 04305016 Sanjeet Khaitan 04305018 Gautam Solanki 04305027

Project ProposalProject Proposal

We will create a One Player Chess Program We will create a One Player Chess Program using Iterative deepening Technique.using Iterative deepening Technique.