class_docstr: ## [History](../index.html#History)
  
  This defines when a game ends, calculates the utility and sample chance events (dealing cards).
  
  The history is stored in a string:
  
  * First two characters are the cards dealt to player 1 and player 2
  * The third character is the action by the first player
  * Fourth character is the action by the second player
docstr: Calculate the terminal utility for player $1$,  $u_1(z)$
docstr_tok: ["Calculate","the","terminal","utility","for","player","$","1","$",",","$","u_1","(","z",")","$"]
code: def _terminal_utility_p1(self) -> float:
      """
      Calculate the terminal utility for player $1$,  $u_1(z)$
      """
      # $+1$ if Player 1 has a better card and $-1$ otherwise
      winner = -1 + 2 * (self.history[0] < self.history[1])
  
      # Second player passed
      if self.history[-2:] == "bp":
          return 1
      # Both players called, the player with better card wins $2$ chips
      elif self.history[-2:] == "bb":
          return winner * 2
      # First player passed, the player with better card wins $1$ chip
      elif self.history[-1] == "p":
          return winner
      # History is non-terminal
      else:
          raise RuntimeError()
  
imports: from typing import List, cast, Dict
  import numpy
  from labml import experiment
  from labml.configs import option
  from labml_nn.cfr import History, InfoSet, Action, Player, CFRConfigs
  from labml_nn.cfr.infoset_saver import InfoSetSaver
label_desc: Use image node_id 3 for calling the History obj's underlying member method code with example usage: obj._terminal_utility_p1() and returns: int, unknown, winner