function updateScoreOracleDruideRefuse($id, $lang, $enregistrement_id)
{
    //~ 		updateScoreOracleDevinEchec($id,$lang,$lvl_pts);
    require_once "./sys/db.class.php";
    $db = db::getInstance();
    //~ 		$sql = 'SELECT nivcarte FROM enregistrement WHERE enregistrementID="' . $enregistrement_id . '"';
    //~ 		$res = mysqli_fetch_array($db->query($sql),MYSQLI_NUM);
    //~ 		if (strcmp($res[0],"facile") == 0) { $lvl = "easy"; }
    //~ 		else if (strcmp($res[0],"moyen") == 0) { $lvl = "medium"; }
    //~ 		else if (strcmp($res[0],"difficile") == 0) { $lvl = "hard"; }
    //~ 		$sql = 'SELECT points FROM game_lvl WHERE userlvl="' . $lvl . '"';
    //~ 		$lvl_pts = mysqli_fetch_array($db->query($sql),MYSQLI_NUM);
    $lvl_pts = getCardLvlPts($enregistrement_id);
    $sql = 'SELECT scoreGlobal,scoreOracle,first_game_time FROM score WHERE userid="' . $id . '" AND langue="' . $lang . '"';
    $scores = computeScore($sql, $id, $lang, $lvl_pts, false);
    if ($scores[0] >= 0 && $scores[1] >= 0) {
        $sql = 'UPDATE score 
					SET  scoreGlobal=' . $db->escape((string) $scores[0]) . ', ' . 'scoreOracle=' . $db->escape((string) $scores[1]) . ', ' . 'first_game_time=' . $db->escape((string) $scores[2]) . '
					WHERE userid=' . $id . ' AND langue= "' . $lang . '"';
        $db->query($sql);
    }
}
Example #2
0
        case 8:
            $n = 9;
            $m = 9;
            break;
        case 9:
            $n = 10;
            $m = 10;
            break;
    }
    $e = selectFromTable($id);
    $finalArray = array('N' => $n, 'M' => $m, 'E' => $e);
    echo json_encode($finalArray);
}
if ($command == 'submit') {
    $id = $_GET["graph_id"];
    $matchArray = json_decode($_GET['solution']);
    $e = selectEdges($id);
    $diff = array();
    for ($i = 0; $i < count($matchArray); $i++) {
        if (!in_array($matchArray[$i], $e)) {
            array_push($diff, $matchArray[$i]);
        }
    }
    if (!empty($diff)) {
        $finalArray = array('graph_id' => $id, 'new_best' => NULL, 'num_match' => 'DNE', 'match_score' => $diff);
        echo json_encode($finalArray);
    } else {
        echo json_encode(computeScore($id, $matchArray));
    }
}
$db->close();
Example #3
0
        header("Content-Length: " . filesize('top10.json'));
        usort($top10Table, "cmp");
        echo json_encode($top10Table);
    }
    exit(0);
}
// POST
// Ler pontuacao do ficheiro
$top10Table = json_decode(file_get_contents($file), true);
// NOTA $_POST está vazio se Content-Type do request for application/json
$inputData = json_decode(file_get_contents("php://input"), true);
if (strcmp($inputData["op"], "check") == 0) {
    $score = computeScore($inputData["moves"], $inputData["elapsedTime"], $inputData["boardSize"]);
    echo checkPOSTResult($score, checkTopTenWorthy($top10Table, $score));
} elseif (strcmp($inputData["op"], "update") == 0) {
    $score = computeScore($inputData["moves"], $inputData["elapsedTime"], $inputData["boardSize"]);
    if (checkTopTenWorthy($top10Table, $score) == true) {
        $pos = getTopTenLowestValuePos($top10Table, $score);
        $top10Table[$pos]['name'] = $inputData["playerName"];
        $top10Table[$pos]['score'] = $score;
        usort($top10Table, "cmp");
        file_put_contents($file, json_encode($top10Table));
        echo json_encode($top10Table);
    }
}
function computeScore($moves, $elapsedTime, $gameBoardSize)
{
    return round(1 / (0.9 * $moves + 0.1 * $elapsedTime) * $gameBoardSize * 100000);
}
function checkPOSTResult($score, $top_ten_worthy)
{
Example #4
0
/**
 * Given a piece of code that runs through all the printable characters using different steps (and wrapping),
 * compute the best value for the step (to match all the output conditions and minimize the score.
 * Display the value it founds as best, the score and the output of the program.
 *
 * Usage:
 * <code>
 *     findBestOffset('for(;++$f<96;$T=($T+&)%95)echo chr(32+$T);')
 * </code>
 *
 * @param string $rawCode
 */
function findBestOffset($rawCode)
{
    $solutions = [];
    $outputs = [];
    $count = 96;
    for ($k = 1; $k < $count; $k++) {
        if ($count % $k) {
            $code = str_replace('&', $k, $rawCode);
            $output = getOutput(function () use($code) {
                eval($code);
            });
            $score = computeScore($output, $code);
            if (is_integer($score)) {
                $solutions[$code] = $score;
                $outputs[$code] = $output;
            }
            echo '.';
        }
    }
    echo "\n";
    asort($solutions);
    $bestK = array_keys($solutions)[0];
    $score = $solutions[$bestK];
    echo 'Best solution: <code>' . $bestK . '</code>, score=' . $score . "\n";
    echo 'Output: <output>' . $outputs[$bestK] . "</output>\n";
}