Ejemplo n.º 1
0
/**
 * Creates matches with the correct results from pasting the pairings and standings from
 * DCI-R, in the special format.
 *
 * @param event The event object to add the matches to
 * @param pairingTexts an array of text pastes from the DCI-R program for pairings.  See extractPairings for format.
 * @param standingsTexts an array of text pastes from the DCI-R program for standings. See extractStandings for format.
 * @param finalsTexts an array of finals text pastes. See extractfinals for format.
 * @param champion the winner of the tournament
 * @return the number of matches parsed and added
 */
function matchesFromDCIPastes($event, $pairingTexts, $standingsTexts, $finalsTexts, $champion)
{
    $pairings = array();
    $standings = array();
    $matchesadded = 0;
    for ($rnd = 0; $rnd < sizeof($pairingTexts); $rnd++) {
        $pairings[$rnd] = extractPairings($pairingTexts[$rnd]);
        if ($rnd == 0) {
            $standings[$rnd] = standFromPairs($pairingTexts[$rnd + 1]);
        } else {
            $testStr = chop($standingsTexts[$rnd - 1]);
            if (strcmp($testStr, "") == 0) {
                $standings[$rnd] = standFromPairs($pairingTexts[$rnd + 1]);
            } else {
                $standings[$rnd] = extractStandings($standingsTexts[$rnd - 1]);
            }
        }
    }
    $sid = $event->mainid;
    $onlyfirstround = true;
    for ($rnd = 1; $rnd < sizeof($pairingTexts); $rnd++) {
        if (strlen($pairingTexts[$rnd]) > 0) {
            $onlyfirstround = false;
            break;
        }
    }
    if ($onlyfirstround) {
        for ($pair = 0; $pair < sizeof($pairings[0]); $pair++) {
            $event->addPlayer($pairings[0][$pair][0]);
            $event->addPlayer($pairings[0][$pair][1]);
        }
        $byeplayer = extractBye($pairingTexts[0]);
        if ($byeplayer) {
            $event->addPlayer($byeplayer);
        }
        return 0;
    }
    for ($rnd = 0; $rnd < sizeof($pairings); $rnd++) {
        for ($pair = 0; $pair < sizeof($pairings[$rnd]); $pair++) {
            $printrnd = $rnd + 1;
            $playerA = $pairings[$rnd][$pair][0];
            $playerB = $pairings[$rnd][$pair][1];
            $winner = "D";
            if ($rnd == 0) {
                if (isset($standings[$rnd][$playerA]) && $standings[$rnd][$playerA] > 1) {
                    $winner = "A";
                }
                if (isset($standings[$rnd][$playerB]) && $standings[$rnd][$playerB] > 1) {
                    $winner = "B";
                }
            } else {
                if (isset($standings[$rnd][$playerA]) && isset($standings[$rnd - 1][$playerA]) && $standings[$rnd][$playerA] - $standings[$rnd - 1][$playerA] > 1) {
                    $winner = "A";
                }
                if (isset($standings[$rnd][$playerB]) && isset($standings[$rnd - 1][$playerB]) && $standings[$rnd][$playerB] - $standings[$rnd - 1][$playerB] > 1) {
                    $winner = "B";
                }
            }
            $event->addPlayer($playerA);
            $event->addPlayer($playerB);
            $event->addMatch($playerA, $playerB, $rnd + 1, $winner, 0, 0);
            $matchesadded++;
        }
    }
    $finals = array();
    foreach ($finalsTexts as $pasteround) {
        $finals[] = extractFinals($pasteround);
    }
    // At this point, $finals is an array of arrays, with the matchings in each round, i.e.
    // [0][0] Alphie     [1][0] Betta     [2][0] Dave
    // [0][1] Betta
    // [0][2] Charlie    [1][1] Dave
    // [0][3] Dave
    $fid = $event->finalid;
    $win = "";
    $sec = "";
    $t4 = array();
    $t8 = array();
    for ($round = 0; $round < sizeof($finals); $round++) {
        for ($match = 0; $match < sizeof($finals[$round]); $match += 2) {
            $playerA = $finals[$round][$match];
            $playerB = $finals[$round][$match + 1];
            $event->addPlayer($playerA);
            $event->addPlayer($playerB);
            if ($round < sizeof($finals) - 1) {
                $winner = detwinner($playerA, $playerB, $finals[$round + 1]);
            } else {
                $winner = $champion;
            }
            $res = "D";
            if (strcmp($winner, $playerA) == 0) {
                $res = "A";
            }
            if (strcmp($winner, $playerB) == 0) {
                $res = "B";
            }
            $event->addMatch($playerA, $playerB, $round + 1 + $event->mainrounds, $res, 0, 0);
            $matchesadded++;
            $loser = strcmp($winner, $playerA) == 0 ? $playerB : $playerA;
            if ($round == sizeof($finals) - 1) {
                $win = $winner;
                $sec = $loser;
            } elseif ($round == sizeof($finals) - 2) {
                $t4[] = $loser;
            } elseif ($round == sizeof($finals) - 3) {
                $t8[] = $loser;
            }
        }
    }
    $event->setFinalists($win, $sec, $t4, $t8);
}
Ejemplo n.º 2
0
function autoInput()
{
    $pairings = array();
    $standings = array();
    for ($rnd = 0; $rnd < sizeof($_POST['pairings']); $rnd++) {
        $pairings[$rnd] = extractPairings($_POST['pairings'][$rnd]);
        if ($rnd == 0) {
            $standings[$rnd] = standFromPairs($_POST['pairings'][$rnd + 1]);
        } else {
            $testStr = chop($_POST['standings'][$rnd - 1]);
            if (strcmp($testStr, "") == 0) {
                $standings[$rnd] = standFromPairs($_POST['pairings'][$rnd + 1]);
            } else {
                $standings[$rnd] = extractStandings($_POST['standings'][$rnd - 1]);
            }
        }
    }
    $event = new Event($_POST['name']);
    $sid = $event->mainid;
    for ($rnd = 0; $rnd < sizeof($pairings); $rnd++) {
        for ($pair = 0; $pair < sizeof($pairings[$rnd]); $pair++) {
            $printrnd = $rnd + 1;
            $playerA = $pairings[$rnd][$pair][0];
            $playerB = $pairings[$rnd][$pair][1];
            $winner = "D";
            if ($rnd == 0) {
                if (isset($standings[$rnd][$playerA]) && $standings[$rnd][$playerA] > 1) {
                    $winner = "A";
                }
                if (isset($standings[$rnd][$playerB]) && $standings[$rnd][$playerB] > 1) {
                    $winner = "B";
                }
            } else {
                if (isset($standings[$rnd][$playerA]) && isset($standings[$rnd - 1][$playerA]) && $standings[$rnd][$playerA] - $standings[$rnd - 1][$playerA] > 1) {
                    $winner = "A";
                }
                if (isset($standings[$rnd][$playerB]) && isset($standings[$rnd - 1][$playerB]) && $standings[$rnd][$playerB] - $standings[$rnd - 1][$playerB] > 1) {
                    $winner = "B";
                }
            }
            $objplayera = Player::findOrCreateByName($playerA);
            $objplayerb = Player::findOrCreateByName($playerB);
            $event->addPlayer($playerA);
            $event->addPlayer($playerB);
            $event->addMatch($playerA, $playerB, $rnd + 1, $winner);
        }
    }
    $finals = array();
    for ($ndx = 0; $ndx < sizeof($_POST['finals']); $ndx++) {
        $finals[$ndx] = extractFinals($_POST['finals'][$ndx]);
    }
    $fid = $event->finalid;
    $win = "";
    $sec = "";
    $t4 = array();
    $t8 = array();
    for ($ndx = 0; $ndx < sizeof($finals); $ndx++) {
        for ($match = 0; $match < sizeof($finals[$ndx]); $match += 2) {
            $playerA = $finals[$ndx][$match];
            $playerB = $finals[$ndx][$match + 1];
            $event->addPlayer($playerA);
            $event->addPlayer($playerB);
            if ($ndx < sizeof($finals) - 1) {
                $winner = detwinner($playerA, $playerB, $finals[$ndx + 1]);
            } else {
                $winner = $_POST['champion'];
            }
            $res = "D";
            if (strcmp($winner, $playerA) == 0) {
                $res = "A";
            }
            if (strcmp($winner, $playerB) == 0) {
                $res = "B";
            }
            $event->addMatch($playerA, $playerB, $ndx + 1 + $event->mainrounds, $res);
            $loser = strcmp($winner, $playerA) == 0 ? $playerB : $playerA;
            if ($ndx == sizeof($finals) - 1) {
                $win = $winner;
                $sec = $loser;
            } elseif ($ndx == sizeof($finals) - 2) {
                $t4[] = $loser;
            } elseif ($ndx == sizeof($finals) - 3) {
                $t8[] = $loser;
            }
        }
    }
    $event->setFinalists($win, $sec, $t4, $t8);
}