code: def simulate_game(
      model,
      state: torch.Tensor,
      t_time: int,
      max_steps: int,
      game_tree: Dict,
      states_dict: Dict,
      horizon: int = 5,
  ):
      """Simulates a game from a given state.
  
      Args:
          model: The model to use for the simulation.
          state (torch.Tensor): The initial state.
          t_time (int): The current time step.
          max_steps (int): The maximum number of steps to simulate.
          game_tree (Dict): The game tree.
          states_dict (Dict): The states dictionary.
          horizon (int): The horizon to use for the simulation.
      """
      idx = t_time
      max_steps = min(max_steps, t_time + horizon)
      state_hash = to_hash(extract_present_state(state))
      trajectory = []
      # selection
      while state_hash in game_tree:
          (
              possible_states_dict,
              old_idx_to_new_idx,
              repetition_map,
              N_s_a,
              q_values,
              actions,
          ) = states_dict[state_hash]
          possible_states = _recompose_possible_states(
              possible_states_dict
          )
          state_idx = select_future_state(
              possible_states,
              q_values,
              N_s_a,
              repetition_map,
              return_idx=True,
          )
          trajectory.append(
              (state_hash, state_idx)
          )  # state_hash, action_idx
          future_state = extract_present_state(
              possible_states[state_idx]
          )
          state = possible_states[state_idx]
          state_hash = to_hash(future_state)
          idx += 1
  
      # expansion
      if idx <= max_steps:
          trajectory.append((state_hash, None))
          if not game_is_finished(extract_present_state(state)):
              state = state.to(model.device)
              scalars = get_scalars(state, idx).to(state.device)
              actions, probs, q_values = model(state, scalars)
              (
                  possible_states,
                  cloned_idx_to_idx,
                  repetitions,
                  not_dupl_indexes,
              ) = extract_children_states_from_actions(
                  state,
                  actions,
              )
              not_dupl_actions = actions[:, not_dupl_indexes].to("cpu")
              not_dupl_q_values = torch.zeros(
                  not_dupl_actions.shape[:-1]
              ).to("cpu")
              N_s_a = torch.zeros_like(not_dupl_q_values).to("cpu")
              present_state = extract_present_state(state)
              states_dict[to_hash(present_state)] = (
                  _reduce_memory_consumption_before_storing(
                      possible_states
                  ),
                  cloned_idx_to_idx,
                  repetitions,
                  N_s_a,
                  not_dupl_q_values,
                  not_dupl_actions,
              )
              game_tree[to_hash(present_state)] = [
                  to_hash(extract_present_state(fut_state))
                  for fut_state in possible_states
              ]
              leaf_q_value = q_values
      else:
          leaf_q_value = -int(torch.linalg.matrix_rank(state).sum())
      # backup
      backward_pass(trajectory, states_dict, leaf_q_value=leaf_q_value)
  
file_path: nebuly/optimization/open_alpha_tensor/open_alpha_tensor/core/actors/stage.py
imports: from typing import Dict, List
  import torch
  from open_alpha_tensor.core.data.utils import get_scalars, map_action_to_triplet
  from open_alpha_tensor.core.modules.alpha_tensor import AlphaTensorModel
label_desc: Use image node_id 11 for calling a global function with example usage: simulate_game(model, state, t_time, max_steps, game_tree, states_dict, horizon) without return types