arXiv(opens in a new tab)cs.AIDec 2017Cited by 17 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:1712.01815

Mastering Chess and Shogi by Self-Play with a General Reinforcement Learning Algorithm

David Silver, Thomas Hubert, Julian Schrittwieser, Ioannis Antonoglou, Matthew Lai, Arthur Guez, Marc Lanctot, Laurent Sifre, Dharshan Kumaran, Thore Graepel, Timothy Lillicrap, Karen Simonyan, Demis Hassabis

David Silver, 1∗^{1*} Thomas Hubert, 1∗^{1*} Julian Schrittwieser, 1∗^{1*} Ioannis Antonoglou, 1^{1} Matthew Lai, 1^{1} Arthur Guez, 1^{1} Marc Lanctot, 1^{1} Laurent Sifre, 1^{1} Dharshan Kumaran, 1^{1} Thore Graepel, 1^{1} Timothy Lillicrap, 1^{1} Karen Simonyan, 1^{1} Demis Hassabis 1^{1}

1^{1}DeepMind, 6 Pancras Square, London N1C 4AG.

∗^{*}These authors contributed equally to this work.

Abstract

The game of chess is the most widely-studied domain in the history of artificial intelligence. The strongest programs are based on a combination of sophisticated search techniques, domain-specific adaptations, and handcrafted evaluation functions that have been refined by human experts over several decades. In contrast, the AlphaGo Zero program recently achieved superhuman performance in the game of Go, by tabula rasa reinforcement learning from games of self-play. In this paper, we generalise this approach into a single AlphaZero algorithm that can achieve, tabula rasa, superhuman performance in many challenging domains. Starting from random play, and given no domain knowledge except the game rules, AlphaZero achieved within 24 hours a superhuman level of play in the games of chess and shogi (Japanese chess) as well as Go, and convincingly defeated a world-champion program in each case.

The study of computer chess is as old as computer science itself. Babbage, Turing, Shannon, and von Neumann devised hardware, algorithms and theory to analyse and play the game of chess. Chess subsequently became the grand challenge task for a generation of artificial intelligence researchers, culminating in high-performance computer chess programs that perform at superhuman level (9, 13). However, these systems are highly tuned to their domain, and cannot be generalised to other problems without significant human effort.

A long-standing ambition of artificial intelligence has been to create programs that can instead learn for themselves from first principles (26). Recently, the AlphaGo Zero algorithm achieved superhuman performance in the game of Go, by representing Go knowledge using deep convolutional neural networks (22, 28), trained solely by reinforcement learning from games of self-play (29). In this paper, we apply a similar but fully generic algorithm, which we call AlphaZero, to the games of chess and shogi as well as Go, without any additional domain knowledge except the rules of the game, demonstrating that a general-purpose reinforcement learning algorithm can achieve, tabula rasa, superhuman performance across many challenging domains.

A landmark for artificial intelligence was achieved in 1997 when Deep Blue defeated the human world champion (9). Computer chess programs continued to progress steadily beyond human level in the following two decades. These programs evaluate positions using features handcrafted by human grandmasters and carefully tuned weights, combined with a high-performance alpha-beta search that expands a vast search tree using a large number of clever heuristics and domain-specific adaptations. In the Methods we describe these augmentations, focusing on the 2016 Top Chess Engine Championship (TCEC) world-champion Stockfish (25); other strong chess programs, including Deep Blue, use very similar architectures (9, 21).

Shogi is a significantly harder game, in terms of computational complexity, than chess (2, 14): it is played on a larger board, and any captured opponent piece changes sides and may subsequently be dropped anywhere on the board. The strongest shogi programs, such as Computer Shogi Association (CSA) world-champion Elmo, have only recently defeated human champions (5). These programs use a similar algorithm to computer chess programs, again based on a highly optimised alpha-beta search engine with many domain-specific adaptations.

Go is well suited to the neural network architecture used in AlphaGo because the rules of the game are translationally invariant (matching the weight sharing structure of convolutional networks), are defined in terms of liberties corresponding to the adjacencies between points on the board (matching the local structure of convolutional networks), and are rotationally and reflectionally symmetric (allowing for data augmentation and ensembling). Furthermore, the action space is simple (a stone may be placed at each possible location), and the game outcomes are restricted to binary wins or losses, both of which may help neural network training.

Chess and shogi are, arguably, less innately suited to AlphaGo’s neural network architectures. The rules are position-dependent (e.g. pawns may move two steps forward from the second rank and promote on the eighth rank) and asymmetric (e.g. pawns only move forward, and castling is different on kingside and queenside). The rules include long-range interactions (e.g. the queen may traverse the board in one move, or checkmate the king from the far side of the board). The action space for chess includes all legal destinations for all of the players’ pieces on the board; shogi also allows captured pieces to be placed back on the board. Both chess and shogi may result in draws in addition to wins and losses; indeed it is believed that the optimal solution to chess is a draw (17, 20, 30).

The AlphaZero algorithm is a more generic version of the AlphaGo Zero algorithm that was first introduced in the context of Go (29). It replaces the handcrafted knowledge and domain-specific augmentations used in traditional game-playing programs with deep neural networks and a tabula rasa reinforcement learning algorithm.

Instead of a handcrafted evaluation function and move ordering heuristics, AlphaZero utilises a deep neural network (p,v)=fθ(s)(\mathbf{p}, v) = f_{\theta}(s) with parameters θ\theta. This neural network takes the board position ss as an input and outputs a vector of move probabilities p\mathbf{p} with components pa=Pr(a∣s)p_a = Pr(a|s) for each action aa, and a scalar value vv estimating the expected outcome zz from position ss, v≈E[z∣s]v \approx \mathbb{E}[z|s]. AlphaZero learns these move probabilities and value estimates entirely from self-play; these are then used to guide its search.

Instead of an alpha-beta search with domain-specific enhancements, AlphaZero uses a general-purpose Monte-Carlo tree search (MCTS) algorithm. Each search consists of a series of simulated games of self-play that traverse a tree from root sroots_{root} to leaf. Each simulation proceeds by selecting in each state s a move a with low visit count, high move probability and high value (averaged over the leaf states of simulations that selected a from s) according to the current neural network fθf_{\theta}. The search returns a vector π\pi representing a probability distribution over moves, either proportionally or greedily with respect to the visit counts at the root state.

The parameters θ\theta of the deep neural network in AlphaZero are trained by self-play reinforcement learning, starting from randomly initialised parameters θ\theta. Games are played by selecting moves for both players by MCTS, at∼πta_t \sim \pi_t. At the end of the game, the terminal position sTs_T is scored according to the rules of the game to compute the game outcome zz: -1 for a loss, 0 for a draw, and +1 for a win. The neural network parameters θ\theta are updated so as to minimise the error between the predicted outcome vtv_t and the game outcome zz, and to maximise the similarity of the policy vector pt\mathbf{p}_t to the search probabilities πt\pi_t. Specifically, the parameters θ\theta are adjusted by gradient descent on a loss function ll that sums over mean-squared error and cross-entropy losses respectively,

(p,v)=fθ(s),l=(z−v)2−π⊤log⁡p+c∣∣θ∣∣2(1)(\mathbf{p},v)=f_{\theta}(s),\quad l=(z-v)^{2}-\boldsymbol{\pi}^{\top}\log\mathbf{p}+c||\theta||^{2} \tag{1}

where c is a parameter controlling the level of L2L_{2} weight regularisation. The updated parameters are used in subsequent games of self-play.

The AlphaZero algorithm described in this paper differs from the original AlphaGo Zero algorithm in several respects.

AlphaGo Zero estimates and optimises the probability of winning, assuming binary win/loss outcomes. AlphaZero instead estimates and optimises the expected outcome, taking account of draws or potentially other outcomes.

The rules of Go are invariant to rotation and reflection. This fact was exploited in AlphaGo and AlphaGo Zero in two ways. First, training data was augmented by generating 8 symmetries for each position. Second, during MCTS, board positions were transformed using a randomly selected rotation or reflection before being evaluated by the neural network, so that the Monte-Carlo evaluation is averaged over different biases. The rules of chess and shogi are asymmetric, and in general symmetries cannot be assumed. AlphaZero does not augment the training data and does not transform the board position during MCTS.

In AlphaGo Zero, self-play games were generated by the best player from all previous iterations. After each iteration of training, the performance of the new player was measured against the best player; if it won by a margin of 55% then it replaced the best player and self-play games were subsequently generated by this new player. In contrast, AlphaZero simply maintains a single neural network that is updated continually, rather than waiting for an iteration to complete.

Figure

Figure 1: Training AlphaZero for 700,000 steps. Elo ratings were computed from evaluation games between different players when given one second per move. a Performance of AlphaZero in chess, compared to 2016 TCEC world-champion program Stockfish. b Performance of AlphaZero in shogi, compared to 2017 CSA world-champion program Elmo. c Performance of AlphaZero in Go, compared to AlphaGo Lee and AlphaGo Zero (20 block / 3 day) (29).

Self-play games are generated by using the latest parameters for this neural network, omitting the evaluation step and the selection of best player.

AlphaGo Zero tuned the hyper-parameter of its search by Bayesian optimisation. In AlphaZero we reuse the same hyper-parameters for all games without game-specific tuning. The sole exception is the noise that is added to the prior policy to ensure exploration (29); this is scaled in proportion to the typical number of legal moves for that game type.

Like AlphaGo Zero, the board state is encoded by spatial planes based only on the basic rules for each game. The actions are encoded by either spatial planes or a flat vector, again based only on the basic rules for each game (see Methods).

We applied the AlphaZero algorithm to chess, shogi, and also Go. Unless otherwise specified, the same algorithm settings, network architecture, and hyper-parameters were used for all three games. We trained a separate instance of AlphaZero for each game. Training proceeded for 700,000 steps (mini-batches of size 4,096) starting from randomly initialised parameters, using 5,000 first-generation TPUs (15) to generate self-play games and 64 second-generation TPUs to train the neural networks. 1^{1} Further details of the training procedure are provided in the Methods.

Figure 1 shows the performance of AlphaZero during self-play reinforcement learning, as a function of training steps, on an Elo scale (10). In chess, AlphaZero outperformed Stockfish after just 4 hours (300k steps); in shogi, AlphaZero outperformed Elmo after less than 2 hours (110k steps); and in Go, AlphaZero outperformed AlphaGo Lee (29) after 8 hours (165k steps). 2^{2}

We evaluated the fully trained instances of AlphaZero against Stockfish, Elmo and the previous version of AlphaGo Zero (trained for 3 days) in chess, shogi and Go respectively, playing 100 game matches at tournament time controls of one minute per move. AlphaZero and the previous AlphaGo Zero used a single machine with 4 TPUs. Stockfish and Elmo played at their

1^{1}The original AlphaGo Zero paper used GPUs to train the neural networks.

2^{2}AlphaGo Master and AlphaGo Zero were ultimately trained for 100 times this length of time; we do not reproduce that effort here.

GameWhiteBlackWinDrawLoss
ChessAlphaZeroStockfish25250
StockfishAlphaZero3470
ShogiAlphaZeroElmo4325
ElmoAlphaZero4703
GoAlphaZeroAG0 3-day31-19
AG0 3-dayAlphaZero29-21

Table 1: Tournament evaluation of AlphaZero in chess, shogi, and Go, as games won, drawn or lost from AlphaZero's perspective, in 100 game matches against Stockfish, Elmo, and the previously published AlphaGo Zero after 3 days of training. Each program was given 1 minute of thinking time per move.

strongest skill level using 64 threads and a hash size of 1GB. AlphaZero convincingly defeated all opponents, losing zero games to Stockfish and eight games to Elmo (see Supplementary Material for several example games), as well as defeating the previous version of AlphaGo Zero (see Table 1).

We also analysed the relative performance of AlphaZero's MCTS search compared to the state-of-the-art alpha-beta search engines used by Stockfish and Elmo. AlphaZero searches just 80 thousand positions per second in chess and 40 thousand in shogi, compared to 70 million for Stockfish and 35 million for Elmo. AlphaZero compensates for the lower number of evaluations by using its deep neural network to focus much more selectively on the most promising variations – arguably a more “human-like” approach to search, as originally proposed by Shannon (27). Figure 2 shows the scalability of each player with respect to thinking time, measured on an Elo scale, relative to Stockfish or Elmo with 40ms thinking time. AlphaZero's MCTS scaled more effectively with thinking time than either Stockfish or Elmo, calling into question the widely held belief (4, 11) that alpha-beta search is inherently superior in these domains. 3^{3}

Finally, we analysed the chess knowledge discovered by AlphaZero. Table 2 analyses the most common human openings (those played more than 100,000 times in an online database of human chess games (1)). Each of these openings is independently discovered and played frequently by AlphaZero during self-play training. When starting from each human opening, AlphaZero convincingly defeated Stockfish, suggesting that it has indeed mastered a wide spectrum of chess play.

The game of chess represented the pinnacle of AI research over several decades. State-of-the-art programs are based on powerful engines that search many millions of positions, leveraging handcrafted domain expertise and sophisticated domain adaptations. AlphaZero is a generic reinforcement learning algorithm – originally devised for the game of Go – that achieved superior results within a few hours, searching a thousand times fewer positions, given no domain

3^{3} The prevalence of draws in high-level chess tends to compress the Elo scale, compared to shogi or Go.

A10: English Opening

Figure

w 20/30/0, b 8/40/2

Figure

1...e5 g3 d5 cxd5 ♡f6 ♣g2 ♣xd5 ♡f3

w 16/34/0, b 1/47/2

D06: Queens Gambit

Figure

w 17/33/0, b 5/44/1

Figure

2...c6 ♣c3 ♡f6 ♡f3 a6 g3 c4 a4

A46: Queens Pawn Game

Figure

w 24/26/0, b 3/47/0

Figure

2...d5 c4 e6 ♣c3 ♣e7 ♣f4 O-O e3

E00: Queens Pawn Game

Figure

w 17/33/0, b 5/44/1

Figure

  1. ♡f3 d5 ♣c3 ♣b4 ♣g5 h6 ♣a4 ♣c6

E61: Kings Indian Defence

Figure

w 16/34/0, b 0/48/2

Figure

3...d5 cxd5 ♣xd5 e4 ♣xc3 bxc3 ♣g7 ♣e3

E00: French Defence

Figure

w 39/11/0, b 4/46/0

Figure

  1. ♣c3 ♣f6 e5 ♣d7 f4 c5 ♣f3 ♣e7

B50: Sicilian Defence

Figure

w 17/32/1, b 4/43/3

Figure

3.d4 cxd4 ♣xd4 ♣f6 ♣c3 a6 f3 e5

B30: Sicilian Defence

Figure

w 11/39/0, b 3/46/1

Figure

  1. ♣b5 e6 O-O ♣e7 ♣e1 a6 ♣f1 d5

B40: Sicilian Defence

Figure

w 17/31/2, b 3/40/7

Figure

3.d4 cxd4 ♣xd4 ♣c6 ♣c3 ♣c7 ♣e3 a6

C60: Ruy Lopez (Spanish Opening)

Figure

w 27/22/1, b 6/44/0

Figure

  1. ♣a4 ♣e7 O-O ♣f6 ♣e1 b5 ♣b3 O-O

B10: Caro-Kann Defence

Figure

w 25/25/0, b 4/45/1

Figure

2.d4 d5 e5 ♣f5 ♣f3 e6 ♣e2 a6

A05: Reti Opening

Figure

w 13/36/1, b 7/43/0

Figure

2.c4 e6 d4 d5 ♣c3 ♣e7 ♣f4 O-O

Total games: w 242/353/5, b 48/533/19

Overall percentage: w 40.3/58.8/0.8, b 8.0/88.8/3.2

Table 2: Analysis of the 12 most popular human openings (played more than 100,000 times in an online database (1)). Each opening is labelled by its ECO code and common name. The plot shows the proportion of self-play training games in which AlphaZero played each opening, against training time. We also report the win/draw/loss results of 100 game AlphaZero vs. Stockfish matches starting from each opening, as either white (w) or black (b), from AlphaZero's perspective. Finally, the principal variation (PV) of AlphaZero is provided from each opening.

Figure

Figure 2: Scalability of AlphaZero with thinking time, measured on an Elo scale. a Performance of AlphaZero and Stockfish in chess, plotted against thinking time per move. b Performance of AlphaZero and Elmo in shogi, plotted against thinking time per move.

knowledge except the rules of chess. Furthermore, the same algorithm was applied without modification to the more challenging game of shogi, again outperforming the state of the art within a few hours.

References

  1. Online chess games database, 365chess, 2017. URL: https://www.365chess.com/.

  2. Victor Allis. Searching for Solutions in Games and Artificial Intelligence. PhD thesis, University of Limburg, Netherlands, 1994.

  3. Thomas Anthony, Zheng Tian, and David Barber. Thinking fast and slow with deep learning and tree search. In Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, 4-9 December 2017, Long Beach, CA, USA, pages 5366–5376, 2017.

  4. Oleg Arenz. Monte Carlo chess. Master's thesis, Technische Universität Darmstadt, 2012.

  5. Computer Shogi Association. Results of the 27th world computer shogi championship. http://www2.computer-shogi.org/wcsc27/index_e.html. Retrieved November 29th, 2017.

  6. J. Baxter, A. Tridgell, and L. Weaver. Learning to play chess using temporal differences. Machine Learning, 40(3):243–263, 2000.

  7. Donald F. Beal and Martin C. Smith. Temporal difference learning for heuristic search and game playing. Inf. Sci., 122(1):3–21, 2000.

  8. Donald F. Beal and Martin C. Smith. Temporal difference learning applied to game playing and the results of application to shogi. Theoretical Computer Science, 252(1–2):105–119, 2001.

  9. M. Campbell, A. J. Hoane, and F. Hsu. Deep Blue. Artificial Intelligence, 134:57–83, 2002.

  10. R. Coulom. Whole-history rating: A Bayesian rating system for players of time-varying strength. In International Conference on Computers and Games, pages 113–124, 2008.

  11. Omid E David, Nathan S Netanyahu, and Lior Wolf. Deepchess: End-to-end deep neural network for automatic learning in chess. In International Conference on Artificial Neural Networks, pages 88–96. Springer, 2016.

  12. Kunihito Hoki and Tomoyuki Kaneko. Large-scale optimization for evaluation functions with minimax search. Journal of Artificial Intelligence Research (JAIR), 49:527–568, 2014.

  13. Feng-hsiung Hsu. Behind Deep Blue: Building the Computer that Defeated the World Chess Champion. Princeton University Press, 2002.

  14. Hiroyuki Iida, Makoto Sakuta, and Jeff Rollason. Computer shogi. Artificial Intelligence, 134:121–144, 2002.

  15. Norman P. Jouppi, Cliff Young, Nishant Patil, et al. In-datacenter performance analysis of a tensor processing unit. In Proceedings of the 44th Annual International Symposium on Computer Architecture, ISCA '17, pages 1–12. ACM, 2017.

  16. Tomoyuki Kaneko and Kunihito Hoki. Analysis of evaluation-function learning by comparison of sibling nodes. In Advances in Computer Games - 13th International Conference, ACG 2011, Tilburg, The Netherlands, November 20-22, 2011, Revised Selected Papers, pages 158–169, 2011.

  17. John Knudsen. Essential Chess Quotations. iUniverse, 2000.

  18. D. E. Knuth and R. W. Moore. An analysis of alphabeta pruning. Artificial Intelligence, 6(4):293–326, 1975.

  19. Matthew Lai. Giraffe: Using deep reinforcement learning to play chess. Master's thesis, Imperial College London, 2015.

  20. Emanuel Lasker. Common Sense in Chess. Dover Publications, 1965.

  21. David N. L. Levy and Monty Newborn. How Computers Play Chess. Ishi Press, 2009.

  22. Chris J. Maddison, Aja Huang, Ilya Sutskever, and David Silver. Move evaluation in Go using deep convolutional neural networks. In International Conference on Learning Representations, 2015.

  23. Tony Marsland. Computer chess methods. In S. Shapiro, editor, Encyclopedia of Artificial Intelligence. John Wiley & Sons, New York, 1987.

  24. Raghuram Ramanujan, Ashish Sabharwal, and Bart Selman. Understanding sampling style adversarial search methods. In Proceedings of the 26th Conference on Uncertainty in Artificial Intelligence (UAI), 2010.

  25. Tord Romstad, Marco Costalba, Joona Kiiski, et al. Stockfish: A strong open source chess engine. https://stockfishchess.org/. Retrieved November 29th, 2017.

  26. A. L. Samuel. Some studies in machine learning using the game of checkers II - recent progress. IBM Journal of Research and Development, 11(6):601–617, 1967.

  27. Claude E Shannon. Xxii. programming a computer for playing chess. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 41(314):256–275, 1950.

  28. David Silver, Aja Huang, Chris J. Maddison, Arthur Guez, Laurent Sifre, George van den Driessche, Julian Schrittwieser, Ioannis Antonoglou, Veda Panneershelvam, Marc Lanctot, Sander Dieleman, Dominik Grewe, John Nham, Nal Kalchbrenner, Ilya Sutskever, Timothy Lillicrap, Madeleine Leach, Koray Kavukcuoglu, Thore Graepel, and Demis Hassabis. Mastering the game of Go with deep neural networks and tree search. Nature, 529(7587):484–489, January 2016.

  29. David Silver, Julian Schrittwieser, Karen Simonyan, Ioannis Antonoglou, Aja Huang, Arthur Guez, Thomas Hubert, Lucas Baker, Matthew Lai, Adrian Bolton, Yutian Chen, Timothy Lillicrap, Fan Hui, Laurent Sifre, George van den Driessche, Thore Graepel, and Demis Hassabis. Mastering the game of go without human knowledge. Nature, 550:354–359, 2017.

  30. Wilhelm Steinitz. The Modern Chess Instructor. Edition Olms AG, 1990.

  31. Sebastian Thrun. Learning to play the game of chess. In Advances in neural information processing systems, pages 1069–1076, 1995.

  32. J. Veness, D. Silver, A. Blair, and W. Uther. Bootstrapping from game tree search. In Advances in Neural Information Processing Systems, pages 1937–1945, 2009.

References (64)