Example #1
0
function dciinputplayoffs($reg, $data)
{
    $event = new Event($_POST['name']);
    $data = preg_replace("/\r\n/", "\n", $data);
    $lines = split("\n", $data);
    $ntables = $lines[0];
    $nrounds = log($ntables, 2);
    for ($rnd = 1; $rnd <= $nrounds; $rnd++) {
        $ngames = pow(2, $nrounds - $rnd);
        for ($game = 0; $game < $ngames; $game++) {
            $offset = 2 + $game * 24;
            $playera = $lines[$offset + ($rnd - 1) * 3];
            $pbl = $offset + ($rnd - 1) * 3 + 12;
            $playerb = $lines[$pbl];
            $winner = $lines[($pbl + 1 + 3 * $rnd - 6) / 2 - 1];
            $pa = $reg[$playera - 1];
            $pb = $reg[$playerb - 1];
            $res = 'D';
            if ($winner == $playera) {
                $res = 'A';
            }
            if ($winner == $playerb) {
                $res = 'B';
            }
            $event->addMatch($pa, $pb, $rnd + $event->mainrounds, $res);
        }
    }
}
Example #2
0
/**
 * This comes from the XXXX303.dat file ($data)
 * As far as I know, the format of this file is:
 * round number, match number, player 1 number, player 2 number, player 1 wins, player 2 wins, draws
 *
 * match number is 0 when there wasn't a Nth match that round
 */
function dci3makematches($event, $data, $regmap)
{
    $event = new Event($_POST['name']);
    $result = array();
    $lines = explode_dcir_lines($data);
    foreach ($lines as $line) {
        $table = explode(",", $line);
        $roundnum = $table[0];
        $matchnum = $table[1];
        $playeranum = $table[2];
        $playerbnum = $table[3];
        $playerawins = $table[4];
        $playerbwins = $table[5];
        if ($matchnum == 0) {
            continue;
        }
        if ($playerawins > $playerbwins) {
            $res = 'A';
        } else {
            if ($playerawins < $playerbwins) {
                $res = 'B';
            } else {
                $res = 'D';
            }
        }
        $event->addMatch($regmap[$playeranum], $regmap[$playerbnum], $roundnum, $res, $playerawins, $playerbwins);
    }
    $event->assignTropiesFromMatches();
}
Example #3
0
function updateMatches()
{
    $event = new Event($_POST['name']);
    if (isset($_POST['matchdelete'])) {
        foreach ($_POST['matchdelete'] as $matchid) {
            Match::destroy($matchid);
        }
    }
    if (isset($_POST['dropplayer'])) {
        foreach ($_POST['dropplayer'] as $playername) {
            $event->dropPlayer($playername);
        }
    }
    if (isset($_POST['hostupdatesmatches'])) {
        for ($ndx = 0; $ndx < sizeof($_POST['hostupdatesmatches']); $ndx++) {
            $result = $_POST['matchresult'][$ndx];
            $resultForA = "notset";
            $resultForB = "notset";
            if ($result == "2-0") {
                $resultForA = "W20";
                $resultForB = "L20";
            } elseif ($result == "2-1") {
                $resultForA = "W21";
                $resultForB = "L21";
            } elseif ($result == "1-2") {
                $resultForA = "L21";
                $resultForB = "W21";
            } elseif ($result == "0-2") {
                $resultForA = "L20";
                $resultForB = "W20";
            } elseif ($result == 'D') {
                // TODO: need to figure out how to enter a draw
            }
            if (strcasecmp($resultForA, 'notset') != 0 && strcasecmp($resultForB, 'notset') != 0) {
                $matchid = $_POST['hostupdatesmatches'][$ndx];
                Match::saveReport($resultForA, $matchid, 'a');
                Match::saveReport($resultForB, $matchid, 'b');
            }
        }
    }
    if (isset($_POST['newmatchplayerA'])) {
        $pA = $_POST['newmatchplayerA'];
    } else {
        $pA = "";
    }
    if (isset($_POST['newmatchplayerB'])) {
        $pB = $_POST['newmatchplayerB'];
    } else {
        $pB = "";
    }
    if (isset($_POST['newmatchresult'])) {
        $res = $_POST['newmatchresult'];
        if ($res == "2-0") {
            $pAWins = 2;
            $pBWins = 0;
            $res = 'A';
        } elseif ($res == "2-1") {
            $pAWins = 2;
            $pBWins = 1;
            $res = 'A';
        } elseif ($res == "1-2") {
            $pAWins = 1;
            $pBWins = 2;
            $res = 'B';
        } elseif ($res == "0-2") {
            $pAWins = 0;
            $pBWins = 2;
            $res = 'B';
        } elseif ($res == 'D') {
            $pAWins = 0;
            $pBWins = 0;
            $res = 'D';
        }
    } else {
        $res = "";
    }
    if (isset($_POST['newmatchround'])) {
        $rnd = $_POST['newmatchround'];
    } else {
        $rnd = "";
    }
    if (strcmp($pA, "") != 0 && strcmp($pB, "") != 0 && strcmp($res, "") != 0 && strcmp($rnd, "") != 0) {
        if ($res == "P") {
            $event->addPairing($pA, $pB, $rnd, $res);
        } else {
            $event->addMatch($pA, $pB, $rnd, $res, $pAWins, $pBWins);
        }
    }
    if (isset($_POST['newbyeplayer']) && strcmp($_POST['newbyeplayer'], "") != 0) {
        $p = $_POST['newbyeplayer'];
        $event->addMatch($p, $p, $rnd, 'BYE');
    }
}