how rebel plays chess ed schröder presented by greg werner csci-297a extreme algorithms

50
How Rebel Plays Chess Ed Schröder Presented by Greg Werner CSCI-297A Extreme Algorithms

Upload: wesley-sims

Post on 16-Dec-2015

239 views

Category:

Documents


0 download

TRANSCRIPT

How Rebel Plays Chess

Ed Schröder

Presented by Greg Werner

CSCI-297A Extreme Algorithms

1. Prerequisites2. History (Context)3. Intro to Rebel4. Rebel Techniques

Outline of Presentation

Prerequisites

In order to understand this presentation best, it is necessary to be familiar with a few concepts.

1) A basic understanding of the rules of chess and all valid moves is necessary.

2) A cursory knowledge of general Artificial Intelligence techniques such as trees, Alpha-Beta search, pruning, and heuristic evaluation is assumed.Will not assume knowledge of REBEL program or where it fits into computer chess history.

Paper written for fellow computer chess programmers.

History (Context)

“Paper Machine” Turing was the CPU (White) vs 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.

History (Context)

MANIAC 1 – Human, Los Alamos 1956: 1.d3 b4 2.Nf3 d4 3.b3 e4 4.Ne1 a4 5.bxa4? [5.Nd2 and 6.Nd2-c4+ Nbcxc4 7.b3xc4 with a good game] 5...Nxa4 6.Kd2? Nc3 7.Nxc3 bxc3+ 8.Kd1 f4 9.a3 Rb6 10.a4 Ra6 11.a5 Kd5 12.Qa3 Qb5 13.Qa2+ Ke5 14.Rb1 Rxa5 15.Rxb5 Rxa2 16.Rb1 [to prevent 16...Ra1

mate!] 16...Ra5 17.f3 Ra4 18.fxe4 c4 19.Nf3+ Kd6 20.e5+ Kd5 21.exf6Q Nc5 22.Qf6xd4+ Kc6 23.Nf3-e5 mate.

Reduced 6x6 board (sans bishops) which took 12 minutes per 4-ply search. First time computer intelligence beat a human player (though the player had learned to play just one week prior)

History (Context)

1994 London – Kasparov played white1. c4 c6 2. d4 d5 3. Nf3 Nf6 4. Qc2 dxc4 5. Qxc4 Bf5 6. Nc3 Nbd7 7. g3 e6 8. Bg2

Be7 9. O-O O-O 10. e3 Ne4 11. Qe2 Qb6 12. Rd1 Rad8 13. Ne1 Ndf6 14. Nxe4 Nxe4 15. f3 Nd6 16. a4 Qb3 17. e4 Bg6 18. Rd3 Qb4 19. b3 Nc8 20. Nc2

Qb6 21. Bf4 c5 22. Be3 cxd4 23. Nxd4 Bc5 24. Rad1 e5 25. Nc2 Rxd3 26. Qxd3 Ne7 27. b4 Bxe3+ 28. Qxe3 Rd8 29. Rxd8+ Qxd8 30. Bf1 b6 31. Qc3 f6 32. Bc4+ Bf7 33. Ne3 Qd4 34. Bxf7+ Kxf7 35. Qb3+ Kf8 36. Kg2 Qd2+ 37. Kh3

Qe2 38. Ng2 h5 39. Qe3 Qc4 40. Qd2 Qe6+ 41. g4 hxg4+ 42. fxg4 Qc4 43. Qe1 Qb3+ 44. Ne3 Qd3 45. Kg3 Qxe4 46. Qd2 Qf4+ 47. Kg2 Qd4 48. Qxd4

exd4 49. Nc4 Nc6 50. b5 Ne5 51. Nd6 d3 52. Kf2 Nxg4+ 53. Ke1 Nxh2 54. Kd2 Nf3+ 55. Kxd3 Ke7 56. Nf5+ Kf7 57. Ke4 Nd2+ 58. Kd5 g5 59. Nd6+ Kg6 60.

Kd4 Nb3+ 0-1

Chess Genius (Richard Lang) beats Kasparov for first defeat of grand master in a tournament game.

Introduction to Rebel

REBEL was created in 1985 by Ed Schroeder. He worked on chess until his retirement in 2006. World Champion 1991-1995 (claimed by Schroeder, more research needed.) Death was induced by introduction of null-move heuristic.

Introduction to RebelVersion Tournament Title

Participants

Score

Games

Chess, 2001, Maastricht 18 5.0 9 Chess (Blitz), 2001, Maastricht 14 6.0 9 Chess, 2000, London 14 6.0 9 Chess (Blitz), 2000, London 10 2.5 9 Chess, 1999, Paderborn 30 4.5 7 Chess, 1995, Shatin 24 3.0 5

Chess, 1990, London Silver medal

11 6.0 7

Chess, 1989, Portorož 9 5.5 7

Chess, 1989, London Gold medal

9 7.5 8

Rebel X Chess, 1989, Edmonton 24 2.0 5

Chess (Software), 1988, Almeria

7 3.0 6

Recom Deventer C

Chess, 1986, Dallas 14 3.5 7

Recom Deventer B

Chess, 1986, Dallas 14 3.5 7

Recom Deventer A

Chess, 1986, Dallas 14 4.0 7

Chess, 1986, Cologne 22 3.0 5

Chess (Amateur), 1985, Amsterdam

5 4.0 7

Courtesy of http://grappa.univ-lille3.fr/icga/game.php?id=1

Introduction to Rebel

1997 – REBEL defeats Arthur Yusupiv 10.5 – 6.5

1998 – REBEL defeats Vishay Anand (elo 2795) 5 - 3

Basic Definitions

Quiescent Search – Searching certain noisy roots beyond the standard depth

Horizon Effect – Missing a move just beyond the standard depth

Null Move Heuristic – If ply 0 were allowed to pass, what plays in ply 1 would not be made

(because they are bad plays).Zugzwang – Forced to make bad move

Basic Definitions

Killer Heuristic – Repeat very good move at similar depth elsewhere in game tree.

Search Extension – Extended the search by 1 (or more ply) in certain situations

Bitboard – 8x8 binary representation of boardIterative Deepening – Searching each level of

tree until some depth d (with a particular move ordering)

Basic Definitions

Futility Pruning – Checking frontier nodes to see if they can be skipped and quiescent

search can be appliedFrontier Node – Nodes which are one level

depth above the quiescence thresholdAspiration Alpha Beta Search – Alpha Beta

Search with a narrow search windows

Rebel Techniques

1 Move Ordering2 Search Techniques

3 Extensions4 Selective Search5 Quiescent Search

6 Evaluation7 King Safety

Move OrderingAt the next ply, all moves are generated 12 piece squares are created (black and white * 6 pieces) each storing from and to values along with computed diff value. Search then takes highest move ordering value to determine which path to take first. Factor of 2X speed when this portion is included in the code.

Move Ordering

Generate_All_Moves() Update_All_Moves() (optional) Reduce_Depth() - When hash table or winning capture not reported by the update all moves. 13-14% speedup by lowering remaining depth by factor of 2 in subtree before full unsorted tree is searched. Get_Highest_Moves() Do_Something()

Move Ordering 127 – Hash Table Value 126 – Mate Killer Move. A Killer Move that has mate value in tree. 122-124 – Winning Capture (hanging pieces) In case of tie, always favor lower value pieces because it can result in a 5% speedup. Hanging piece (en prise) are pieces which are undefended. 121 – Queen Promotion with capture 120 – Queen Promotion sans capture 119 – Good Capture: Queen Captures Queen 118 – Good Capture: Rook Captures Rook 117 – Good Capture: Knight Captures Bishop 116 – Good Capture: Bishop Captures Bishop 115 – Good Capture: Bishop Captures Knight 114 – Good Capture: Pawn Captures Pawn 110 – Killer-One current ply: Best moves from search for a given ply. Do not include captures, promotions, or winning materials moves. Killer-one is best move 109 – Historic Mate Killer – 3-4% speedup. Mate-score during search. Store the value furthest in the the future in this slot. 108 – Killer-One ply-2 106 – Killer-Two current ply: Killer-two is second best move. Make sure Killer-two is not Killer-one 104 – Killer-Two ply-2 103 – 0-0 102 - 0-0-0 101 – Minor promotions – (Necessary to prevent stalemates in a few cases) -70 Everything else. Gives away material subtracts 30. If causes hanging pieces add 30.

Search Techniques

Alpha BetaLazy EVALFutility PruningHorizon SearchReductions

Alpha BetaAspiration Alpha Beta with 0.5 basic value:

a) Fail-high or fail-low results in 2.00 basic value instead of going to ply-1. This catches many of the cases that 0.50 does not catch. Should 2.00 fail as well, then we proceed to

ply-1 as before.b) Best score of previous ply stored. Beta

narrowing takes places, especially in the case of a small decline in score.

Lazy EVALAttempt to estimate the evaluation heuristic without considering every single factorThere is a margin involved in comparing alpha with scoreCan be used in:a) Horizon Depthb) Quiescent Search

Futility PruningUsed at horizon -1 and horizon – 2 depth levels

Here is the pseudocode for futility pruning:if (current_depth == horizon_depth – 1) { if (king in check) SKIP; if (move checks opponent king) SKIP; if (move captures opponent) SKIP; is (special case) SKIP; FUTILITY(); if (ALPHA < SCORE + MARGIN) can not

use; PRUNE THE TREE;}

Horizon Search

Avoid quiescent search at all costs!

if (LAZY_EVAL) return score (avoiding EVAL and QS)Evaluate_Position();

if (current_depth == max_depth) return score (no QS)if (TRICK_ONE) return score (no QS) // (MARGIN SETTING)

if (check opponent king) goto QSif (ALPHA >= SCORE) return score (no QS)

if (TRICK_TWO) return score (no QS) // (AUTHOR FORGETS)QS: Quiescent Search()

Reductions

Reduce the ply to search by 1.The author gives 5 separate cases to reduce

Reductions

if (remaining_depth > 2 && own_king_not_in_check && move is not a capture &&

move does not check opponent king) { if (ALPHA > SCORE + MARGIN) REDUCE

BY 1 } SCORE = // calculate new score (material +

piece-square value) MARGIN = // lookup remaining depth to get

the value

ReductionsSkip if :a) Reduction already taken placeb) Own king in checkc) Move would place opponent in checkd) Material is won by movee) Pressure increased on king

if (current_move is hash table move) do not reduce else { if (ALPHA < hash_table_score) do not reduce; else if (hash_table_score – evaluation_score > 0.50) do not

reduce; else reduce; }

Reductions

if (remaining_depth <=x && remaining_depth > 1) { if (ALPHA > SCORE + THREAT && ALPHA < SCORE + THREAT + MARGIN)

then reduce 1 ply }

Reductions

if (remaining_depth <=x && remaining_depth > 2) { if (ALPHA > SCORE + THREAT && ALPHA < SCORE + THREAT + MARGIN)

then reduce 2 ply }

Reductions if (winning_capture exists, but this move is not a capture) { if (threat_progress_is_made) do not reduce; if (remaining_depth <= 2) do not reduce; if (current_move is in hash table) do not reduce else { if (ALPHA < hash_table_score) { do not reduce; } if (hash_table_score – evaluation_score > 0.50) { do_not_reduce; } else { reduce; } } }

Extensions

ChecksRecapturesPawnsEndgameKing Safety

Checks

100-150 ELO points gainWhen the current ply move needs to be move out of check, an additional 1 ply of searching can be attained because of the limited scoped of the current ply. In particular, the first check found is ignored and the fourth check is given 2 ply additional searching as a means to tweak this feature

Recaptures30 – 40 ELO points gain2.2 -2.5 times slowdownDeeper in the tree, less likely to useIf (move_already_extended) do not extend;if (previous_ply_was_no_capture) do not extend; // duh, definition of recaptureif (move_does_not_capture_same_square) do not extend;if (move_not_winning_capture) do not extend;if (outside window) do not extend; // uses LOW with HIGH + piece value depth-1otherwise extend analysis by 1 ply.

Pawns

A very simple extension not explained in detail. Whenever a pawn is one rank short of promotion, it gets extended by 1-ply.

Endgame

The author notes that this extension is very powerful.Simple endings get extended by 1-ply. These are rook and/or bishop/knight endings.Pawn endings get extended by 3-ply. This one is a bit more involved and the pseudocode is as follows:

if (no_capture) do not extend; if (no_pawn_extending) do not extend; if (ISCORE not in +/- 3 range) do not extend; otherwise extend

King Safety

5-10 ELO Point Gain5% slowdownPressure (but not checks) are evaluatedExact algorithm not given by author

Selective Search

Composed Of:Null MoveStatic EvaluationRebel has favored selective search by static evaluation

over pure brute force methodsEven after “discovery” of null-move heuristic, REBEL kept its static evaluation portion.

Selective SearchGame divided into three portions1) Middle game2) End game3) Late end gameEach stage has its own analysis tableIn general, null-move is applied at earlier plies and static evaluation at later plies

Null-Move

REBEL attempts to avoid the expense of null-move searchAble to avoid full search 93-95% of the timeSome sacrifice in quality of move ordering is given up for a nice speedup factor.

Static EvaluationVery dangerous section of code potentially because of the pruning which could take placeThis section of code is what made REBEL dominant until about 1995 or 1996Do we do full search of the tree depends on:

if (own_king_in_check) return TRUE; if (move_checks_opponent) return TRUE;

if (move_is_winning_capture) return TRUE; if (ALPHA < SCORE + THREAT + MARGIN) return

true; if (pawn move to 2nd or 3rd to last rank) return true; if (move_threatens_opponent's king) return true;

prune if we have reached here

Quiescent Search

Two goals are present: Is evaluation of horizontal depth immune

from surprises. SCORE decreases. Check for possible series of mating

moves. SCORE increases

Quiescent Search

All captures are not evaluated in QS, which is a difference between REBEL and other chess engines. Instead, winning captures, equals captures, and queen promotions are the only ones evaluated. The order of analysis in QS is 1st winning capture, 2nd equal capture, and finally checking moves. Queen promotions have been grouped into the winning capture by the author.

Quiescent Search Get a move until no more moves if (Lazy_Eval_is_true) { Evaluate_Position(); return; } else if (Trick_one_is_true) { (Same as Horizon) return; } else if (move_checks_opponent_king) { go_one_ply_deeper } else if (ALPHA >= SCORE) { return } else if (Trick_two_is_true) { (Same as Horizon) return } else { go_one_ply_deeper; }

Quiescent Search

When king is in check and only has one or two moves, can significantly increase depthLong check analysis can speedup 14%Example given of a mate in 30 solved

Evaluation

CharacteristicsHanging Pieces

CharacteristicsA few hundred evaluation characteristics are used (many not listed in paper)Piece type very important for speed

13 pieces (6 types * 2 colors + 1 empty) An integer-like type (could be short) is

used to represent each piece type Switch represented by single jump – C

Indexing – Squares tables over fixed values

Hanging Pieces

For the side to move, REBEL can detect hanging pieces for up to 3 squares. They are sorted by material loss expectation. A similar thing happens for the opponent, only they are referred to as threatened pieces. A table is maintained for both sides which initially are given 0.0 for all squares. First for the white table, each white piece is analyzed based upon which squares they can move to

Hanging PiecesThe value is stored as an 8 bit value already

mentioned. Here is the exact determination of value:

3 bits number of attackers (0-7) 1 bit pawn (8) 1 bit knight/bishop (16) 1 bit rook (32) 1 bit queen (64) 1 bit king (128)

Hanging Pieces

Overall, a 860 kb data structure is created char TABLE[12][256][256]; If, for a single piece, the status value is not 0, then the piece is considered to be a hanging piece. During start-up, the TABLE is filled with predefined values

King SafetySymmetric algorithmREBEL uses progressive evaluation only in its king safety algorithmThe reason the author chooses this is approach is that coherence between would-be king attackers is captured by this method, whereas in a normal evaluation scheme would not.

King Safety

Sample progression for King Safety Contibutionint EVAL [] = {0, 2, 3, 6, 12, 18, 25, 37, 50, 75,100, 1125, 150, 175, 200, 225, 250, 275, 300, 325,350, 375, 400, 425, 450, 475, 500, 525, 550, 575,600, 600, 600 ,.....};At first, there is little impact of pressure on the king. Only significant pressure is given any notice.Positional blunders are prevented by this progressive approach

King Safety

Three categories of threatened squares are then evaluated in order. A flag value is kept

and this flag value provides the lookup to the contribution of the EVAL table.

King Safety

Not used when opponent queen has exited board or during the late end game where

analysis can actually be hurt by this routine.