Answers.Body: <p>I am not sure what you mean by</p>
  <blockquote>
  <p>There is now multiple ways to represent this same exact game state in my network because each individual card has it's own state. To me this does not seem good.</p>
  </blockquote>
  <p>We can think of game state as a column vector of the form <span class="math-container">$1Xn$</span>. In this case, you can formalize cards held according to some encoding. This can be anything from a Gödel Numbering to simple integer assignment. Here is an example for poker in python: <a href="https://pypi.org/project/treys/" rel="nofollow noreferrer">https://pypi.org/project/treys/</a></p>
  <p>In the example of duplicates you would have a column vector that simply has duplicate indices. I.e: {241, 424, <strong>112, 112</strong>, 455}$</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T02:30:32.853Z
Answers.Text: In this case your column vector has indices indicating the card. I mentioned in my question that this doesn't work well because in order to represent a players hand your column vector is of variable size. Instead consider the column to be a specific card in the game and the indices to be the current state of that card (deck,hand,discard,etc)
Answers.UserDisplayName: ngroover
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T08:30:38.010Z
Answers.Text: @ngroover Why not just pad the vector?
Answers.UserDisplayName: hisairnessag3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-13T12:56:58.883Z
Answers.Text: I guess that's part of my question is lots of padding bad? Does the network even learn correctly if there is more zero padding than actual relevant data? It seems to me that it would not work well
Answers.UserDisplayName: ngroover
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-13T16:08:30.597Z
Answers.Text: @ngroover, well I assume that n cards aren't possible? I.e you can't have 100000 cards. If they aren't just set the pad to the upper bound and 0 or similar encoding will represent a empty card 'slot'. You would only likely run into trouble in training an agent if the possible cards was in the hundreds
Answers.UserDisplayName: hisairnessag3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-10T01:24:36.230Z
Answers.LastActivityDate: 2021-04-01T08:25:24.943Z
Answers.LastEditDate: 2021-04-01T08:25:24.943Z
Answers.UserDisplayName: hisairnessag3
Body: <p>I'm trying create neural network to predict moves in a card game.  I am looking for recommendations on encoding the game state to my input layer.  It's a complex turn based collectible card game (think Magic the Gathering).  I need to represent cards being in various areas of the game board (deck, discard pile, hand, etc).  It seems difficult to assign cards to these areas because the number of cards in these areas is never constant.</p>
  
  <p>I was thinking of an approach where I assign each card in the game to being in a specific card area.  The number of total cards in the game should be constant (let's assume that).  This approach I feel should give me a potentially less sparse input.</p>
  
  <p>Also, With this approach what is the best way to handle card duplicates?  Let's say I have 3 copies of the exact same card in my deck.  Maybe 1 of the copies is in my hand and 2 in my discard pile.  It does not matter which of the 3 copies is in my hand because they are all the same exact card.  There is now multiple ways to represent this same exact game state in my network because each individual card has it's own state.  To me this does not seem good.  How much will this effect my neural network's ability to learn the game?</p>
  
Tags: <neural-networks><game-ai>
Title: How to encode card game state into neural network input
UserDisplayName: ngroover
ThreadText: # How to encode card game state into neural network input
  
  (Asked by: username_0 on 2019-03-09)
  
  I'm trying create neural network to predict moves in a card game. I am looking for recommendations on encoding the game state to my input layer. It's a complex turn based collectible card game (think Magic the Gathering). I need to represent cards being in various areas of the game board (deck, discard pile, hand, etc). It seems difficult to assign cards to these areas because the number of cards in these areas is never constant.
  
  I was thinking of an approach where I assign each card in the game to being in a specific card area. The number of total cards in the game should be constant (let's assume that). This approach I feel should give me a potentially less sparse input.
  
  Also, With this approach what is the best way to handle card duplicates? Let's say I have 3 copies of the exact same card in my deck. Maybe 1 of the copies is in my hand and 2 in my discard pile. It does not matter which of the 3 copies is in my hand because they are all the same exact card. There is now multiple ways to represent this same exact game state in my network because each individual card has it's own state. To me this does not seem good. How much will this effect my neural network's ability to learn the game?
  
  **Tags:** neural-networks, game-ai
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-10. Score: 1
  
  I am not sure what you mean by
  
  > There is now multiple ways to represent this same exact game state in my network because each individual card has it's own state. To me this does not seem good.
  
  We can think of game state as a column vector of the form $1Xn$. In this case, you can formalize cards held according to some encoding. This can be anything from a Gödel Numbering to simple integer assignment. Here is an example for poker in python: <https://pypi.org/project/treys/>
  
  In the example of duplicates you would have a column vector that simply has duplicate indices. I.e: {241, 424, **112, 112**, 455}$
  
  > **Comments:**
  > **username_0**: In this case your column vector has indices indicating the card. I mentioned in my question that this doesn't work well because in order to represent a players hand your column vector is of variable size. Instead consider the column to be a specific card in the game and the indices to be the current state of that card (deck,hand,discard,etc)  
  > **username_1**: @username_0 Why not just pad the vector?  
  > **username_0**: I guess that's part of my question is lots of padding bad? Does the network even learn correctly if there is more zero padding than actual relevant data? It seems to me that it would not work well  
  > **username_1**: @username_0, well I assume that n cards aren't possible? I.e you can't have 100000 cards. If they aren't just set the pad to the upper bound and 0 or similar encoding will represent a empty card 'slot'. You would only likely run into trouble in training an agent if the possible cards was in the hundreds  
  
  ---
  
  