Top Banner
Programming a Computer for Playing Chess By Claude E. Shannon
40

Programming a Computer for Playing Chess By Claude E. Shannon.

Dec 16, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming a Computer for Playing Chess By Claude E. Shannon.

Programming a Computer for Playing Chess

By Claude E. Shannon

Page 2: Programming a Computer for Playing Chess By Claude E. Shannon.

Programming a Computer for Playing Chess

Published in “Philosophical Magazine”, in 1950.

Considered as an important milestone in computer chess programming

Page 3: Programming a Computer for Playing Chess By Claude E. Shannon.

About the paper

• Written while Shannon was working in Bell Telephone Laboratories

• One of Shannon famous “hobbies” as well as cycling and juggling

• Surveys the problem of constructing a computer routine for a modern computer that will play chess

Page 4: Programming a Computer for Playing Chess By Claude E. Shannon.

First chess “machine”…

First machine built in 1769 Constructed by the

Hungarian engineer von Kempelen for queen Maria Theresia.

Had outstanding playing strength

Mechanical device supplied by a human chess master hidden inside.

It was a *FAKE*

Page 5: Programming a Computer for Playing Chess By Claude E. Shannon.

El Ajedrecista (chess player)- Playing a Rook-King Endgame

Invented in 1914 by Leonardo Torres y Quevedo

Played rook and king against a king Machine forced checkmate no matter

however its opponent played Explicit set of rules - relatively simple

idea

Page 6: Programming a Computer for Playing Chess By Claude E. Shannon.

Turing’s “paper machine”

Was written soon after WWII Instruction that would enable a machine to

play chess no machines that could execute the

instructions... Turing acts as a human CPU More than ½ hour per move ! However…looses to one of his colleagues

Page 7: Programming a Computer for Playing Chess By Claude E. Shannon.

Turing’s “paper machine”

Here's the historic game: Turing's paper machine – Alick Glennie, Manchester 1952

: 1.e4 e5 2.Nc3 Nf6 3.d4 Bb4 4.Nf3 d6 5.Bd2 Nc6 6.d5 Nd4 7.h4 Bg4 8.a4 Nxf3+ 9.gxf3 Bh5 10.Bb5+ c6 11.dxc6 0-0 12.cxb7 Rb8 13.Ba6 Qa5 14.Qe2 Nd7 15.Rg1 Nc5 16.Rg5 Bg6 17.Bb5 Nxb7 18.0-0-0 Nc5 19.Bc6 Rfc8 20.Bd5 Bxc3 21.Bxc3 Qxa4 22.Kd2? [22.h5 would have trapped the bishop] 22...Ne6 23.Rg4 Nd4? [23...Rxb2! 24.Bxb2 Rxc2+] 24.Qd3 Nb5 25.Bb3 Qa6 26.Bc4 Bh5 27.Rg3 Qa4 28.Bxb5 Qxb5 29.Qxd6 Rd8 0-1.

Page 8: Programming a Computer for Playing Chess By Claude E. Shannon.

First win for a computer

MANIAC I was delivered in 1950 for developing atomic weapons

Before calculating detonation parameters, was tested with a limited chess program

Simplified 6x6 board without bishops Twelve minutes to search up to four ply (2 moves) In Los Alamos, 1956 it wins in 23 moves against a

young lady who learnt the game a week before the game.

First win of a machine against a human player

Page 9: Programming a Computer for Playing Chess By Claude E. Shannon.

Why Chess?

Sharply defined problem both in operations (moves) and ultimate goal (checkmate)

Neither trivial nor too difficult for satisfactory solution

Its discrete structure fits well modern computers

*** Chess is generally considered to require “thinking” for a skilful play. A solution to this problem will force us to admit that machine thinks, or further restrict the concept of “thinking”

***

Page 10: Programming a Computer for Playing Chess By Claude E. Shannon.

Definition of a “Chess Position”

1. A statement of the positions of all pieces on the board.

2. A statement of which side, White or Black, has the move.

3. A statement as to whether the king and rooks have moved.

4. A statement of, say, the last move. This will determine whether a possible en passant capture is legal

5. A statement of the number of moves made since the last pawn move or capture.

Page 11: Programming a Computer for Playing Chess By Claude E. Shannon.

Game Types

Games can be deterministic or non-deterministic “probabilistic”, “stochastic”

…and have perfect information or not “Accessible” – The world state is fully accessible to the

program or agent (nothing hidden)

Page 12: Programming a Computer for Playing Chess By Claude E. Shannon.

50-move drawing rule

The F.I.D.E. Laws of Chess 10.12

the game is drawn when a player having the move claims a draw and demonstrates that at least [the last?] 50 consecutive moves have been made by each side without the capture of any piece and without the movement of any pawn. This number of 50 moves can be increased for certain positions, provided that this increase in number and these positions have been clearly announced by the organisers before the event starts.

The most extreme case yet known of a position which might take more than 50 moves to win is king, rook and bishop against king and two knights, which can run for 223 moves between captures!

Page 13: Programming a Computer for Playing Chess By Claude E. Shannon.

Von Neumann and Morgenstern, 1944 In chess there is no element of chance, and since each

opponent has “prefect information” at each move:

For any given position, either:

A won position for White. That is, White can force a win, however Black defends.

A draw position. White can force at least a draw, however Black plays, and likewise Black can force at least a draw, however White plays. If both sides play correctly the game will end in a draw.

A won position for Black. Black can force a win, however White plays.

Page 14: Programming a Computer for Playing Chess By Claude E. Shannon.

Von Neumann and Morgenstern, 1944

Nature of existence theorem No practical method is known to

determine which of the three is correct If would be determined, probably

would lose interest in chess

Page 15: Programming a Computer for Playing Chess By Claude E. Shannon.

Altering the rules… A slight change of the rules, guarantees at least a

draw for white. Suggested change: A player may choose to “pass”.

Proof:

If white has a winning move – make it.

Otherwise – choose to “pass”.

By the symmetry Black is faced with the same position white just had…

Since white had no winning move before, Black has none now.

Hence, black at best can draw

Page 16: Programming a Computer for Playing Chess By Claude E. Shannon.

Evaluation function - f(P)

Sometimes a simple evaluation function can be applied to any position P to determine whether it is a won/lost/drawn position

Example: The game of Nim If number of ones in each column binary

representation) is even, the player about to move looses

f(P) =

+1, won position

0, drawn position

-1, lost position

Page 17: Programming a Computer for Playing Chess By Claude E. Shannon.

Evaluation function - f(P)

It is possible, in principle, to play a perfect game. However…

In typical chess position there are 30-40 legal moves. One move for white, and one for black yields 10^3

possibilities Typical game lasts ~40 moves to resignation of one

party Need to check 10^120 variations… infeasible…

It is easy to play a trivial game – not interesting.

Page 18: Programming a Computer for Playing Chess By Claude E. Shannon.

Approximating Evaluation Functions

The relative values of queen, rook, bishop, knight and pawn are about 9, 5, 3, 3,1, respectively.

Mobility - Rooks should be placed on open files. Backward, isolated and doubled pawns are weak. An exposed king is a weakness (until the end

game).

200(K-K') + 9(Q-Q') + 5(R-R') + 3(B-B'+N-N') + (P-P') - 0.5(D-D'+S-S'+I-I') + 0.1(M-M') + ...

f(P) =

Page 19: Programming a Computer for Playing Chess By Claude E. Shannon.

Two Players Games

One Search Tree for both Players Even layers – Max Player move Odd Layers – Min Player move

The state evaluated according to evaluation function.

Page 20: Programming a Computer for Playing Chess By Claude E. Shannon.

MinMax search strategy

Generate the whole game tree. (Or up to a constant depth)

Evaluate Terminal states (Leafs) propagate Min-Max values up from

leafs Search for MAX best next move, so that

no matter what MIN does MAX will be better off

Page 21: Programming a Computer for Playing Chess By Claude E. Shannon.
Page 22: Programming a Computer for Playing Chess By Claude E. Shannon.

-1

Page 23: Programming a Computer for Playing Chess By Claude E. Shannon.

-1 1

Page 24: Programming a Computer for Playing Chess By Claude E. Shannon.

-1 1 -2

Page 25: Programming a Computer for Playing Chess By Claude E. Shannon.

-1 1 -2

1

Page 26: Programming a Computer for Playing Chess By Claude E. Shannon.

MinMax Complexity

For branching factor b and depth search d the complexity is O(bd)

Page 27: Programming a Computer for Playing Chess By Claude E. Shannon.

Cuting Off Search

We want to prune the tree: stop exploring subtrees with values that will not influence the final MinMax root decision

Page 28: Programming a Computer for Playing Chess By Claude E. Shannon.

Alpha Beta Simple Example

Page 29: Programming a Computer for Playing Chess By Claude E. Shannon.

Alpha-Beta search cutoff rules

Keep track and update two values so far: alpha is the value of best choice in the MAX

path beta is the value of best choice in the MIN

path Rule: do not expand node n when

beta <= alpha for MAX node return beta for MIN node return alpha

Page 30: Programming a Computer for Playing Chess By Claude E. Shannon.

Alpha-Beta Prunning

function Max-Value(state,game,alpha,beta) returns minmax value of state if Cutoff-Test(state) then return Eval(state) for each s in Successor(state) do alpha := Max(alpha,Min-Value(s, game,alpha,beta) if beta <= alpha then return beta end; return alpha

function Min-Value(state,game,alpha,beta) returns minmax value of state if Cutoff-Test(state) then return Eval(state) for each s in Successor(state) do beta := Min(beta,Max-Value(s, game,alpha,beta) if beta <= alpha then return alpha end; return beta

Page 31: Programming a Computer for Playing Chess By Claude E. Shannon.

Complexity

In the worst case, no cut-off. The complexity is O(bd). In practice, O(bd/2), with branching factor of b1/2 instead of b.

Page 32: Programming a Computer for Playing Chess By Claude E. Shannon.

Type A Strategy

Consider all positions down the min-Max, up to a fixed depth d.

For each position in depth d, use some evaluation function to estimate the position

Possible to implement using only 3000 bits !

Simple and ineffective

Page 33: Programming a Computer for Playing Chess By Claude E. Shannon.

Type A Strategy - Backdraws

Type A Strategy is Slow & Weak ~10^9 evaluations needed after 3 moves

(6 plies) Evaluates positions at unreliable states Rather limited ‘thinking’ World champion can construct (at best)

15-20 moves deep

Page 34: Programming a Computer for Playing Chess By Claude E. Shannon.

Human Strategies

Studied experimentally by De Groot, 1946. showed various typical positions to chess

masters In certain case the chess master examined

sixteen variations, ranging in depth from 1/2 (one Black move) to 4-1/2 (five Black and four White) moves.

The total number of positions considered was 44.

Page 35: Programming a Computer for Playing Chess By Claude E. Shannon.

Type B Strategy

Examine forceful variations out as far as possible and evaluate only at reasonable positions, where some quasi-stability (quiescence) has been established.

Select the variations to be explored by some process so that the machine does not waste its time in totally pointless variations.

Page 36: Programming a Computer for Playing Chess By Claude E. Shannon.

Quiescence Positions

Define a function g(P) of a position which determines whether approximate stability exists:

g(P) = 1 ,

g(P) = 0 , Otherwise.

Variations can be explored until g(P)=0 Making sure we check at least 2 moves and at most 10 moves

any piece is attacked by a piece of lower value or by more pieces than defenses, or any check exists on a square controlled by the opponent

Page 37: Programming a Computer for Playing Chess By Claude E. Shannon.

h(P,M) – Is this move essential?

For position P, and move M – evalutate decide whether it is worth exploring:

High value: Check Captures Attack on major pieces

Medium value: Developing moves Defensive moves

Low value - other moves

should NOT eliminate moves that merely look bad at first sight (piece en prise)

Page 38: Programming a Computer for Playing Chess By Claude E. Shannon.

Further Developments..

Opening Book Statistical variation – for position P,

create some distribution and play by it Positional vs. Combination Player Endgame Solver Iterative Deepening

Page 39: Programming a Computer for Playing Chess By Claude E. Shannon.

Recent Achivements

Page 40: Programming a Computer for Playing Chess By Claude E. Shannon.

References

Claude E. Shannon , Programming a Computer Playing Chess, Philosophical Magazine, Ser. 7, Vol 41, No. 312 – March 1950

The F.I.D.E. Laws of Chess, http://www.chessvariants.com/fidelaws.html S. Russel, P. Norvig, Artificial Intelligence A Modern Approach, Prentice

Hall, 1995. Lecture notes of Workshop in Reinforcement Learnning 2003/4 by Prof.

Yishay Mansour, TAU ChessBase, A short history of computer chess,

http://www.chessbase.com/columns/column.asp?pid=102