Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think...

41
Artificial Intelligence in Chess Dan Pomerantz

Transcript of Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think...

Page 1: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

Artificial Intelligencein ChessDan Pomerantz

Page 2: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 2

Outline• Brief history of Artificial Intelligence in chess

• Why are computers good at chess?

• Basic techniques for writing a chess AI

Page 3: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 3

The first AI – 1770 ! “The Turk”

Page 4: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 4

The first AI – 1770 ! “The Turk”

Page 5: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 5

The Turk

• Able to play chess “automatically”• Appeared to work like a clock• Turned out to be illusion using magnets

and a real human underneath• No one figured out the secret for 50

years!

Page 6: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 6

• In the 1940s and 1950s, mathematicians and computer scientists came up with algorithms or descriptions of HOW to program a computer to play chess.

• Problem : Computers weren't powerful enough to follow these descriptions!

Page 7: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 7

Finally.....

• Around the late 1950s, we finally were able to create programs that played FULL games of chess.

• Turing test : Can we train a computer to make us think there is a human?

Page 8: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 8

Deep Blue (mid 1990s)

Page 9: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 9

Page 10: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 10

Page 11: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 11

“It was an impressive achievement, of course, and a human achievement by the members of the IBM team, but Deep Blue was only intelligent the way your programmable alarm clock is intelligent. Not that losing to a $10 million alarm clock made me feel any better.” - Garry Kasparov

Page 12: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 12

Page 13: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 13

Page 14: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 14

Page 15: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 15

Page 16: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 16

State of various games• Chess – computers can beat world

champions• Checkers – solved by Jonathan Schaeffer• Bridge – computers can compete with top

players but don't normally win• Go – computers not even close to top

players

Page 17: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 17

Why is AI Chess “easier”• Small “branching” factor• Perfect information• Positions can be evaluated with reasonably

simple heuristics• “Chess mastery essentially consists of

analyzing chess positions accurately.” - Mikhail Botvinnik

Page 18: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 18

What makes AI better than human?

• Key factor : Emotions lead to inconsistency

Page 19: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 19

What makes computers stronger than humans?

• Key factor : Emotions lead to inconsistency• Computers don't experience fatigue• “Chess is thirty to forty percent psychology.

You don't have this when you play a computer. I can't confuse it.” - Judit Polgar

• “Few things are as psychologically brutal as chess.” - Garry Kasparov

Page 20: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 20

Emotion and fatigue : Kotov• “I was Black and had a completely

won position. I was annoyed that my opponent – a certain Golubev – did not resign although he was a whole rook down. It was my turn to move and I realized that the joy of victory could not be long delayed. My opponent had already folded his score sheet in two, written “Resigns” on it and put it in his pocket. With an air of hopelessness he was looking round and seemed to express with his whole demeanor that as soon as I made my move he would resign.”

Page 21: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 21

Emotion and fatigue

Page 22: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 22

Emotion and fatigue

Page 23: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 23

Emotion and fatigue

Page 24: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 24

Emotion and fatigue

Page 25: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 25

Emotion and fatigue• So I made my move – the most

obvious one there was – taking his bishop with my rook. Immediately the other bishop whizzed through the air and landed with a bang on d8. Again with a bang my opponent started my clock and looked round in triumph at the people who were watching the game. Then he took out his score sheet, wrote down his move and mine and crossed out the word “Resigns”. I was the one who had to resign!

Page 26: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 26

How to Create an AI : Search (minimax algorithm)

Page 27: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 27

●Key idea: Choose the move that maximizes your position in the WORST case

Qb6 here is aterrible move for white!

Page 28: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 28

Chess is way too complex●Tree is just too large●Heuristic search●Choosing the best moves without searching!●Transpositions

Page 29: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 29

Heuristic Search●Search up until a certain point using this approach●At some point, stop and evaluate the position.●How to evaluate a position?

Page 30: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 30

Horizon Effect●5 move combination that wins a piece!●Unfortunately it's also a 6 move combination to lose a piece!●Try to determine “interesting” position

Page 31: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 31

Trimming Search Tree:“Alpha-beta” pruning

●Idea: ●1)Suppose I am debating between choice a,b,c for move.●2)Now suppose I searched choice a) and determined it won a pawn.●3)I am looking at choice b and I notice that ONE of my opponent's moves in response leave the position even. I can now conclude there is no point of looking at all of my opponent's responses

Page 32: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 32

Trimming Search Tree:“Alpha-beta” pruning

●Order of searching is now important.●This matches the way humans try to search.

Page 33: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 33

Trimming Search Tree:Transposition tables

●Many positions occur via transpositions.If the computer has an evaluation for:

1.e4 e5 2.f4

it should be able to use that for

1.f4 e5 2.e4

Trade off of search time vs storage time

Page 34: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 34

Current State

• Computer AIs now teach us!• Big part of challenge is making the AI

levels varying so that people can use them to get better

• Is chess solvable? Difficult to say if we'll ever have enough power to solve chess?

Page 35: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 35

Kramnik

“I don’t know whether computers are improving the style of play, I know they are changing it. Chess has become a different game, one could say that computers have changed the world of chess. That is pretty clear.” - Vladimir Kramnik

Page 36: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 36

What can we learn from computers?

“Let us suppose that at one point in your game you have a choice between two moves, Rd1 or Ng5. Which should you play? You settle down comfortably in your chair and start your analysis by silently saying to yourself the possible moves. 'All right, I could play Rd1 and he would probably play ...Bb7, or he could take my a-pawn, which is now undefended. What then? Do I like the look of the position then?' You go one move further in your analysis and then you pull a long face—the rook move no longer appeals to you. Then you look at the knight move. 'What if I go NG5?

Page 37: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 37

What can we learn from computers?

“He can drive it away by ...h6, I go Ne4, he captures it with his bishop. I recapture and he attacks my queen with his rook. That doesn't look very nice...so the knight move is no good. Let's look at the rook move again. If he plays ...Bb7 I can reply f3, but what if he captures my a-pawn. What can I play then? No, the rook move is no good. I must check the knight move again. So, Ng5, h6; Ne4, Bxe4; Qxe4, Rd4. No good! So I mustn't move the knight. Try the rook move again. Rd1, Qxa2.' At this point you glance at the clock. 'My goodness! Already 30 minutes gone on thinking whether to move the rook or knight.'

Page 38: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 38

What can we learn from computers?

“If it goes on like this you'll really be in time trouble. And then suddenly you are struck by the happy idea—why move the rook or knight? 'What about Bb1?' And without any more ado, without any analysis at all you move the bishop, just like that, with hardly any consideration at all”

-Think Like a Grandmaster, Alexander Kotov

Page 39: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 39

What can computers learn from us?

Page 40: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 40

Kickboxing

“A computer once beat me at chess, but it was no match for me at kick boxing.”-Emo Phillips

Page 41: Artificial Intelligence in Chesschess.ssmu.ca/wp-content/uploads/2012/05/AiInChess.pdf · -Think Like a Grandmaster, Alexander Kotov. AI in Chess 39 What can computers learn from

AI in Chess 41

Thank you