Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under...

33
Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya

Transcript of Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under...

Page 1: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

Thinking Machine

Abhirup Ghosh (09305052)

Rathish Das (09305040)

Soumya Prasad Ukil (09305028)

Under the guidance of

Prof. Pushpak Bhattacharyya

Page 2: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

2

Outline

• Introduction

• A brief history of computer chess

• Evaluation function

• Basic Algorithms

• Advanced Algorithm

• Deep blue

• Conclusion

Page 3: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

3

Introduction to chess

• Ancient two player strategy based board game.

• Played on 8×8 chess board.

• Players play with pure decision making and skill of thinking.

• The object of the game is to checkmate the opponent’s king.

Page 4: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

4

Why AI in chess?

• A game of perfect knowledge, not too trivial not too complex, goal state known.

• A way to solving complex decision making.

• Testing many algorithm efficiency.

• Similar to many other problems –– Machines for designing filters, equalizers.– Machines capable of orchestrating a melody.

Page 5: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

5

Computers playing chess

• 1950 – 1st computer model hand simulation.

• mid 1960’s – 1st international computer-computer match.

• 1974 – 1st World Computer Chess Championship.

• 1997 – IBM’s big giant Deep Blue defeated  Garry Kasparov!

Page 6: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

6

How computer play chess

• Opening game mode, endgame mode handled by typically databases.

• Middle game mode by searching the best move possible.

• For searching assume opponent always plays his best.

• Form a game tree.

Page 7: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

7

Game tree

Avg branching factor - 30

Average game lasts for 40 moves

Page 8: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

8

Evaluation Function

• Evaluate how good a state is.

• Evaluation function f(P) when applied to a chess position P tells – which category P belongs {Win, Loss, Tie}

• How to get perfect f(P)?

Page 9: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

9

• Another approach– Store every possibility in the memory and the best

move in every situation.– Number of possible position in general – 64!/32!

(8!)2(2!)6 =

Play perfect chess (!)

• Time– For a white move after a black move # of possibilities

= 30×30 = 103

– If the game lasts for 40 moves, Total possibilities = (103)40 = 10120.

– Machine examining one possibility per 1µs needs1090 years

1043

Page 10: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

10

Approximating Evaluation function

• Material Balance – difference between number of pieces.– Shannon used

• f(P) = 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') + ...

• Mobility – Number of possible move.• Pawn formation• King safety• … many more to consider!

Page 11: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

11

Approximating Evaluation function(2)

Pawn ramsDoubled pawn

Isolated pawn

Passed pawn

Page 12: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

12

Evaluation function weights

• Most popular is to set static weights.• Can be implemented using Genetic

Algorithm.• Define a chromosome of weights.• How to define the fitness???

– Conduct games between individuals. Winner is better.

– Consume too much time.• Research area (mentor based approach).

Page 13: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

13

Basic AlgorithmsBasic Algorithms

Page 14: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

14

Min-max algorithm

• Idea borrowed from zero-sum game strategy (if one gains, another loses).

• A decision rule used to minimize the maximum possible loss.

• The two players are working towards opposite goals to make predictions about which future states will be reached as the game progresses, and then proceeds accordingly to optimize its chance of victory.

• An evaluation function is used to determine whether player1(MAX) is going to win or the player2(MIN)

Page 15: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

15

How does it work?

• By the Min-max algorithm, Max will always choose to play B, even though he would score a bigger victory if he played A and Min made a mistake!

Max Move Min Move Evaluation

A C 12

A D -2

B C 5

B D 6

Page 16: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

16

Implementation in Chess

1 3 5 9 4 6

1 4

4

3

MIN Move

MAX Move

Page 17: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

17

Performance

• Expensive, since every leaf node has to be visited to make a decision.

• Time complexity:-

O(WD) W : No of moves D : Max depth

In chess, W=30 and D >=100.

Clearly impractical to use.

Page 18: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

18

α-β pruning

• Returns exactly same moves as min-max

• Does not explore those branches which can't influence the result.

Page 19: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

19

α-β pruning

• Two parameters:-• α - Holds the best MAX value

found β - Holds the best MIN value found

• At MIN level, if β < α, abort expanding child.• At MAX level, if α > β, abort search.

Page 20: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

20

α-β pruning A

B C

D E

6 5 8

6 >=8

<=6

H I J K

= agent = opponent

On discovering eval( D ) = 6

we know that eval( B ) <= 6

On discovering eval( J ) = 8

we know that eval( E ) >= 8

Can stop expansion of E as best play will not go via E

Value of K is irrelevant – prune it!

STOP! What else can

you deduce now!?STOP! What else can

you deduce now!?STOP! What else can

you deduce now!?

MAX

MIN

MAX

Example from internet

Page 21: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

21

Performance

• Does not affect the final result.• Time complexity:-• O(WD/2)

– W : No of moves– D : Max depth

• Suffers from Horizon effect.

Page 22: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

22

Advanced Algorithms

Page 23: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

23

Iterative Deepening

• Chess should be played in strict and limited time control .

• Program does depth two search , depth three search and so on until allotted time has time out .

• When time is up programs returns its current best guess .

12/01/09 23

Page 24: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

24

Quiescence Search

• Used to overcome horizon effect.

• Search all non-quiescent or ‘violent’ moves beyond the depth 0-th node until the situation becomes calm.

• 3 types:

1)Full width search

2)Reduced width search

3)Capture search 12/01/09 24

Page 25: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

25

Transposition Table

• Basically a hash table.

• During search some moves occur several times.

• Store information about position which have already been searched.

• When same position is reached again , the stored information can be used to speed up the searching.

12/01/09 25

Page 26: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

26

Null Move

• If one opt NOT to play a move ("pass"), letting the opponent play two sequential moves, and opponent’s score is still not any good, then clearly his position is very strong.

• It should not be used when the side to play has only a few pieces left or the side to play is in danger of losing to checkmate in the near future.

12/01/09 26

Page 27: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

27

Aspiration window

• Searching speed depends on width of initial α-β window .

• The narrower the search-window , the more node will fail with either α or β cut-off

• Make window width around the previous score returned .

e.g. : α = old score-30,

β = old score+30.

12/01/09 Created by Abhirup, Rathish, Soumya

27

Page 28: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

28

Man Vs Machine (Deep Blue)

• Defeat world champion Kasparov in a 6 game match – win 2 , lost 1 , draw 3.

• Search up to 40 moves Developed by IBM on May 11 , 1997.

• 30 Processor , each contains 16 single chip chess processor.

• Search Speed – 2.5 million position/sec chip.• Developed mainly in hardware level.

12/01/09 28

Page 29: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

29

Deep Blue

• Fast evaluation , Slow evaluation.

• Move generation , search control , evaluation function calculation all are done in chip level.

12/01/09 29

Page 30: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

30

Conclusion

• More than 5 decades of computer chess.• The progress of chess programs in terms of their

measured performance ratings has been steady.• This progress however mostly come from h/w

speed.• Searching algorithm testing.• Recently people trying to apply evolutionary

algorithm and heuristics in calculating evaluation functions, endgame mode.

Page 31: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

31

When will a computer be the unassailed expert on chess?

• "in five years“ - Newborn

• "about the end of the century" - Scherzer and Hyatt

• "eventually - it is inevitable" - Thompson

• "never, or not until the limits on human skill are known" – Marsland.

Page 32: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

32

References

• E. Shannon, Claude, “XXII. Programming a Computer for Playing Chess,” Philosophical Magazine, Ser. 7, vol. 41, No. 314, Mar 1950.

• Computer Chess And Search (1991), by T. A. Marsland• A Self-Learning Evolutionary Chess Program (IEEE Dec 2004), by

Fogel, D.B. Hays, T.J. Hahn, S.L. Quon.• Genetic Algorithms for Mentor-Assisted Evaluation Function

Optimization – Omid David-Tabibi, Moshe Koppel, Nathan S. Netanyahu, 2008.

• Deep Blue (Science Direct) - Murray Campbell , A. Joseph Hoane Jr. , Feng-hsiung Hsu, 2002.

• Chess Programming tutorial by François Dominic Laramée in http://www.gamedev.com.

• http://www.Wikipedia.org• http://www.computerhistory.org/chess/

Page 33: Thinking Machine Abhirup Ghosh (09305052) Rathish Das (09305040) Soumya Prasad Ukil (09305028) Under the guidance of Prof. Pushpak Bhattacharyya.

12/01/09 Created by Abhirup, Rathish, Soumya

33

Thank You

Questions ?