Exemplo n.º 1
0
function bestMatch($team1players)
{
    $team1players = explode(',', $team1players);
    if (count($team1players) == 2) {
        if ($team1players[0] == 0) {
            $team1players = array($team1players[1]);
        } elseif ($team1players[1] == 0) {
            $team1players = array($team1players[0]);
        }
    }
    $players = loadPlayers();
    $ratings = loadRatings();
    $bestScore = 0;
    $bestMatch = array();
    foreach ($players as $id1 => $name1) {
        foreach ($players as $id2 => $name2) {
            if (in_array($id1, $team1players) || in_array($id2, $team1players)) {
                continue;
            }
            $team2players = array($id1);
            if ($id1 != $id2) {
                $team2players[] = $id2;
            }
            $score = matchScore($team1players, $team2players, $ratings);
            if ($score > $bestScore) {
                $bestScore = $score;
                $bestMatch = $team2players;
            }
        }
    }
    return $bestMatch;
}
Exemplo n.º 2
0
function ranking()
{
    $players = loadPlayers();
    $ratings = loadRatings();
    uasort($ratings, 'compareRatings');
    $result = array();
    foreach ($ratings as $playerId => $rating) {
        $result[] = array($playerId, $players[$playerId], round($rating->getConservativeRating() * 100));
    }
    return $result;
}
Exemplo n.º 3
0
function updateStats($time, $team1players, $team2players, $scores, $enableLogging = true)
{
    $scores = explode(',', $scores);
    if (count($scores) == 2 && $scores[0] == $scores[1]) {
        return 'Draws are not supported.';
    }
    $team1players = explode(',', $team1players);
    if (count($team1players) == 2) {
        if ($team1players[0] == 0) {
            $team1players = array($team1players[1]);
        } elseif ($team1players[1] == 0) {
            $team1players = array($team1players[0]);
        }
    }
    $team2players = explode(',', $team2players);
    if (count($team2players) == 2) {
        if ($team2players[0] == 0) {
            $team2players = array($team2players[1]);
        } elseif ($team2players[1] == 0) {
            $team2players = array($team2players[0]);
        }
    }
    if ($enableLogging) {
        file_put_contents('games.log', $time . "\t" . join(',', $team1players) . "\t" . join(',', $team2players) . "\t" . join(',', $scores) . "\n", FILE_APPEND);
    }
    $gameInfo = new GameInfo();
    $ratings = loadRatings();
    $team1 = new Team();
    foreach ($team1players as $playerId) {
        $player = new Player($playerId);
        $team1->addPlayer($player, $ratings[$playerId]);
    }
    $team2 = new Team();
    foreach ($team2players as $playerId) {
        $player = new Player($playerId);
        $team2->addPlayer($player, $ratings[$playerId]);
    }
    $teams = Teams::concat($team1, $team2);
    $calculator = new TwoTeamTrueSkillCalculator();
    $winner = count($scores) == 1 ? $scores : ($scores[0] > $scores[1] ? 1 : 2);
    $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, $winner == 1 ? array(1, 2) : array(2, 1));
    foreach ($newRatings->getAllPlayers() as $player) {
        $rating = $newRatings->getRating($player);
        $ratings[$player->getId()] = $rating;
    }
    $stats = array();
    foreach ($ratings as $playerId => $rating) {
        $stats[] = $playerId . "\t" . $rating->getMean() . "\t" . $rating->getStandardDeviation();
        file_put_contents('players.stats', $time . "\t" . $playerId . "\t" . $rating->getConservativeRating() . "\n", FILE_APPEND);
    }
    file_put_contents('games.stats', join("\n", $stats));
    return 'OK';
}