//---------------------------------------------------------------------------
ribi::gtst::ServerStates::ServerStates(
  Server * const server,
  boost::shared_ptr<const Parameters> parameters,
  LogFile * const log)
  : m_i(0),
    m_log(log),
    m_n_cycles{},
    m_v{}
{
  assert(parameters);
  assert(m_log);

  m_v.push_back(boost::shared_ptr<ServerState>(new ServerStateGroupAssign(server,0,0)));
  const int n_periods = parameters->GetGroupReAssign()->GetNumberOfPeriods();
  for (int period = 0; period!=n_periods; ++period)
  {
    m_v.push_back(boost::shared_ptr<ServerState>(new ServerStateChat(server,period,0,parameters->GetChat())));

    const boost::shared_ptr<ServerState> voting(
      new ServerStateVoting(server,period,0,parameters->GetVoting()));
    m_v.push_back(voting);

    const boost::shared_ptr<ServerStateViewResultsVoting> view_results_voting(
      new ServerStateViewResultsVoting(server,period,0,parameters->GetViewResultsVoting()));
    m_v.push_back(view_results_voting);

    const int n_cycles = parameters->GetViewResultsGroup()->GetRepeatAssigner()->Assign();
    ///Store the number of IPGG cycles
    m_n_cycles[period] = n_cycles;

    for (int cycle = 0; cycle!=n_cycles; ++cycle)
    {
      m_v.push_back(boost::shared_ptr<ServerState>(
        new ServerStateChooseAction(server,period,cycle,parameters->GetChooseAction())));
      m_v.push_back(boost::shared_ptr<ServerState>(new ServerStateAssignPayoff(server,period,cycle,
        parameters->GetAssignPayoff(),view_results_voting)));
      m_v.push_back(boost::shared_ptr<ServerState>(
        new ServerStateViewResultsGroup(server,period,cycle,parameters->GetViewResultsGroup())));
    }
    m_v.push_back(boost::shared_ptr<ServerState>(
      new ServerStateGroupReAssign(server,period,0,parameters->GetGroupReAssign())));
  }
  m_v.push_back(boost::shared_ptr<ServerState>(new ServerStateFinished(server,n_periods,0)));
}