Transcript Document
Computer Chess
Chess is the game most intensively studied thus far by the AI community.
• In 1965, it was called the Drosophila of Artificial Intelligence (by Russian
mathematician Alexander Kronrod)
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
1
Computer Chess
Chess is the game most intensively studied thus far by the AI community.
• In 1965, it was called the Drosophila of Artificial Intelligence (by Russian
mathematician Alexander Kronrod)
• In 1997, John McCarthy commented on this:
• “However computer chess has developed as genetics might have if the
geneticists had concentrated their efforts starting in 1910 on breeding
racing Drosophila. We would have some science, but mainly we would
have very fast fruit flies.”
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
2
Computer Chess
Chess is the game most intensively studied thus far by the AI community.
• In 1965, it was called the Drosophila of Artificial Intelligence (by Russian
mathematician Alexander Kronrod)
• In 1997, John McCarthy commented on this:
• “However computer chess has developed as genetics might have if the
geneticists had concentrated their efforts starting in 1910 on breeding
racing Drosophila. We would have some science, but mainly we would
have very fast fruit flies.”
• Anon said: “If you can’t beat your computer at chess, try kickboxing.”
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
3
Computer Chess
Chess is the game most intensively studied thus far by the AI community.
• In 1965, it was called the Drosophila of Artificial Intelligence (by Russian
mathematician Alexander Kronrod)
• In 1997, John McCarthy commented on this:
• “However computer chess has developed as genetics might have if the
geneticists had concentrated their efforts starting in 1910 on breeding
racing Drosophila. We would have some science, but mainly we would
have very fast fruit flies.”
• Anon said: “If you can’t beat your computer at chess, try kickboxing.”
• and “At times it seems that all what we have achieved in 40 years of computer
chess research is to drop the prediction time from ‘sometime in the next
decade’ to ‘in the next three years’.”
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
4
Highpoints of Computer Chess history
•1950:Claude Shannon writes Programming a Computer for Playing Chess, introduces
minimax, Type A (search based) and Type B (knowledge based) programs.
•1951:Alan Turing creates & hand-simulates a B program, it loses to a weak player.
• 1956, 1957: A- and B- Programs implemented on computers, getting better
•1958: Alpha-beta pruning introduced, it greatly reduces the work involved in tree search,
enabling deeper search.
•1967: MacHack-6 competes in 4 amateur chess tournaments, wins 3, draws 3, loses 12
•1973: Chess 4.0 wins computer tournament comfortably, others start switching to type A
•1977:Belle, with special-purpose hardware, beats a Grandmaster at speed chess.
•1988: Deep Thought defeats a Grandmaster in a tournament.
•1996: Deep Blue beats reigning champion Kasparov in the first game of a six-game
match, but loses the match.
•1997: Improved Deep Blue defeats Kasparov, though he did not play at his best.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
5
Shannon Types A, B
•Type A programs work by (or as if by) exploring all moves in a game tree to a
uniform depth.
•Type B programs explore a game tree to a non-uniform depth,
• doing selective move generation
• using chess knowledge
to determine promising lines of play to be explored further,
and to determine poor lines of play to be explored no further
(“Quiescence Search” complicates this simplistic picture, but it is not considered
to turn an A program into a B one)
Shannon believed Type B clearly superior, but (in chess anyhow) experience has
not borne this out.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
6
ELO Ratings for human players
800 - Beginner
1400 - Class D or C
1600 - Class C or B
1800 - Class B or A
2000 - Class A or Expert
2200 - Expert or National Master
2300 - National Master
2520 - International Master
2600 - Grandmaster
2700+ - Super Grandmaster
Each extra 100 points corresponds roughly to expecting to win two games out of
three: approx 20 such steps from beginner to champion.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
7
Gross Anatomy of a chess program
•User Interface - most probably a GUI but this is not strict requirement
•Representations
• For board positions (perhaps also, parts of board positions)
• For moves (whether played or merely imagined)
•Chess Engine
• Judge legality of user-input moves
• Effect board position changes in response to moves
• Allow retraction of moves (for user convenience, also for search)
• Means of selecting moves for computer player
Game-Tree Search: often alpha-beta with several refinements
Evaluation Function: often dominated by material gains/losses
Opening book
Endgame database
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
8
GUI example
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
9
Representations required
Board Positions:
•Board-Centric:
• Chess board has 64 squares, each may be empty or occupied by one of
twelve kinds of chessmen.
• Therefore one may use an 2-d 8x8 array (or 1-d 64-vector) of 4-bit values,
(or several bitboards to be described in a future lecture).
•Piece-Centric:
• A player has 16 men, each is either captured or on one of 64 squares.
• Therefore one may use a 1-d 16-vector of 7-bit values.
Moves:
•A chessman belonging to one player moves from one square to another.
•Therefore one may use a pair (FromSquare, ToSquare) of 6-bit numbers.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
10
Representations required
Board Positions:
•Board-Centric:
• Chess board has 64 squares, each may be empty or occupied by one of
twelve kinds of chessmen.
• Therefore one may use an 2-d 8x8 array (or 1-d 64-vector) of 4-bit values,
(or several bitboards to be described in a future lecture).
•Piece-Centric:
• A player has 16 men, each is either captured or on one of 64 squares.
• Therefore one may use a 1-d 16-vector of 7-bit values.
Moves:
•A chessman belonging to one player moves from one square to another.
•Therefore one may use a pair (FromSquare, ToSquare) of 6-bit numbers.
•But …
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
11
Requirements of representations
The rules of chess have two oddities that defy this simple representation of
moves (and piece-centric board representations too)
• Castling:
• Subject to certain provisos, a king K and a rook R may move simultaneously
Each K just once per game, neither it nor R has yet moved, K is not
moving out of check or through check, all spaces empty between K & R
• K may normally only move one square; in castling it moves two squares.
• Special logic could handle the implied R movement of a 2-square K move.
• Pawn Promotion:
• A pawn that reaches the 8th rank is replaced with another piece: Queen
Rook Bishop or Knight
• Piece-Centric board representation now needs to say what type of piece
• (FromSquare, ToSquare) pair needs extra WhatPieceNow element
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
12
Chess Engine element: The Rules
The rules of movement and capture need to be represented:
•Different pieces may move in different ways:
• Pawn: forward two empty squares from its starting position;
• Pawn: one empty square forward from any position;
• Bishop: diagonally any direction any number of empty squares;
• Rook: forward backward or sideways any number of empty squares;
• Queen: diagonally like bishop or to-or-fro-or-sideways like rook;
• Knight: one square forward or back plus two sideways, or vice versa
• King: to any of eight adjacent squares, or special castling move.
•All pieces except pawns may capture an opposing piece by finishing their
movement where it is. The opposing piece is removed.
• Pawns capture with a one-square forward-diagonal;
• There is an en-passant rule too. Read all about it!
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
13
Chess Engine element: Make Move and Retract Move
•User-input moves, and Computer-Generated responses, must have the correct
effect, and be reflected in the GUI.
•Interactive users should be given the opportunity to Undo a pair of moves.
• Therefore, Move Representation must include information on captures too,
so that a captured piece can be reinstated by Undo.
•The Make-Move and Retract-Move functionality is needed also, intensively,
while the computer player is searching the game tree
• Must therefore be fast
• Will not involve GUI
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
14
Chess Engine element: Game-Tree search
The full game tree for chess is so large that it is not feasible to search for the
winning move.
50
•Estimates of 1010 possible games, 1040 possible positions
•Typical game: each player has around 50 moves, around 38 choices each time
• 38100
Shannon Type A programs would use Minimax algorithm, to a fixed depth,
backing up values heuristically computed by an evaluation function.
The deeper the search, the better the play.
There are many refinements to the basic Minimax: Alpha-Beta, Progressive
Deepening, Transposition Tables, Quiescence Search, NegaScout, History
Heuristic, NullMove Heuristic, Aspiration Search, Killer Heuristic, Selective
Extensions, Conspiracy Number Search, and more! Also some algorithms instead
of minimax: B*, Proof Number Search.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
15
Chess Engine element: Evaluation Function
An evaluation function provides a number which indicates how good a position
is for one player.
• This is vague, but should not be treated as probability of a win.
• Evaluation function will be heavily used in search, so should be fast.
Evaluation functions for chess are typically dominated by material balance.
Typical values: Pawn 1; Bishop 3; Knight 3; Rook 5; Queen 9; King infinite.
Other features taken into account too:
•Control of the centre four squares
•Passed pawns
•Mobility, especially of the queens.
• The sum of possible value of all other features combined is typically
regarded as no more than 1.5 pawns
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
16
Chess Engine element: Opening book
It quickly proved too hard to select good opening moves using limited search and
an evaluation function.
•Centuries of human experience are codified in opening books which serious
players study.
•Chess programs use the knowledge in these publications,
• perhaps augmented by team members expert or better in chess,
• coded by programmers into a form their program can use.
•A common strategy of human players confronting computers is to make moves
out of the book - i.e. not found in the book - in the expectation that the computer
will not be able to find the responses which make the move sub-optimal.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
17
Chess Engine element: Endgame databases
An Endgame database is a tabulation of the possible positions in which only a
very small number of chessmen remain on the board. For each position, it
records the best move.
Examples are:
King and Pawn versus King (KPK)
King and Rook versus King (KRK)
King Rook and Pawn versus King and Rook (KRPKR)
Some endgame databases did exist, as books, before computer chess.
But Computer Chess has contributed enormously to the chess world’s knowledge
of several endgames, through exhaustive analysis of positions too numerous for
humans to tabulate. Championship contenders have been known to consult
computer-generated databases overnight during an adjourned game.
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
18
http://csiweb.ucd.ie/Staff/acater/comp4031.html
Artificial Intelligence for Games and Puzzles
19