TournamentPair* RoundRobinTournament::nextPair(int gameNumber)
{
	if (gameNumber >= finalGameCount())
		return 0;
	if (gameNumber % gamesPerEncounter() != 0)
		return currentPair();

	if (m_pairNumber >= m_topHalf.size())
	{
		m_pairNumber = 0;
		setCurrentRound(currentRound() + 1);
		m_topHalf.insert(1, m_bottomHalf.takeFirst());
		m_bottomHalf.append(m_topHalf.takeLast());
	}

	int white = m_topHalf.at(m_pairNumber);
	int black = m_bottomHalf.at(m_pairNumber);

	m_pairNumber++;

	// If 'white' or 'black' equals 'playerCount()' it means
	// that it's a "bye" player, that is an empty player that
	// makes the pairings easier to organize. In that case
	// no game is played and we skip to the next pair.
	if (white < playerCount() && black < playerCount())
		return pair(white, black);
	else
		return nextPair(gameNumber);
}
void RoundRobinTournament::initializePairing()
{
	m_pairNumber = 0;
	m_topHalf.clear();
	m_bottomHalf.clear();
	int count = playerCount() + (playerCount() % 2);

	for (int i = 0; i < count / 2; i++)
		m_topHalf.append(i);
	for (int i = count - 1; i >= count / 2; i--)
		m_bottomHalf.append(i);
}
Exemplo n.º 3
0
/*!
  \brief Processes the player count reply.

  The player count comes with a json answer. We parse it and extract the player
  count.

  \param data The data to be parsed.
*/
void
Steam::processReplyPlayerCount( const QByteArray &data )
{
  WAITCURSOR;
  int count = -1;

  if( ! data.isEmpty() )
  {
    JSONStreamReader jsonReader;
    JSONObject *json = jsonReader.read( data );
    if( ! json || jsonReader.hasError() )
    {
      SteamPrivate::jsonError( jsonReader );
      return;
    }

    JSONObject *response = json->valueObject( QL( "response" ) );
    if( response )
    {
      JSONScalar *result = response->valueScalar( QL( "result" ) );
      if( result && result->iValue() == 1 )
      {
        JSONScalar *player_count = response->valueScalar( QL( "player_count" ) );
        if( player_count )
          count = player_count->iValue();
      }
    }

    delete json;
    json = NULL;
  }

  emit( playerCount( count ) );
}
Exemplo n.º 4
0
void PlayerManager::update()
{
	for (int i = 0; i < playerCount(); ++i)
	{
		_player[i]->updatePlayer();
	}
}
Exemplo n.º 5
0
void LoginServer::initDB(el::Logger * const logger) {
	odb::transaction t(db->begin());

	PlayerCount playerCount(db->query_value<PlayerCount>());

	if (playerCount.count == 0u) {
		static const char * const suID = "*****@*****.**";
		static const char * const suPWD = "testa";

		logger->info("DB is empty, creating super-user \"%v\".", suID);

		const auto salt = hasher.generateSalt();
		const auto hashedPassword = hasher.hashPasswordSHA256(suPWD, salt);

		const auto pwdString = hasher.sha256ToString(hashedPassword);
		const auto saltString = hasher.saltToString(salt);

		Player superUser(suID, pwdString, saltString);
		superUser.id = 1;
		superUser.joinDate = superUser.lastLogin = boost::posix_time::second_clock::universal_time();

		db->persist(superUser);

		t.commit();

		logger->info("Created super-user.");
	}
}
Exemplo n.º 6
0
int Reversi::win(void)
{
	bool spaces = false;
	int cnt[playerCount()];
	for (int i = 0; i < playerCount(); i++)
		cnt[i] = 0;
	for (int r = 0; r < size().height(); r++)
		for (int c = 0; c < size().width(); c++) {
			if (data.pos[r][c] == -1) {
				spaces = true;
				continue;
			}
			cnt[data.pos[r][c]]++;
		}
	if (cnt[Black] == 0)
		return White;
	if (cnt[White] == 0)
		return Black;
	if (spaces)
		return -1;
	if (cnt[Black] == cnt[White])
		return -2;
	return cnt[Black] > cnt[White] ? Black : White;
}
Exemplo n.º 7
0
QPair<int, int> GauntletTournament::nextPair()
{
	if (m_opponent >= playerCount())
	{
		m_opponent = 1;
		setCurrentRound(currentRound() + 1);
	}

	int white = 0;
	int black = m_opponent++;

	// Alternate colors between rounds to make it fair
	if (currentRound() % 2 == 0)
		qSwap(white, black);

	return qMakePair(white, black);
}
Exemplo n.º 8
0
int GauntletTournament::gamesPerCycle() const
{
	return playerCount() - 1;
}
int RoundRobinTournament::gamesPerCycle() const
{
	return (playerCount() * (playerCount() - 1)) / 2;
}