programming a computer for playing chess l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Programming a Computer for Playing Chess PowerPoint Presentation
Download Presentation
Programming a Computer for Playing Chess

Loading in 2 Seconds...

play fullscreen
1 / 40

Programming a Computer for Playing Chess - PowerPoint PPT Presentation


  • 226 Views
  • Uploaded on

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 About the paper

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Programming a Computer for Playing Chess' - issac


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
programming a computer for playing chess2
Programming a Computer for Playing Chess
  • Published in “Philosophical Magazine”, in 1950.
  • Considered as an important milestone in computer chess programming
about the paper
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
first chess machine
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*
el ajedrecista chess player playing a rook king endgame
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
turing s paper machine
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
turing s paper machine7
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.
first win for a computer
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
why chess
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”

***

definition of a chess position
Definition of a “Chess Position”
  • A statement of the positions of all pieces on the board.
  • A statement of which side, White or Black, has the move.
  • A statement as to whether the king and rooks have moved.
  • A statement of, say, the last move. This will determine whether a possible en passant capture is legal
  • A statement of the number of moves made since the last pawn move or capture.
game types
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)

50 move drawing rule
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!
von neumann and morgenstern 1944
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.
  • Adraw 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.
von neumann and morgenstern 194414
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
altering the rules
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

evaluation function f p

+1, won position

0, drawn position

-1, lost position

f(P) =

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
evaluation function f p17
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.
approximating evaluation functions
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) =

two players games
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.
minmax search strategy
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
slide23

1

-1

slide24

1

-2

-1

slide25

1

1

-2

-1

minmax complexity
MinMax Complexity
  • For branching factor b and depth search d the complexity is O(bd)
cuting off search
Cuting Off Search
  • We want toprune the tree: stop exploring subtrees with values that will not influence the final MinMax root decision
alpha beta search cutoff rules
Alpha-Beta search cutoff rules
  • Keep track and update two values so far:
    • alpha is thevalue 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
alpha beta prunning
Alpha-Beta Prunning
  • functionMax-Value(state,game,alpha,beta) returns
  • minmax value of state
  • if Cutoff-Test(state) then return Eval(state)
  • for eachs in Successor(state) do
  • alpha := Max(alpha,Min-Value(s, game,alpha,beta)
  • if beta <= alpha then returnbeta
  • end; returnalpha
  • functionMin-Value(state,game,alpha,beta) returns
  • minmax value of state
  • if Cutoff-Test(state) then return Eval(state)
  • for eachs in Successor(state) do
  • beta := Min(beta,Max-Value(s, game,alpha,beta)
  • if beta <= alphathen returnalpha
  • end; returnbeta
complexity
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.
type a strategy
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
type a strategy backdraws
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
human strategies
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.
type b strategy
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.
quiescence positions
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
h p m is this move essential
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)
further developments
Further Developments..
  • Opening Book
  • Statistical variation – for position P,

create some distribution and play by it

  • Positional vs. Combination Player
  • Endgame Solver
  • Iterative Deepening
references
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