Example #1
0
/**
 * Iterate through all jugglers, assigning them to circuits recursively
 * 1. By preference
 * 2. If their preferred circuit is full
 *   a. If they are a better fit for the circuit than someone in it, bump that person
 *   b. Otherwise, check the next circuit in their list
 * 
 * @param juggler $juggler
 * @param array $circuits
 * @param array $jugglers
 */
function assignJuggler(&$juggler, &$circuits, &$jugglers)
{
    $jugglers_per_circuit = count($jugglers) / count($circuits);
    foreach ($juggler->preferences as $preference) {
        // Check for an opening in their preferred circuit
        if (count($circuits[$preference]->jugglers) < $jugglers_per_circuit) {
            $circuits[$preference]->jugglers[] = $juggler->id;
            $juggler->circuit = $preference;
            break;
        } else {
            foreach ($circuits[$preference]->jugglers as $key => $circuit_juggler_id) {
                // They are a better fit, bump that person
                if (calculateScore($juggler, $circuits[$preference]) > calculateScore($jugglers[$circuit_juggler_id], $circuits[$preference])) {
                    $circuits[$preference]->jugglers[$key] = $juggler->id;
                    $juggler->circuit = $preference;
                    assignJuggler($jugglers[$circuit_juggler_id], $circuits, $jugglers);
                    // Done comparing to jugglers in this circuit
                    break;
                    // Done looking for a circuit for this juggler
                    break;
                }
            }
            // If they've gotten to here, they're not a better fit, try their next preference
        }
    }
}
Example #2
0
<?php

include 'include/game.php';
//Starting and initializing game
$deck = startGame($deck);
$cardAmount = generateCardAmount($cardAmount);
$score = calculateScore($cardAmount, $deck, $score);
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">

  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame 
       Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>Silverjack</title>
  <meta name="description" content="">
  <meta name="author" content="The Incompetent Tigers">

  <meta name="viewport" content="width=device-width; initial-scale=1.0">


  
    <!-- External CSS -->
  <link href="css/style.css" rel="stylesheet" />
  
</head>
Example #3
0
     # Receive submission of user solution, verify and record best solution
 } else {
     if ($_GET['cmd'] == 'submit') {
         if (isset($_SESSION['visittime'])) {
             $time = time() - $_SESSION['visittime'];
             session_destroy();
         } else {
             $time = 2147483647;
             // MAX_INTEGER
         }
         if (isset($_GET['graph_id']) && isset($_GET['solution'])) {
             $X = $_GET['graph_id'];
             $graph = getGraph($X);
             $selectedEdges = json_decode($_GET['solution'], true);
             if (isValid($selectedEdges, $graph)) {
                 $user_score = calculateScore($selectedEdges, $graph);
                 global $db;
                 $query = "SELECT num_match, match_score, time FROM record WHERE graph_id = " . $X . ";";
                 $res = $db->query($query);
                 if (!$res) {
                     exit("There is a MySQL error, exiting this script");
                 }
                 $best = mysqli_fetch_row($res);
                 $isNewBest = count($selectedEdges) >= $best[0] && $user_score >= $best[1] ? 1 : 0;
                 $isNewHighScore = count($selectedEdges) >= $best[0] && $user_score > $best[1] || count($selectedEdges) == $best[0] && $user_score == $best[1] && $time <= $best[2] ? 1 : 0;
                 if ($isNewHighScore == 1) {
                     $query = "UPDATE record SET num_match = " . count($selectedEdges) . ", match_score = " . $user_score . ", time = " . $time . " WHERE graph_id = " . $X . ";";
                     $res = $db->query($query);
                     if (!$res) {
                         exit("There is a MySQL error, exiting this script");
                     }
Example #4
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/ScrabbleScore.php";
// start session and check for populated word_bank array
// creates empty array if it doesn't exist
session_start();
if (empty($_SESSION['word_bank'])) {
    $_SESSION['word_bank'] = array();
}
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// displays words added to word_bank if any, displays input form
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('scrabblescores' => ScrabbleScore::getAll()));
});
$app->post("/score", function () use($app) {
    // instantiates ScrabbleScore and calculates score
    // $my_ScrabbleScore = new ScrabbleScore($_POST['userword']);
    $my_ScrabbleScore = $_POST['userword'];
    $my_ScrabbleScore_score = calculateScore($my_ScrabbleScore);
    var_dump($my_ScrabbleScore_score);
    $my_ScrabbleScore->save();
    array_push($_SESSION['word_bank'], $my_ScrabbleScore);
    // posts results to score page
    return $app['twig']->render('score.html.twig', array('result' => $my_ScrabbleScore_score, 'original' => $_POST['userword']));
});
$app->post("/delete", function () use($app) {
    ScrabbleScore::deleteAll();
    return $app['twig']->render('deleteScrabbleScore.html.twig');
});
return $app;