コード例 #1
0
 function forwardPlayers($enc, $roundId, $encId)
 {
     global $db;
     if ($roundId + 1 >= $this->numberOfRounds) {
         // Check if everygame is finished
         $openenc = $db->num_rows('tournamentencounters', "`tournamentid`=" . $this->tournamentId . " AND `roundid`=" . ($this->numberOfRounds - 1) . " AND `state`=0");
         if (isset($openenc) && $openenc == 0) {
             // Close the tournament
             global $notify;
             global $lang;
             $notify->add($lang->get('tournament'), $lang->get('ntfy_end_game'));
             return $db->update('tournamentlist', "`state`=3", "`tournamentid`=" . $this->tournamentId);
         }
         return false;
     }
     $encounters = $db->selectList('tournamentencounters', '*', "`tournamentid`=" . $this->tournamentId . " AND `roundid`=" . ($roundId + 1), "`encounterid` ASC");
     $encountercount = $db->num_rows('tournamentencounters', "`tournamentid`=" . $this->tournamentId . " AND `roundid`=" . $roundId);
     // First Winner - make next round encounters
     if (count($encounters) == null) {
         for ($i = 0; $i < $encountercount; $i++) {
             $curEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $i, true);
             $curEnc->setPlayers(0, 0);
         }
         $this->setEncTimes($curEnc->getRoundId());
     }
     $winnerid = $enc->winner() == 1 ? $enc->getPlayer1id() : $enc->getPlayer2id();
     $looserid = $enc->winner() == 1 ? $enc->getPlayer2id() : $enc->getPlayer1id();
     // Top Game - winner stays(top left) looser goes one lower left
     if ($encId == 0) {
         $winEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0);
         $winEnc->setPlayer1id($winnerid);
         $losEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 1);
         $losEnc->setPlayer1id($looserid);
     } else {
         if ($encId == $encountercount - 1) {
             $losEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $encountercount - 1);
             $losEnc->setPlayer2id($looserid);
             $winEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $encountercount - 2);
             $winEnc->setPlayer2id($winnerid);
         } else {
             $winEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $enc->getId() - 1);
             $winEnc->setPlayer2id($winnerid);
             $losEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $enc->getId() + 1);
             $losEnc->setPlayer1id($looserid);
         }
     }
     // Check if the bottom game has a bye
     $bottomgame = new EliminationEncounter($this->tournamentId, $roundId + 1, $encountercount - 1);
     if (@$bottomgame->getPlayer2id() == -1 && $bottomgame->getPlayer1id() > 0) {
         $bottomgame->setPoints(0, 0);
         $this->forwardPlayers($bottomgame, $roundId + 1, $bottomgame->getId());
     }
 }
コード例 #2
0
 private function setEncPoints($roundId, $encId, $p1points, $p2points)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId);
     if ($roundId < $this->roundCount() - 1) {
         // not in last round
         $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2);
         if ($this->thirdplayoff && $roundId == $this->roundCount() - 2) {
             $firstAtNext = $enc->getId() % 2 == 0;
         } else {
             $firstAtNext = $enc->getAlias() % 2 == 0;
         }
     }
     // check which player has won and forward this player
     $enc->setPoints($p1points, $p2points);
     if (isset($nextEnc)) {
         if ($enc->winner() == 1) {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer1id());
             }
         } else {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer2id());
             }
         }
     }
     //  /w 3rd playoff forward loosers as well
     if ($this->thirdplayoff && $roundId == $this->roundCount() - 2) {
         $thirdPlayoffEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 1);
         if ($enc->winner() == 2) {
             if ($firstAtNext) {
                 $thirdPlayoffEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $thirdPlayoffEnc->setPlayer2id($enc->getPlayer1id());
             }
         } else {
             if ($firstAtNext) {
                 $thirdPlayoffEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $thirdPlayoffEnc->setPlayer2id($enc->getPlayer2id());
             }
         }
         // Check if there is a bye in the 3rd playoff
         if ($thirdPlayoffEnc->getPlayer1id() == -1 or $thirdPlayoffEnc->getPlayer2id() == -1) {
             $thirdPlayoffEnc->setPoints(0, 0);
         }
     }
 }
コード例 #3
0
 private function setEncPoints($roundId, $encId, $p1points, $p2points)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId);
     if ($roundId < $this->lastRound() - 1) {
         // normal and looser tier not merged yet
         if ($enc->getId() >= $this->lowerEncOffset()) {
             // in looser tier
             if ($roundId == $this->lastRound() - 2) {
                 // winner will get in first final match
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0);
                 $firstAtNext = false;
             } else {
                 if ($roundId % 2 == 0) {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $enc->getId());
                     $firstAtNext = false;
                 } else {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                     $firstAtNext = $enc->getAlias() % 2 == 0;
                 }
             }
         } else {
             // in winner tier
             if ($roundId == 1) {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                 $loserFirstAtNext = $enc->getAlias() % 2 == 0;
             } else {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 2, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() + $this->lowerEncOffset());
                 $loserFirstAtNext = true;
             }
         }
     } else {
         if ($p2points >= $p1points && $roundId == $this->lastRound() - 1) {
             // create second final match
             $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0, false);
             $loserNextEnc = $nextEnc;
             $firstAtNext = true;
             $loserFirstAtNext = false;
         } else {
             // final match
             global $db;
             global $notify;
             global $lang;
             $db->update('tournamentlist', "`state`=3", "`tournamentid`=" . $this->tournamentId);
             $notify->add($lang->get('tournament'), $lang->get('ntfy_end_game'));
         }
     }
     // check which player has won and forward this player
     $enc->setPoints($p1points, $p2points);
     if (isset($nextEnc)) {
         if ($enc->winner() == 1) {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer1id());
             }
         } else {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer2id());
             }
         }
     }
     if (isset($loserNextEnc)) {
         if ($enc->winner() == 1) {
             if ($loserFirstAtNext) {
                 $loserNextEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $loserNextEnc->setPlayer2id($enc->getPlayer2id());
             }
         } else {
             if ($loserFirstAtNext) {
                 $loserNextEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $loserNextEnc->setPlayer2id($enc->getPlayer1id());
             }
         }
     }
     // Forward looser if he has a bye
     if (isset($loserNextEnc)) {
         $p1id = $loserNextEnc->getPlayer1id();
         $p2id = $loserNextEnc->getPlayer2id();
         if ($p1id == -1 && $p2id > 0 || $p2id == -1 && $p1id > 0 || $p1id == -1 && $p2id == -1) {
             $loserNextEnc->setPoints(0, 0);
             $this->setEncPoints($roundId + 1, $loserNextEnc->getId(), 0, 0);
         }
     }
 }