title: Transforming game tree to the list of players' behavior
body: <p>Consider a game in which <code>N</code> players compete for some prize</p>
  <p>players are numbered <code>1</code> to <code>N</code>, have <code>A1...AN</code> amounts of money and make moves in a circle</p>
  <p>player <code>1</code> is the first to act</p>
  <p>he can either bet amount <code>a1&lt;=A1</code> or pass the turn to player <code>2</code></p>
  <p>if player <code>1</code> bets, then player <code>2</code> can put a bigger bet a2&gt;a1, given that <code>a2&lt;=A2</code>, or pass</p>
  <p>the next player can put a bigger bet <code>a3&gt;a2</code>, given that <code>a3&lt;=A3</code>, or pass and so son</p>
  <p>if the move returns to player <code>1</code>, he can add money to his bet so that <code>(a1+added money)&gt;ai</code> where <code>ai</code> is the last bet made, given that <code>a1+added money&lt;=A1</code></p>
  <p>each player is limited to <code>2</code> actions per game</p>
  <p>The game description consists of</p>
  <ul>
  <li><p>the player list where each item contains the <code>player ID</code>, his position(<code>1...N</code>), and his initial amount of money</p>
  </li>
  <li><p>the ordered action list where each item contains the <code>player ID</code>, the <code>action</code>(bet/pass), and the <code>amount</code> of the bet if any</p>
  </li>
  </ul>
  <p>Example:</p>
  <p>Player List:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">PlayerId</th>
  <th style="text-align: left;">Position</th>
  <th style="text-align: left;">Amount</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">P1</td>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">60</td>
  </tr>
  <tr>
  <td style="text-align: left;">P2</td>
  <td style="text-align: left;">2</td>
  <td style="text-align: left;">140</td>
  </tr>
  <tr>
  <td style="text-align: left;">P3</td>
  <td style="text-align: left;">3</td>
  <td style="text-align: left;">90</td>
  </tr>
  <tr>
  <td style="text-align: left;">P4</td>
  <td style="text-align: left;">4</td>
  <td style="text-align: left;">200</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Action List:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">PlayerId</th>
  <th style="text-align: left;">Action</th>
  <th style="text-align: left;">Amount</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">P1</td>
  <td style="text-align: left;">bet</td>
  <td style="text-align: left;">20</td>
  </tr>
  <tr>
  <td style="text-align: left;">P2</td>
  <td style="text-align: left;">pass</td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">P3</td>
  <td style="text-align: left;">raise</td>
  <td style="text-align: left;">30</td>
  </tr>
  <tr>
  <td style="text-align: left;">P4</td>
  <td style="text-align: left;">raise</td>
  <td style="text-align: left;">40</td>
  </tr>
  <tr>
  <td style="text-align: left;">P1</td>
  <td style="text-align: left;">raise</td>
  <td style="text-align: left;">60</td>
  </tr>
  <tr>
  <td style="text-align: left;">P3</td>
  <td style="text-align: left;">pass</td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">P4</td>
  <td style="text-align: left;">pass</td>
  <td style="text-align: left;"></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Given the game description as the input, I want to transform it to the
  list of N items where each item describes the player's behavior in the game:</p>
  <ul>
  <li>PlayerId,</li>
  <li>Could Bet First(true if a player had the opportunity to start betting, false otherwise),</li>
  <li>Bet First (true if a player started betting, false otherwise)</li>
  <li>Could Raise(true if a player had the opportunity to raise the previous bet, false otherwise),</li>
  <li>Raised(true if a player had the opportunity to raise the previous bet, false otherwise),</li>
  <li>Could Re-raise(true if a player had the opportunity to re-raise, false otherwise),</li>
  <li>Re-raised(true if a player bet first, was raised, and re-raised, false otherwise),</li>
  <li>Number of times player was active(bet, raised, or reraised)</li>
  <li>The total amount of money the player put in the game</li>
  </ul>
  <p>The output for the aforementioned example should be:</p>
  <ul>
  <li>P1, True, True, False, False, True, True, 2, 60</li>
  <li>P2, False, False, False, False, False, False, 0, 0</li>
  <li>P3, False, False, True, True, True, False, 1, 30</li>
  <li>P4, False, False, True, True, True, False, 1, 40</li>
  </ul>
  <p>Ideally, the code would go through the list of actions once and build the desired outcome by updating the player's stat objects with each action. Can anyone suggest an algorithm for solving this problem?</p>