当前位置: 首页>>代码示例>>C++>>正文


C++ Match::getPlayerPair1方法代码示例

本文整理汇总了C++中Match::getPlayerPair1方法的典型用法代码示例。如果您正苦于以下问题:C++ Match::getPlayerPair1方法的具体用法?C++ Match::getPlayerPair1怎么用?C++ Match::getPlayerPair1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Match的用法示例。


在下文中一共展示了Match::getPlayerPair1方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testGetPairs

void tstMatch::testGetPairs()
{
  printStartMsg("tstMatch::testGetGroup");

  TournamentDB* db = getScenario04(true);
  Tournament t(getSqliteFileName());
  MatchMngr* mm = Tournament::getMatchMngr();
  Category mx = Tournament::getCatMngr()->getCategoryById(5);

  ERR e;
  auto mg = mm->getMatchGroup(mx, 1, 1, &e);
  CPPUNIT_ASSERT(e == OK);
  CPPUNIT_ASSERT(mg != nullptr);

  auto mgl = mg->getMatches();
  CPPUNIT_ASSERT(mgl.count() == 1);
  Match ma = mgl.at(0);

  // test the getPair-functions
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == false);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == false);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair1(), std::runtime_error);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair2(), std::runtime_error);

  // (artificially) assign one pair
  PlayerPair pp1 = Tournament::getPlayerMngr()->getPlayerPair(1);
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR1_REF, pp1.getPairId());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == true);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == false);
  CPPUNIT_ASSERT(ma.getPlayerPair1().getPairId() == pp1.getPairId());
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair2(), std::runtime_error);

  // (artificially) assign the second pair
  PlayerPair pp2 = Tournament::getPlayerMngr()->getPlayerPair(2);
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR2_REF, pp2.getPairId());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == true);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == true);
  CPPUNIT_ASSERT(ma.getPlayerPair1().getPairId() == pp1.getPairId());
  CPPUNIT_ASSERT(ma.getPlayerPair2().getPairId() == pp2.getPairId());

  // remove the first one
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR1_REF, QVariant());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == false);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == true);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair1(), std::runtime_error);
  CPPUNIT_ASSERT(ma.getPlayerPair2().getPairId() == pp2.getPairId());

  delete db;
  printEndMsg();
}
开发者ID:Foorgol,项目名称:QTournament,代码行数:56,代码来源:tstMatch.cpp

示例2: updateRankingsAfterMatchResultChange

  ERR RankingMngr::updateRankingsAfterMatchResultChange(const Match& ma, const MatchScore& oldScore, bool skipSorting) const
  {
    if (ma.getState() != STAT_MA_FINISHED) return WRONG_STATE;

    Category cat = ma.getCategory();
    int catId = cat.getId();
    int firstRoundToModify = ma.getMatchGroup().getRound();

    // determine the score differences (delta) for each affected player pair
    MatchScore newScore = *(ma.getScore());  // is guaranteed to be != nullptr
    tuple<int, int, int> deltaMatches_P1{0,0,0};  // to be added to PlayerPair1
    tuple<int, int, int> deltaMatches_P2{0,0,0};  // to be added to PlayerPair2

    int oldWinner = oldScore.getWinner();
    int newWinner = newScore.getWinner();
    if ((oldWinner == 0) && (newWinner == 1))
    {
      deltaMatches_P1 = tuple<int, int, int>{1, 0, -1};
      deltaMatches_P2 = tuple<int, int, int>{0, 1, -1};
    }
    if ((oldWinner == 0) && (newWinner == 2))
    {
      deltaMatches_P1 = tuple<int, int, int>{0, 1, -1};
      deltaMatches_P2 = tuple<int, int, int>{1, 0, -1};
    }
    if ((oldWinner == 1) && (newWinner == 0))
    {
      deltaMatches_P1 = tuple<int, int, int>{-1, 0, 1};
      deltaMatches_P2 = tuple<int, int, int>{0, -1, 1};
    }
    if ((oldWinner == 2) && (newWinner == 0))
    {
      deltaMatches_P1 = tuple<int, int, int>{0, -1, 1};
      deltaMatches_P2 = tuple<int, int, int>{-1, 0, 1};
    }
    if ((oldWinner == 1) && (newWinner == 2))
    {
      deltaMatches_P1 = tuple<int, int, int>{-1, 1, 0};
      deltaMatches_P2 = tuple<int, int, int>{1, -1, 0};
    }
    if ((oldWinner == 2) && (newWinner == 1))
    {
      deltaMatches_P1 = tuple<int, int, int>{1, -1, 0};
      deltaMatches_P2 = tuple<int, int, int>{-1, 1, 0};
    }

    tuple<int, int> gameSumOld = oldScore.getGameSum();
    tuple<int, int> gameSumNew = newScore.getGameSum();
    int gamesTotalOld = get<0>(gameSumOld) + get<1>(gameSumOld);
    int gamesTotalNew = get<0>(gameSumNew) + get<1>(gameSumNew);

    int deltaWonGamesP1 = -get<0>(gameSumOld) + get<0>(gameSumNew);
    int deltaLostGamesP1 = -(gamesTotalOld - get<0>(gameSumOld)) + (gamesTotalNew - get<0>(gameSumNew));
    int deltaWonGamesP2 = -get<1>(gameSumOld) + get<1>(gameSumNew);
    int deltaLostGamesP2 = -(gamesTotalOld - get<1>(gameSumOld)) + (gamesTotalNew - get<1>(gameSumNew));
    tuple<int, int> deltaGames_P1{deltaWonGamesP1, deltaLostGamesP1};  // to be added to PlayerPair1
    tuple<int, int> deltaGames_P2{deltaWonGamesP2, deltaLostGamesP2};  // to be added to PlayerPair2

    tuple<int, int> scoreSumOld = oldScore.getScoreSum();
    tuple<int, int> scoreSumNew = newScore.getScoreSum();
    int oldWonPoints_P1 = get<0>(scoreSumOld);
    int newWonPoints_P1 = get<0>(scoreSumNew);
    int deltaWonPoints_P1 = newWonPoints_P1 - oldWonPoints_P1;
    int oldLostPoints_P1 = oldScore.getPointsSum() - oldWonPoints_P1;
    int newLostPoints_P1 = newScore.getPointsSum() - newWonPoints_P1;
    int deltaLostPoints_P1 = newLostPoints_P1 - oldLostPoints_P1;
    tuple<int, int> deltaPoints_P1{deltaWonPoints_P1, deltaLostPoints_P1};
    tuple<int, int> deltaPoints_P2{deltaLostPoints_P1, deltaWonPoints_P1};

    // determine who actually is P1 and P2
    int pp1Id = ma.getPlayerPair1().getPairId();
    int pp2Id = ma.getPlayerPair2().getPairId();

    // find the first entry to modify

    // derive the group number of the affected ranking entries
    //
    // we may only modify subsequent entries with the same
    // group number as the initial number. Thus, we prevent
    // a modification of e.g. the ranking entries in a KO-phase
    // after we started modifications in the round robin phase.
    //
    // we get the group number from the first entry of the
    // first player pair to be modified
    WhereClause w;
    w.addIntCol(RA_CAT_REF, catId);
    w.addIntCol(RA_PAIR_REF, pp1Id);
    w.addIntCol(RA_ROUND, firstRoundToModify);
    auto re = getSingleObjectByWhereClause<RankingEntry>(w);
    if (re == nullptr) return OK;  // no ranking entries yet
    int grpNum = re->getGroupNumber();

    //
    // a helper function that does the actual modification
    //
    auto doMod = [&](int pairId, const tuple<int, int, int>& matchDelta,
                     const tuple<int, int>& gamesDelta, const tuple<int, int>& pointsDelta)
    {
      // let's build a where clause that captures all entries
      // to modified
//.........这里部分代码省略.........
开发者ID:Foorgol,项目名称:QTournament,代码行数:101,代码来源:RankingMngr.cpp


注:本文中的Match::getPlayerPair1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。