Answers.Body: <p>Great question!  NN is very promising for this type of problem: <a href="https://arxiv.org/pdf/1509.01549.pdf" rel="nofollow noreferrer">Giraffe Chess</a>.  Lai's accomplishment <a href="https://www.technologyreview.com/s/541276/deep-learning-machine-teaches-itself-chess-in-72-hours-plays-at-international-master/" rel="nofollow noreferrer">was considered to be a pretty big deal</a>, but unfortunately came just a few months before AlphaGo took the spotlight. <em>(It all turned out well, in that Lai was subsequently hired by DeepMind, <a href="https://motherboard.vice.com/en_us/article/the-chess-engine-that-died-so-alphago-could-live-giraffe-matthew-lai" rel="nofollow noreferrer">although not so well for the Giraffe engine</a>;)</em></p>
  
  <p>I've found Lai's approach to be quite helpful, and it is backed by solid results.</p>
  
  <hr>
  
  <p>You may want to use "<a href="https://en.wikipedia.org/wiki/Sequential_game" rel="nofollow noreferrer">sequential</a>" as opposed to "round based" since sequential is the preferred term in <a href="https://en.wikipedia.org/wiki/Game_theory" rel="nofollow noreferrer">Game Theory</a> and <a href="https://en.wikipedia.org/wiki/Combinatorial_game_theory" rel="nofollow noreferrer">Combinatorial Game Theory</a>, and these are the fields that apply mathematical analysis to games. </p>
  
  <p>The games you list are further termed "<a href="https://en.wikipedia.org/wiki/Abstract_strategy_game" rel="nofollow noreferrer">abstract</a>" to distinguish them from modern strategy boardgames, or games in general, which utilize a strong theme and are generally less compact than abstract games in terms of mechanics and elements. This carries the caveat that abstract games are not restricted to sequential games or boardgames, or even games specifically, as in the case of puzzles like Sudoku.</p>
  
  <p>The formal name for this group of games is generally "<a href="https://en.wikipedia.org/wiki/Partisan_game" rel="nofollow noreferrer">partisan</a>, sequential, <a href="http://library.msri.org/books/Book29/contents.html" rel="nofollow noreferrer">deterministic</a>, <a href="https://en.wikipedia.org/wiki/Perfect_information#Examples" rel="nofollow noreferrer">perfect information</a>" with the further categorization of Tic-Tac-Toe as "trivial" (solved and easily solvable) and non-trivial (intractable and unsolved) for games like Chess and Go. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-06-19T21:07:40.203Z
Answers.LastActivityDate: 2019-04-19T19:14:01.967Z
Answers.LastEditDate: 2019-04-19T19:14:01.967Z
Answers.UserDisplayName: DukeZhou
Answers.Body: <p>I'm a chess player and my answer will be only on chess.</p>
  <p>Training a neural network with reinforcement learning isn't new, it has been done many times in the literature.</p>
  <p>I'll briefly explain the common strategies.</p>
  <ul>
  <li><p>The purpose of a network is to learn <strong>position evaluation.</strong> We all know a queen is stronger than a bishop, but can we make the network know about it without explicitly programming? What about pawn structure? Does the network understand how to evaluate whether a position is winning or not?</p>
  </li>
  <li><p>Now, we know why we need the network, we'll need to design it. The design differs radically between studies. Before deep learning was popular, people were using the shallow network. Nowadays, a network with many layers stands out.</p>
  </li>
  <li><p>Once we have the network, you'll need to make a chess engine. Neural network can't magically play chess by itself, it needs to connect to a chess engine. Fortunately, we don't need to write position evaluation code because the network can do that for us.</p>
  </li>
  <li><p>Now, we have to play games. We could start with some high-quality chess databases or instead have our AI agent play games with another player (e.g. itself, another AI agent, or a human). This is known as <strong>reinforcement learning</strong>.</p>
  </li>
  <li><p>While we play games, we update the network parameter. This can be done by stochastic gradient descent (or other similar techniques). We repeat our training as long as we want, usually over millions of iterations.</p>
  </li>
  <li><p>Finally, we have a trained neural network model for chess!</p>
  </li>
  </ul>
  <p>Look at the following resources for details:</p>
  <blockquote>
  <p><a href="https://www.chessprogramming.org/Learning" rel="nofollow noreferrer">https://www.chessprogramming.org/Learning</a></p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-05-20T04:25:37.720Z
Answers.LastActivityDate: 2023-05-23T04:58:27.410Z
Answers.LastEditDate: 2023-05-23T04:58:27.410Z
Answers.UserDisplayName: SmallChess
Answers.Body: <p>I think you should get familiar with reinforcement learning. In this field of machine learning the agent interacts whit its environment and after that the agent gets some reward. Now, the agent is the neural network the environment is the game and the agent can get a reward +1 if it wins or -1 if loses. You can use this state, action, reward experienc tuple to train the agent.  I can recommend David Silver's lectures on youtube and Sutton's book as well. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T19:02:44.060Z
Answers.LastActivityDate: 2017-11-10T06:19:16.423Z
Answers.LastEditDate: 2017-11-10T06:19:16.423Z
Answers.UserDisplayName: Molnár István
Body: <p>I'm wondering how to train a neural network for a round based board game like, tic-tac-toe, chess, risk or any other round based game.
  Getting the next move by inference seems to be pretty straight forward, by feeding the game state as input and using the output as the move for the current player.
  However training an AI for that purpose doesn't appear to be that straight forward, because:</p>
  
  <ol>
  <li>There might not be a rating if a single move is good or not, so training of single moves doesn't seem to be the right choice</li>
  <li>Using all game states (inputs) and moves (outputs) of the whole game to train the neural network, doesn't seem to be the right choice as not all moves within a lost game might be bad</li>
  </ol>
  
  <p>So I'm wondering how to train a neural network for a round based board game?
  I would like to create a neural network for tic-tac-toe using tensorflow.</p>
  
Tags: <training><tensorflow><game-ai>
Title: How to train a neural network for a round based board game?
UserDisplayName: soriak
ThreadText: # How to train a neural network for a round based board game?
  
  (Asked by: username_0 on 2017-05-19)
  
  I'm wondering how to train a neural network for a round based board game like, tic-tac-toe, chess, risk or any other round based game.
  Getting the next move by inference seems to be pretty straight forward, by feeding the game state as input and using the output as the move for the current player.
  However training an AI for that purpose doesn't appear to be that straight forward, because:
  
  1. There might not be a rating if a single move is good or not, so training of single moves doesn't seem to be the right choice
  2. Using all game states (inputs) and moves (outputs) of the whole game to train the neural network, doesn't seem to be the right choice as not all moves within a lost game might be bad
  
  So I'm wondering how to train a neural network for a round based board game?
  I would like to create a neural network for tic-tac-toe using tensorflow.
  
  **Tags:** training, tensorflow, game-ai
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2017-06-19. Score: 10
  
  Great question! NN is very promising for this type of problem: [Giraffe Chess](https://arxiv.org/pdf/1509.01549.pdf). Lai's accomplishment [was considered to be a pretty big deal](https://www.technologyreview.com/s/541276/deep-learning-machine-teaches-itself-chess-in-72-hours-plays-at-international-master/), but unfortunately came just a few months before AlphaGo took the spotlight. *(It all turned out well, in that Lai was subsequently hired by DeepMind, [although not so well for the Giraffe engine](https://motherboard.vice.com/en_us/article/the-chess-engine-that-died-so-alphago-could-live-giraffe-matthew-lai);)*
  
  I've found Lai's approach to be quite helpful, and it is backed by solid results.
  
  ---
  
  You may want to use "[sequential](https://en.wikipedia.org/wiki/Sequential_game)" as opposed to "round based" since sequential is the preferred term in [Game Theory](https://en.wikipedia.org/wiki/Game_theory) and [Combinatorial Game Theory](https://en.wikipedia.org/wiki/Combinatorial_game_theory), and these are the fields that apply mathematical analysis to games.
  
  The games you list are further termed "[abstract](https://en.wikipedia.org/wiki/Abstract_strategy_game)" to distinguish them from modern strategy boardgames, or games in general, which utilize a strong theme and are generally less compact than abstract games in terms of mechanics and elements. This carries the caveat that abstract games are not restricted to sequential games or boardgames, or even games specifically, as in the case of puzzles like Sudoku.
  
  The formal name for this group of games is generally "[partisan](https://en.wikipedia.org/wiki/Partisan_game), sequential, [deterministic](http://library.msri.org/books/Book29/contents.html), [perfect information](https://en.wikipedia.org/wiki/Perfect_information#Examples)" with the further categorization of Tic-Tac-Toe as "trivial" (solved and easily solvable) and non-trivial (intractable and unsolved) for games like Chess and Go.
  
  
  ---
  
  ### Answer by username_2 on 2017-05-20. Score: 7
  
  I'm a chess player and my answer will be only on chess.
  
  Training a neural network with reinforcement learning isn't new, it has been done many times in the literature.
  
  I'll briefly explain the common strategies.
  
  * The purpose of a network is to learn **position evaluation.** We all know a queen is stronger than a bishop, but can we make the network know about it without explicitly programming? What about pawn structure? Does the network understand how to evaluate whether a position is winning or not?
  * Now, we know why we need the network, we'll need to design it. The design differs radically between studies. Before deep learning was popular, people were using the shallow network. Nowadays, a network with many layers stands out.
  * Once we have the network, you'll need to make a chess engine. Neural network can't magically play chess by itself, it needs to connect to a chess engine. Fortunately, we don't need to write position evaluation code because the network can do that for us.
  * Now, we have to play games. We could start with some high-quality chess databases or instead have our AI agent play games with another player (e.g. itself, another AI agent, or a human). This is known as **reinforcement learning**.
  * While we play games, we update the network parameter. This can be done by stochastic gradient descent (or other similar techniques). We repeat our training as long as we want, usually over millions of iterations.
  * Finally, we have a trained neural network model for chess!
  
  Look at the following resources for details:
  
  > <https://www.chessprogramming.org/Learning>
  
  
  ---
  
  ### Answer by username_3 on 2017-05-19. Score: 4
  
  I think you should get familiar with reinforcement learning. In this field of machine learning the agent interacts whit its environment and after that the agent gets some reward. Now, the agent is the neural network the environment is the game and the agent can get a reward +1 if it wins or -1 if loses. You can use this state, action, reward experienc tuple to train the agent. I can recommend David Silver's lectures on youtube and Sutton's book as well.
  
  
  ---
  
  