570 likes | 590 Views
Pasi Fränti. Computer Chess. 5.5.2016. History. Mechanical Turk [von Kempelen, 1770] Computer Chess problem and Minmax search [Shannon, 1950] Turings Chess test Deep Blue wins Garry Kasparov [1987] Best computers today (~3200); Magnus Carlsen (2853)
E N D
Pasi Fränti Computer Chess 5.5.2016
History • Mechanical Turk [von Kempelen, 1770] • Computer Chess problem and Minmax search [Shannon, 1950] • Turings Chess test • Deep Blue wins Garry Kasparov [1987] • Best computers today (~3200);Magnus Carlsen (2853) • Machine learning for optimizingweights of material and positional factors
Minmax searchFixed depth 3 17 12 15 25 0 2 5 3 2 14 2 https://www.youtube.com/watch?v=fJ4uQpkn9V0
Materialtypical values 9 3 3 5 1
Alpha-beta pruning Upper bound Lower bound Terminate when < Max! Min! =3 Max! =2 3 2 Min! Min! 3 17 15 25 0 2 5 3 2 14 2
Alpha-beta pruning Max! =3 Min! 15 =15 3 Max! 15 3 2 3 17 15 2 5 3 2 14 2
Alpha-beta pruning =3 Max! 3 =3 Min! =3 15 3 Max! 15 =2 3 2 2 Min! 3 17 15 2 3 2 14 2
Alpha-beta pruning Final result: 3 =3 3 Max! 3 3 Min! 15 3 3 15 3 2 2 3 3 17 15 2 3 2
Order of moves • Very important! • More accurate value More can be pruned • If branch of best move (oracle!) always searched first, branching factor n • Assume fixed amount of time allowed: d = search dept of minmax e = search dept of alpha-beta n = number of moves n e n d Twice as deep!
Heuristics for ordering • If the same position reached again; use the previous best move to search first again. • If a move was found good in sibling node, then assume it is good also in this node. • Capturing higher value piece = GOODCapturing defended lower value piece = BAD • Queen promotions
Examples of captures • Nxe5 Nxe5 -2 • Bxc6 dxc6 • Nxe5 +1 • Nxd5 (+3) cxd5 (+3) • Bxd5 (+1) Bxd5 (+3) • Qxd5 (+3) Qxd5 (+9) • Rxd5 (+9) +1 -2
Horizon effectblack to move Two plies search: • … Bxh2 • Kxh2 Three plies search: • … Nbc5 • cxd7 Nxc7 -2 -2
Horizon effectblack to move Nine ply search: • … b2 • Bxb2 c3 • Bxc3 d4 • Bxd4 e5 • Bxe5 f6 -4
Horizon effectPushing the disaster beyond horizon What can black do?
Quiescent position Search deeper until quiescent position Non-quiescent situations: • Winning captures (or any / major capture) • Checks + evasions of checks • Pawn promotions • Pawn move to 7th rank Earlier used also singular extension
Check is non-quiescent • Material is even • Check is forcing • Black will lose either Queen or another piece
Pawn promotionWhite to play and win 1.e7 Qa3+ 2.Rb4 Qa7+ 3.Kxc4! Qxe7 4.Nxg6+fxg6 5.Bf6+ Qxf6 6.Kd5+Kg5 7.h4+Kf5 8.g4+hxg4 9.Rf4+Bxf4 10.e4#
Pawn promotionWhite wins after 10 moves • All moves since e7 were non-quiescent: • Check • Forced move • Capture • Threat to promote
Limits of non-quiescent Looks quiet…
Limits of non-quiescent 1. Nf6+ gxf6 2. Qg4+ Kh8 3. Kg2 Quiet move but…
Limits of non-quiescent Unstoppable: 4. Rh1X
Material Piece-square tables Pawn structure Piece-specific evaluation Mobility King safety Threat Space Draw-ish-ness Evaluation criteria
Material Basic values 9 5 3 3 1 Double knights Double bishops ?? 6+
Pawn valuesopening Center important Progress
Piece-square tableKnight -50,-40,-30,-30,-30,-30,-40,-50, -40,-20, 0, 0, 0, 0,-20,-40, -30, 0, 10, 15, 15, 10, 0,-30, -30, 5, 15, 20, 20, 15, 5,-30, -30, 0, 15, 20, 20, 15, 0,-30, -30, 5, 10, 15, 15, 10, 5,-30, -40,-20, 0, 5, 5, 0,-20,-40, -50,-40,-20,-30,-30,-20,-40,-50,
Piece-square tableKing during mid-game -30,-40,-40,-50,-50,-40,-40,-30, -30,-40,-40,-50,-50,-40,-40,-30, -30,-40,-40,-50,-50,-40,-40,-30, -30,-40,-40,-50,-50,-40,-40,-30, -20,-30,-30,-40,-40,-30,-30,-20, -10,-20,-20,-20,-20,-20,-20,-10, 20, 20, 0, 0, 0, 0, 20, 20, 20, 30, 10, 0, 0, 10, 30, 20
Piece-square tableend game -50,-40,-30,-20,-20,-30,-40,-50, -30,-20,-10, 0, 0,-10,-20,-30, -30,-10, 20, 30, 30, 20,-10,-30, -30,-10, 30, 40, 40, 30,-10,-30, -30,-10, 30, 40, 40, 30,-10,-30, -30,-10, 20, 30, 30, 20,-10,-30, -30,-30, 0, 0, 0, 0,-30,-30, -50,-30,-30,-30,-30,-30,-30,-50
Pawn structure Backward Passed Opposed Passed Lever Unsupported Isolated
Mobility 4 2 1 3 0 2
Transposition table • 1. e4 e5 • 2. Nf3 Nc6 • Nf3 Nc6 • e4 e5 • 1. e4 Nc6 • 2. Nf3 e5 • Castling rights • En passant moves
Opening book • Known games from grand masters. • Include moves played often. • Systematic self-play by computer until pre-defined depth. • Exclude moves leading to bad position.
Deep Blue – Kasparov 1997 Decisive game 6 Kasparov played h6… Ne4 and black has better position Knight sacrifice wins but only if white knows how to play the position. Typical computer chess programs don’t know how to do it.
Deep Blue game 6Continuation of the game 8. Nxe6 Qe7 9. 0-0 fxe6 10. Bg6+ Nine moves later after 19. c5 1-0 black resigns
End game database • Known games from grand masters. • Include moves played often. • Systematic self-play by computer until pre-defined depth. • Exclude moves leading to bad position.
Optimizing by Genetic AlgorithmStudent project by P.Aksenov (Joensuu, Finland) • Population of computer players. • Random initial parameters. • Tournament playing to find fitness. • Crossover for new parameter combies.
GiraffeStudent project by M.Lai (London, UK) • Temporal-difference learning: play fixed depth (12 plies). • Fitness based on stability. • Non-linear combination of 363 features. • Optimizes parameters and selection of the next branch in the search.