Ejemplo n.º 1
0
const size_t* ForwardDeadReckoningPropnetStateMachine::Simulate6(const StateType& s)
{
  StateType temp = StateType();
  MoveType m = MoveType();
  temp.Equate(s);

  size_t role_id = 0;

  for(size_t i = 0;i < role_size;i++)
  {
    if(alt_role_masks[i] & temp)
    {
      role_id = i;
      break;
    }
  }

  while(!role_propnets[role_id].Update(temp, *role_propnet_payloads[role_id]))
  {
    role_propnets[role_id].GetRandomLegalMove(*role_propnet_payloads[role_id], m);

    role_propnets[role_id].Update(m, *role_propnet_payloads[role_id]);

    temp.Equate(role_propnet_payloads[role_id]->GetState());

    role_id = ++role_id % role_size;

    //cout << m << endl;
    //cout << temp << endl;
  }

  return GetGoals(temp);
}
Ejemplo n.º 2
0
const size_t* ForwardDeadReckoningPropnetStateMachine::Simulate5(const StateType& s)
{
  StateType temp;
  MoveType m;
  temp.Equate(s);

  while(!initial_pn.Update(temp, *initial_pn_payload))
  {
    initial_pn.GetRandomLegalMove(*initial_pn_payload, m);

    initial_pn.Update(m, *initial_pn_payload);

    temp.Equate(initial_pn_payload->GetState());
  }

  return GetGoals(temp);
}
Ejemplo n.º 3
0
const size_t* ForwardDeadReckoningPropnetStateMachine::Simulate2(const StateType& s)
{
  StateType temp;
  temp.Equate(s);

  size_t state_index = 0;
  bool isLoop = true;
  bool isLoop2 = true;

  size_t t;

  //cout << "testing-2" << endl;

  StateType top = without_terminal_payload->top;
  MoveSet* m_set = without_terminal_payload->m_set;

  while(!without_terminal_payload->terminal)
  {
    //cout << "testing-1" << endl;

    without_terminal_pn->Update2(temp, *without_terminal_payload);

    //cout << "testing-4" << endl;

    for(size_t i = 0;i < role_size;i++)
    {
      //cout << *m_set[i].begin() << endl;
      simulate2_it[i] = m_set[i].begin();
//      if(m_set[i].begin() == m_set[i].end())
//      {
//        std::cout << s << std::endl;
//        std::cout << LOGID << ": lol" << endl;
//        size_t t;
//        std::cin >> t;
//      }
    }

    state_index = 0;
    isLoop2 = true;
    while(isLoop2)
    {
      //cout << "testing" << endl;

      without_terminal_pn->Update3(simulate2_it, *without_terminal_payload);

      //cout << "testing1" << endl;

      //std::cout << without_terminal_payload->top << std::endl;

      //std::cin >> t;

      if(IsTerminal_compiled(top, GetGoals_buff))
      {
        return GetGoals(top);
      }
      else simulate2_state_arr[state_index++].Equate(top);

      //cout << "testing2" << endl;

      size_t index = 0;
      while(true)
      {
        simulate2_it[index]++;
        if(simulate2_it[index] == m_set[index].end())
        {
          if(index == role_size - 1)
          {
            isLoop2 = false;
            break;
          }
          simulate2_it[index] = m_set[index].begin();
          index++;
        }
        else break;
      }
    }

    //cout << "testing3" << endl;

    size_t rnd = rand() % state_index;
    temp.Equate(simulate2_state_arr[rnd]);

    //std::cout << temp << std::endl;

    //std::cin >> t;
  }

  return GetGoals(temp);
}
Ejemplo n.º 4
0
void ForwardDeadReckoningPropnetStateMachine::MetaGame_multi_player(size_t simulation_time)
{
  isZeroSumGame = true;
  isAlternatingMoves = true;

  size_t num_simulations = 0;

  size_t stop = util::Timer::microtimer() + simulation_time;

  StateType temp;
  for(size_t i = 0;i < core::RawAState::arr_size;i++)
    temp->s[i] = 255;

  alt_role_masks = new StateType[role_size];
  for(size_t i = 0;i < role_size;i++)
    alt_role_masks[i] = temp.Clone();

  while(util::Timer::microtimer() < stop)
  {
    StateType temp = InitState().Clone();

    MoveType m;

    while(!initial_pn.Update(temp, *initial_pn_payload))
    {
      if(isAlternatingMoves)
      {
        int current_control_r_id = -1;

        for(size_t i = 0;i < role_size;i++)
        {
          if(initial_pn_payload->legal_size[i] > 1)
          {
            if(current_control_r_id > -1)
            {
              isAlternatingMoves = false;
              break;
            }
            else current_control_r_id = i;
          }
        }

        if(current_control_r_id != -1)
          alt_role_masks[current_control_r_id] = temp & std::move(alt_role_masks[current_control_r_id]);
      }


      initial_pn.GetRandomLegalMove(*initial_pn_payload, m);

      initial_pn.Update(m, *initial_pn_payload);

      temp.Equate(initial_pn_payload->top);

      //cout << m << endl;
      //cout << temp << endl;
//
//      size_t t;
//      cin >> t;
    }

    if(isZeroSumGame)
      CheckZeroSumGame();

    num_simulations++;
  }

  log.Info << "Performed " << num_simulations << " simulations in meta game simulations." << std::endl;

  if(isZeroSumGame)
  {
    log.Info << "Game is Zero-Sum game." << std::endl;
  }

  if(isAlternatingMoves)
  {
    log.Info << "Game with alternating moves." << std::endl;
  }
  else
  {
    delete[] alt_role_masks;
    alt_role_masks = NULL;
  }
}