Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations

Presentation on theme: "Programming a Computer for Playing Chess By Claude E. Shannon."— Presentation transcript:

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

2 Programming a Computer for Playing Chess Published in “Philosophical Magazine”, in Considered as an important milestone in computer chess programming

3 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

4 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*

5 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

6 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

7 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.dxc cxb7 Rb8 13.Ba6 Qa5 14.Qe2 Nd7 15.Rg1 Nc5 16.Rg5 Bg6 17.Bb5 Nxb 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.

8 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

9 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” ***

10 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.

11 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)

12 50-move drawing rule The F.I.D.E. Laws of Chess 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!

13 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.

14 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

15 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

16 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 NimNim 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

17 Evaluation function - f(P) It is possible, in principle, to play a perfect game. However…  In typical chess position there are 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.

18 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) =

19 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.

20 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



23 1

24 1-2

25 1-2 1

26 MinMax Complexity For branching factor b and depth search d the complexity is O(b d )

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

28 Alpha Beta Simple Example

29 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

30 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

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

32 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

33 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) moves deep

34 Human Strategies Studied experimentally by De Groot, 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.

35 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.

36 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

37 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)

38 Further Developments.. Opening Book Statistical variation – for position P, create some distribution and play by it Positional vs. Combination Player Endgame Solver Iterative Deepening

39 Recent Achivements

40 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, S. Russel, P. Norvig, Artificial Intelligence A Modern Approach, Prentice Hall, Lecture notes of Workshop in Reinforcement Learnning 2003/4 by Prof. Yishay Mansour, TAU ChessBase, A short history of computer chess,

Download ppt "Programming a Computer for Playing Chess By Claude E. Shannon."

Similar presentations

Ads by Google