class_docstr: A state-settable environment for Tic-Tac-Toe game.
  
  For MCTS/AlphaZero, we need to keep states of the environment in a node and
  later restore them once MCTS selects which node to visit. This requires
  calling into get_state() and set_state() functions.
  
  The states are a 3 x 3 array where 0 = empty, 1 = player, 2 = opponent.
  The action is a 2-d vector to indicate the position for the player's move.
class_docstr_tok: ["A","state-settable","environment","for","Tic-Tac-Toe","game",".","For","MCTS\/AlphaZero",",","we","need","to","keep","states","of","the","environment","in","a","node","and","later","restore","them","once","MCTS","selects","which","node","to","visit",".","This","requires","calling","into","get_state","(",")","and","set_state","(",")","functions",".","The","states","are","a","3","x","3","array","where","0","=","empty",",","1","=","player",",","2","=","opponent",".","The","action","is","a","2-d","vector","to","indicate","the","position","for","the","player","'s","move","."]
docstr: Check if the given states are final and calculate reward.
  
  Args:
    states: states of the board.
  
  Returns:
    A tuple of (is_final, reward) where is_final means whether the states
    are final are not, and reward is the reward for stepping into the states
    The meaning of reward: 0 = not decided or draw, 1 = win, -1 = loss
docstr_tok: ["Check","if","the","given","states","are","final","and","calculate","reward",".","Args",":","states",":","states","of","the","board",".","Returns",":","A","tuple","of","(","is_final",",","reward",")","where","is_final","means","whether","the","states","are","final","are","not",",","and","reward","is","the","reward","for","stepping","into","the","states","The","meaning","of","reward",":","0","=","not","decided","or","draw",",","1","=","win",",","-1","=","loss"]
code: def _check_states(self, states: np.ndarray):
      """Check if the given states are final and calculate reward.
  
      Args:
        states: states of the board.
  
      Returns:
        A tuple of (is_final, reward) where is_final means whether the states
        are final are not, and reward is the reward for stepping into the states
        The meaning of reward: 0 = not decided or draw, 1 = win, -1 = loss
      """
      seqs = np.array(
          [
              # each row
              states[0, :],
              states[1, :],
              states[2, :],
              # each column
              states[:, 0],
              states[:, 1],
              states[:, 2],
              # diagonal
              states[(0, 1, 2), (0, 1, 2)],
              states[(2, 1, 0), (0, 1, 2)],
          ]
      )
      seqs = seqs.tolist()
      if [1, 1, 1] in seqs:
          return True, TicTacToeEnvironment.REWARD_WIN  # win
      if [2, 2, 2] in seqs:
          return True, TicTacToeEnvironment.REWARD_LOSS  # loss
      if 0 in states:
          # Not final
          return False, TicTacToeEnvironment.REWARD_DRAW_OR_NOT_FINAL
      return True, TicTacToeEnvironment.REWARD_DRAW_OR_NOT_FINAL
  
file_path: agents/tf_agents/environments/examples/tic_tac_toe_environment.py
imports: import copy
  import numpy
  from tf_agents.environments import py_environment
  from tf_agents.specs import BoundedArraySpec
  from tf_agents.trajectories.time_step import StepType
  from tf_agents.trajectories.time_step import TimeStep
label_desc: Use image node_id 10 for calling the TicTacToeEnvironment obj's underlying member method code with example usage: obj._check_states(states) and returns: True,  TicTacToeEnvironment, True,  TicTacToeEnvironment, True,  TicTacToeEnvironment, False,  TicTacToeEnvironment