Answers.Body: <p>The core of the question seems to really be: "how to approach thinking about this", where "this" is the input of an AI player.</p>
  
  <p>Modern attempts at game playing AI players try to replace a human player "as is". No advantage whatsoever. This implies that we want to feed the same "raw input" to the software player and to the human player. For a video game, the raw input is usually the screen we see, but it could also include sound, vibration feedback from a game controller, force feedback from driving gears, etc. Basically any sensor input available. For a physical board game like Go, the raw input could be a video feed, as done for <a href="https://www.youtube.com/watch?v=vFr3K2DORc8" rel="nofollow noreferrer">AlphaGo</a>. Doing so, we fall back to the video game approach. So the input to the AI player is often a tensor, where each element is the intensity of a screen pixel, or some other sensor signal (note there is nothing here about the shape of the tensor, please see below).</p>
  
  <p>The way of thinking here is actually pretty simple, and neat: We want an AI player to replace a human player. So we list up what the human player can sense, and model each input as a tensor (this includes vectors and matrices).</p>
  
  <p>There is perhaps a subtlety here. We face choices not so obvious to make, and there are usually trials and errors (many errors). For example, the Deep-Q Network from DeepMind to play Atari games takes as input <em>differences</em> between two consecutive video frames. Some other approach could solve the same problem with actual <em>sequences</em> of inputs (e.g. 10 consecutive frames). The two approaches are valid---they just have different tradeoffs we must evaluate to find the best configuration.</p>
  
  <p>Another subtelty is the "shape" of the input. Should a single (W, H) input frame be a (W*H) vector, or a (W, H) matrix, or something else? The ramifications can go far. If the frame is an RGB frame with transparency, the input could well be a tensor of shape (W, H, 4), a "cubic volume" with 4 "slices" of shape (W, H)---one for each RGB channel, and a fourth one for transparency. Imagine now if you also have sound, and can add a fifth "slice"---and more if you have stereo or Dolby system channels.</p>
  
  <p>Last point: There is no reference to the architecture of the AI player beyond the input here. Although most exemples refer to recent architectures based on neural networks, this "thinking" also applies whatever can leverage the input. For example, the Big Blue system from IBM, who won Chess against Gary Kasparov, is an AI player using exclusively (if my memory's good) clever tree search. Yet its input is a tensor representing the Chess board.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-27T13:26:14.883Z
Answers.LastActivityDate: 2018-05-27T13:26:14.883Z
Answers.UserDisplayName: Eric Platon
Body: <p>I've seen data sets for classification / regressions tasks in domains such as credit default detection, object identification in an image, stock price prediction etc.  All of these data sets could simply be represented as an input matrix of size (n_samples, n_features) and fed into your machine learning algorithm to ultimately yield a trained model offering some predictive capability.  Intuitively and mathematically this makes sense to me.</p>
  <p>However, I'm really struggling with how to think about the structure of an input matrix for game-like tasks (Chess, Go, <a href="https://www.youtube.com/watch?v=Ipi40cb_RsI" rel="nofollow noreferrer">Seth Blings Mario Kart AI</a>) specifically (using the Chess example):</p>
  <ol>
  <li><p>How would you encode the state of the board to something that a model could train on?  Is it reasonable to think about the board state as a 8x8 matrix (or 1x64) vector with each point being encoded by a numerical value dependent on the type of piece and color?</p>
  </li>
  <li><p>Assuming a suitable representation of the board state, how would the model be capable of making a recommendation given that each piece type moves differently?  Would it not have to evaluate the different move possibilities for each piece and propose which move it &quot;thinks&quot; would have the best long term outcome for the game?</p>
  </li>
  <li><p>A follow up on 2 - given the interplay between a moves made now and moves made n moves into the future how would the model be able to recognize and make trade-offs between moves which may offer a better position now vs those that offer a position n moves in the future - would one have to extend the board state input to a vector of length 1x64n where n is the total number of moves for expected for an individual player or is this a function of a different algorithm which should be able to capture historical information which training?</p>
  </li>
  </ol>
  <p>I am unsure if I'm overthinking this and am missing something really obvious but I would appreciate any guidance in terms of how to approach thinking about this.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-03T17:32:39.937Z
Comments.Text: Welcome to AI!  Very good questions, imo.  *(I've taken the liberty of adding a couple of tags to improve searchability.)*
Comments.UserDisplayName: DukeZhou
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-12T15:40:48.383Z
Comments.Text: Update:  I've come across [this](https://karpathy.github.io/2016/05/31/rl/) blog post which runs through Reinforcement Learning and tackles almost all of the questions listed in the original post.  I'm unsure if encoding the game in pixels would still work given the complexity with pieces and their unique movements but it's a start.
Comments.UserDisplayName: ZYH
Tags: <deep-learning><ai-design><training><combinatorial-games><chess>
Title: How would you encode your input vector/matrix from a sequence of moves in game like tasks to train an AI? e.g. Chess AI?
UserDisplayName: ZYH
ThreadText: # How would you encode your input vector/matrix from a sequence of moves in game like tasks to train an AI? e.g. Chess AI?
  
  (Asked by: username_0 on 2018-01-03)
  
  I've seen data sets for classification / regressions tasks in domains such as credit default detection, object identification in an image, stock price prediction etc. All of these data sets could simply be represented as an input matrix of size (n\_samples, n\_features) and fed into your machine learning algorithm to ultimately yield a trained model offering some predictive capability. Intuitively and mathematically this makes sense to me.
  
  However, I'm really struggling with how to think about the structure of an input matrix for game-like tasks (Chess, Go, [Seth Blings Mario Kart AI](https://www.youtube.com/watch?v=Ipi40cb_RsI)) specifically (using the Chess example):
  
  1. How would you encode the state of the board to something that a model could train on? Is it reasonable to think about the board state as a 8x8 matrix (or 1x64) vector with each point being encoded by a numerical value dependent on the type of piece and color?
  2. Assuming a suitable representation of the board state, how would the model be capable of making a recommendation given that each piece type moves differently? Would it not have to evaluate the different move possibilities for each piece and propose which move it "thinks" would have the best long term outcome for the game?
  3. A follow up on 2 - given the interplay between a moves made now and moves made n moves into the future how would the model be able to recognize and make trade-offs between moves which may offer a better position now vs those that offer a position n moves in the future - would one have to extend the board state input to a vector of length 1x64n where n is the total number of moves for expected for an individual player or is this a function of a different algorithm which should be able to capture historical information which training?
  
  I am unsure if I'm overthinking this and am missing something really obvious but I would appreciate any guidance in terms of how to approach thinking about this.
  
  **Tags:** deep-learning, ai-design, training, combinatorial-games, chess
  
  > **Comments:**
  > **username_1**: Welcome to AI!  Very good questions, imo.  *(I've taken the liberty of adding a couple of tags to improve searchability.)*  
  > **username_0**: Update:  I've come across [this](https://karpathy.github.io/2016/05/31/rl/) blog post which runs through Reinforcement Learning and tackles almost all of the questions listed in the original post.  I'm unsure if encoding the game in pixels would still work given the complexity with pieces and their unique movements but it's a start.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-05-27. Score: 2 | Accepted answer
  
  The core of the question seems to really be: "how to approach thinking about this", where "this" is the input of an AI player.
  
  Modern attempts at game playing AI players try to replace a human player "as is". No advantage whatsoever. This implies that we want to feed the same "raw input" to the software player and to the human player. For a video game, the raw input is usually the screen we see, but it could also include sound, vibration feedback from a game controller, force feedback from driving gears, etc. Basically any sensor input available. For a physical board game like Go, the raw input could be a video feed, as done for [AlphaGo](https://www.youtube.com/watch?v=vFr3K2DORc8). Doing so, we fall back to the video game approach. So the input to the AI player is often a tensor, where each element is the intensity of a screen pixel, or some other sensor signal (note there is nothing here about the shape of the tensor, please see below).
  
  The way of thinking here is actually pretty simple, and neat: We want an AI player to replace a human player. So we list up what the human player can sense, and model each input as a tensor (this includes vectors and matrices).
  
  There is perhaps a subtlety here. We face choices not so obvious to make, and there are usually trials and errors (many errors). For example, the Deep-Q Network from DeepMind to play Atari games takes as input *differences* between two consecutive video frames. Some other approach could solve the same problem with actual *sequences* of inputs (e.g. 10 consecutive frames). The two approaches are valid---they just have different tradeoffs we must evaluate to find the best configuration.
  
  Another subtelty is the "shape" of the input. Should a single (W, H) input frame be a (W\*H) vector, or a (W, H) matrix, or something else? The ramifications can go far. If the frame is an RGB frame with transparency, the input could well be a tensor of shape (W, H, 4), a "cubic volume" with 4 "slices" of shape (W, H)---one for each RGB channel, and a fourth one for transparency. Imagine now if you also have sound, and can add a fifth "slice"---and more if you have stereo or Dolby system channels.
  
  Last point: There is no reference to the architecture of the AI player beyond the input here. Although most exemples refer to recent architectures based on neural networks, this "thinking" also applies whatever can leverage the input. For example, the Big Blue system from IBM, who won Chess against Gary Kasparov, is an AI player using exclusively (if my memory's good) clever tree search. Yet its input is a tensor representing the Chess board.
  
  
  ---
  
  