/** * function play( $id, $id_param, $back_url ) * @param int $id contains the resource id * @param int $id_param contains the id needed for params retriving * @param string $back_url contain the back url * @return nothing return **/ function play($id, $id_param, $back_url) { require_once $GLOBALS['where_lms'] . '/modules/link/do.link.php'; $this->id = $id; $this->back_url = $back_url; $step = importVar('next_step'); switch ($step) { default: play($this, $id_param); break; } }
} else { $result = 'you win!'; } break; case 'paper': if ($act == 'p') { $result = 'draw this time.'; } elseif ($act == 's') { $result = 'you lose!'; } else { $result = 'you win!'; } break; } } play($act, $com); ?> <!DOCTYPE html> <html> <head> <title>srp-game</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <style type="text/css"> td{text-align:center;} </style> </head> <body> <form action="1.php" method="GET"> <table align="center" border="2" width="70%"> <caption>THE SIMPLE SRP GAME</caption> <tr>
function env_play($id_reference, $back_url, $options = array()) { require_once Docebo::inc(_lms_ . '/modules/scorm/scorm.php'); $this->id_reference = $id_reference; $this->back_url = $back_url; play($this->id, $id_reference, $back_url, true, 'default', $this->environment); }
<?php require_once __DIR__ . "/helpers.php"; // pause the track // ===================================== var_dump(pause()); print PHP_EOL . PHP_EOL; // sleep sleep(3); // resume the track // ===================================== var_dump(resume()); print PHP_EOL . PHP_EOL; // sleep sleep(3); // play the track // ===================================== // our spotify track url var_dump(play("spotify:track:4Tyv7nnNTHC6mR1pTubIrw")); print PHP_EOL . PHP_EOL; // sleep sleep(30); // play the playlist // ===================================== // our spotify track url var_dump(play("spotify:user:djekl:playlist:1AIZcUvQ6f8rnGx7vSGPHN")); print PHP_EOL . PHP_EOL;
echo selectComments(); break; case 'addComment': echo addComment(); break; case 'addUser': echo addUser(); break; case 'updateShareEvent1': echo updateShareEvent1(); break; case 'updateShareEvent2': echo updateShareEvent2(); break; case 'play': echo play(); break; default: $error = array("error" => "Undefined function."); echo json_encode($error); break; } $dbh = null; function isXMLHTTPRequest() { if (!sizeError($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { return true; } else { return false; } }
function playlist_update($playlist) { mp3act_connect(); $query = "SELECT song_id FROM mp3act_playlist WHERE " . playlistCondition() . " ORDER BY pl_id"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $current[] = $row['song_id']; } $current_nr = count($current); $new = explode(",", $playlist); if ($_SESSION['sess_playmode'] != "streaming") { // renumber currently playing song $query = "SELECT mp3act_currentsong.pl_id FROM mp3act_currentsong"; $result = mysql_query($query); if ($row = mysql_fetch_array($result)) { $currently_playing_pl_id = $row['pl_id']; } } if ($current_nr > count($new)) { $query = "DELETE FROM mp3act_playlist WHERE pl_id >=" . count($new) . " AND " . playlistCondition(); mysql_query($query); $current_nr = count($new); } for ($i = 0; $i < $current_nr; $i++) { if ($current[$i] != $new[$i]) { $query = "UPDATE mp3act_playlist SET song_id={$new[$i]} WHERE pl_id={$i} AND " . playlistCondition(); mysql_query($query); } } while ($i < count($new)) { $query = "INSERT INTO mp3act_playlist VALUES({$id}, {$new[$i]}, {$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")"; mysql_query($query); $i++; } if (isset($currently_playing_pl_id)) { $currently_playing_song = $current[$currently_playing_pl_id]; for ($i = 0; $i < count($new) && $new[$i] != $currently_playing_song; $i++) { } if ($i < count($new)) { // found, restore pl_id if ($i != $currently_playing_pl_id) { // moved, so renumber to $i $query = "UPDATE mp3act_currentsong SET mp3act_currentsong.pl_id={$i}"; mysql_query($query); } } else { // currently playing song has been removed from list play("jukebox", "restart", 0); } } }
<?php // hidden iframe to process streaming include "base.inc.php"; if ($_GET['mode'] == 'player') { $mode = 'player'; } else { $mode = 'streaming'; } /* Play the Music */ if (isset($_GET['type'])) { if ($_GET['type'] == 'artists' || $_GET['type'] == 'genre' || $_GET['type'] == 'albums' || $_GET['type'] == 'all') { echo randPlay($mode, $_GET['type'], $_GET['num'], $_GET['items']); } else { echo play($mode, $_GET['type'], $_GET['id']); } } ?>
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program. If not, see <http://www.gnu.org/licenses/>. | // +------------------------------------------------------------------------+ // +------------------------------------------------------------------------+ // | play.php | // +------------------------------------------------------------------------+ require_once 'include/initialize.inc.php'; //require_once('include/library.inc.php'); //require_once('include/config.inc.php'); header('Content-type: application/json'); $action = get('action'); if ($action == 'play') { play(); } elseif ($action == 'pause') { pause(); } elseif ($action == 'stop') { stop(); } elseif ($action == 'prev') { prev_(); } elseif ($action == 'next') { next_(); } elseif ($action == 'playSelect') { playSelect(); } elseif ($action == 'addSelect') { addSelect(); } elseif ($action == 'insertSelect') { insertSelect(); } elseif ($action == 'seekImageMap') {
function drop() { $_SESSION["obj"] = (int) $_GET["obj"]; if ($_SESSION["stuff"][$_SESSION["obj"]] >= 1) { $_SESSION["world"][$_SESSION["room"]]["stuff"][$_SESSION["obj"]] += 1; $_SESSION["stuff"][$_SESSION["obj"]] -= 1; } play(); }
function watchdog() { $app = Slim\Slim::getInstance(); $app->contentType('application/json'); $log = $app->getLog(); $watchdog = getWatchdog(); $newWatchdog = $watchdog; $body = array(); switch ($watchdog) { case 'PLAY': $playlist = readPlaylist(); exec('pgrep omxplayer.bin', $pids); if (sizeof($playlist) > 0) { if (empty($pids)) { // play next from playlist $file = trim($playlist[0]); $log->info("-> watchdog stopped, play " . $file); $playlist = array_slice($playlist, 1); if (writePlaylist($playlist) !== false) { $out = play($file); $body['message'] = $out; } } else { $log->info("-> watchdog playing, wait for end"); } } else { if (empty($pids)) { // out of playlist and player stopped $newWatchdog = 'STOPPED'; $log->info("-> watchdog stopped, no more tracks queued"); } else { $log->info("-> watchdog still playing, no more tracks queued"); } } break; case 'STOP': $newWatchdog = 'STOPPED'; break; default: break; } if ($watchdog != $newWatchdog) { setWatchdog($newWatchdog); } $body['watchdog'] = $newWatchdog; echo json_encode($body); $response = $app->response(); $response["Cache-Control"] = "max-age=5"; $log->info("-> watchdog, status " . $newWatchdog); /* //polling takes too much CPU time if ($newWatchdog == 'PLAY') { usleep(1000000); wakeWatchdog('http://localhost/omxplayer-ui/watchdog'); } */ }
<?php // hidden iframe to process streaming require_once 'modules/music/mp3act_functions.php'; // Play the Music if ('' != $_GET['id']) { echo play($_GET['type'], $_GET['id'], $_GET['quality']); }
fclose($statfd); } } } } else { $out = ''; $err .= 'not running'; } return array('res' => $out, 'err' => $err); } $act = $_REQUEST['act']; unset($result); switch ($act) { case 'play': // Pass arguments $result = play($_REQUEST['arg'], $VIDDIR); break; case 'stop': $result = send('q'); break; case 'pause': $result = send('p'); break; case 'volup': $result = send('+'); break; case 'voldown': $result = send('-'); break; case 'seek-30': $result = send(pack('n', 0x5b44));
function play($radioname, $server, $radiodescription, $labelgenres, $radiohasyp, $statid, $bytessent, $isinitial) { if (file_exists('../d/lock.txt') && microtime(true) - floatval(file_get_contents('../d/lock.txt')) > 120) { unlink('../d/lock.txt'); } $radiofeatured = file_get_contents('../../d/radioFeatured.txt'); $radiobase = file_get_contents('../../d/radioBase.txt'); $nowplayingduration = intval(file_get_contents('../d/nowplayingduration.txt')); $nowplayingurl = file_get_contents('../d/nowplayingurl.txt'); $nowplayingalbum = file_get_contents('../d/nowplayingalbum.txt'); $nowplayingtitle = file_get_contents('../d/nowplayingtitle.txt'); $nowplayingartist = file_get_contents('../d/nowplayingartist.txt'); $expire = floatval(file_get_contents('../d/expire.txt')); $nowplayingbitrate = intval(file_get_contents('../d/nowplayingbitrate.txt')); $starttime = intval(file_get_contents('../d/starttime.txt')); $nexturl = $nowplayingurl; $nextduration = $nowplayingduration; $nextalbum = $nowplayingalbum; $nextartist = $nowplayingartist; $nextbitrate = $nowplayingbitrate; $nexttitle = $nowplayingtitle; while (file_exists('../d/lock.txt')) { $silenttimer = microtime(true); fpassthru('../silence.mp3'); ob_flush(); flush(); usleep(round(1000000 * (0.052 - (microtime(true) - $silenttimer)))); } if (microtime(true) >= $expire && !file_exists('../d/lock.txt')) { file_put_contents('../d/lock.txt', microtime(true)); $apitimestart = microtime(true); $featuredapi = false; $listeners = array_diff(scandir('../d/listeners'), array('..', '.')); foreach ($listeners as $listener) { if (intval(file_get_contents('../d/listeners/' . $listener)) !== $statid) { unlink('../d/listeners/' . $listener); } } $isthislistenercounted = false; foreach ($listeners as $listener) { if (intval(file_get_contents('../d/listeners/' . $listener)) === $statid) { $isthislistenercounted = true; } } if (!$isthislistenercounted) { file_put_contents('../d/listeners/' . microtime(true), $statid); } $dice = rand(1, 10); if ($dice == 1) { $featuredapi = true; if (!$isinitial) { $loop = ceil(floatval(file_get_contents('../d/featuredapitime.txt')) / 0.052); $silent = ''; $silentfile = file_get_contents('../silence.mp3'); for ($i = 0; $i < $loop; $i++) { $silent .= $silentfile; } echo $silent; ob_flush(); flush(); } $featured = explode("\n", $radiofeatured); shuffle($featured); $thisfeatured = $featured[mt_rand(0, count($featured) - 1)]; $featuredbasenamed = explode('/', $thisfeatured); $featuredbasename = array_pop($featuredbasenamed); $apihook = str_replace($featuredbasename, '', $thisfeatured); $apihook = str_replace('/z/', '/api.php', $apihook); $apihook = str_replace('/audio/', '/api.php', $apihook); $apihook .= '?radio=' . urlencode($featuredbasename); $apirequest = file_get_contents($apihook); if (count($apirequest) > 0) { $result = explode("\n", $apirequest); $nexturl = $thisfeatured; $nextartist = $result[0]; $nextalbum = $result[1]; $nexttitle = $result[2]; $nextduration = $result[3]; $nextbitrate = $result[4]; file_put_contents('../d/nowplayingisfeatured.txt', '0'); file_put_contents('../d/starttime.txt', microtime(true)); } } else { if (!$isinitial) { $loop = ceil(floatval(file_get_contents('../d/baseapitime.txt')) / 0.052); $silent = ''; $silentfile = file_get_contents('../silence.mp3'); for ($i = 0; $i < $loop; $i++) { $silent .= $silentfile; } echo $silent; ob_flush(); flush(); } $featured = explode("\n", $radiobase); shuffle($featured); $thisfeatured = $featured[mt_rand(0, count($featured) - 1)]; $featuredbasenamed = explode('/', $thisfeatured); $featuredbasename = array_pop($featuredbasenamed); $apihook = str_replace($featuredbasename, '', $thisfeatured); $apihook = str_replace('/audio/', '/api.php', $apihook); $apihook = str_replace('/z/', '/api.php', $apihook); $apihook .= '?radio=' . urlencode($featuredbasename); $apirequest = file_get_contents($apihook); $result = explode("\n", $apirequest); $nexturl = $thisfeatured; $nextartist = $result[0]; $nextalbum = $result[1]; $nexttitle = $result[2]; $nextduration = $result[3]; $nextbitrate = $result[4]; file_put_contents('../d/nowplayingisfeatured.txt', '1'); file_put_contents('../d/starttime.txt', microtime(true)); } $nowplayingduration = $nextduration; file_put_contents('../d/nowplayingduration.txt', $nowplayingduration); $nowplayingurl = $nexturl; file_put_contents('../d/nowplayingurl.txt', $nowplayingurl); $nowplayingalbum = $nextalbum; file_put_contents('../d/nowplayingalbum.txt', $nowplayingalbum); $nowplayingtitle = $nexttitle; file_put_contents('../d/nowplayingtitle.txt', $nowplayingtitle); $nowplayingartist = $nextartist; file_put_contents('../d/nowplayingartist.txt', $nowplayingartist); $expire = floatval(microtime(true)) + floatval($nextduration); file_put_contents('../d/expire.txt', $expire); $nowplayingbitrate = $nextbitrate; file_put_contents('../d/nowplayingbitrate.txt', $nowplayingbitrate); unlink('../d/lock.txt'); if (file_exists('../d/ypsid.txt') && floatval(trim(file_get_contents('../d/ypexpires.txt'))) < microtime(true)) { $sid = file_get_contents('../d/ypsid.txt'); $nowplaying = html_entity_decode(file_get_contents('../d/nowplayingartist.txt') . ' - ' . file_get_contents('../d/nowplayingtitle.txt')); $listenerscount = count(array_diff(scandir('../d/listeners'), array('.', '..'))); $postdata = http_build_query(array('action' => 'touch', 'sid' => $sid, 'st' => $nowplaying, 'listeners' => $listenerscount)); $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata)); $context = stream_context_create($opts); $handler = fopen('http://dir.xiph.org/cgi-bin/yp-cgi', 'r', false, $context); $meta_data = stream_get_meta_data($handler); $ttl = 0; $save = false; foreach ($meta_data['wrapper_data'] as $response) { if (strtolower(substr($response, 0, 12)) == 'ypresponse: ') { $save = boolval(substr($response, 12)); } } fclose($handler); if ($save) { file_put_contents('../d/ypexpires.txt', microtime(true) + floatval(file_get_contents('../d/ypttl.txt'))); } } if ($featuredapi) { file_put_contents('../d/featuredapitime.txt', microtime(true) - $apitimestart); } else { file_put_contents('../d/baseapitime.txt', microtime(true) - $apitimestart); } } $nowplayingduration = intval(file_get_contents('../d/nowplayingduration.txt')); $nowplayingurl = file_get_contents('../d/nowplayingurl.txt'); $nowplayingalbum = file_get_contents('../d/nowplayingalbum.txt'); $nowplayingtitle = file_get_contents('../d/nowplayingtitle.txt'); $nowplayingartist = file_get_contents('../d/nowplayingartist.txt'); $expire = floatval(file_get_contents('../d/expire.txt')); $nowplayingbitrate = intval(file_get_contents('../d/nowplayingbitrate.txt')); $starttime = intval(file_get_contents('../d/starttime.txt')); $filepath = ''; if (strstr($nowplayingurl, 'clewn.org')) { $filepath = str_replace('http://audio.clewn.org/audio', '../../../audio/clewn/opt/hop/audio', $nowplayingurl); } if (strstr($nowplayingurl, 'cremroad.com')) { $filepath = str_replace('http://cremroad.com/z', '../../z', $nowplayingurl); } $alpha = microtime(true); $hasstarted = file_get_contents('../d/starttime.txt'); $bytestosend = intval($nowplayingbitrate / 8); if (floatval(microtime(true)) < floatval($expire) && $bytestosend >= 1 && $nowplayingurl === file_get_contents('../d/nowplayingurl.txt')) { $initialburstcounter = 0; $thirdtimer = microtime(true); $beta = microtime(true) - $alpha; $burstbytesent = 0; $hassavedfetch = false; $opts = array('http' => array('header' => 'Range: bytes=' . intval(intval($nowplayingbitrate) / 8 * (microtime(true) - floatval($hasstarted) + $beta)) . '-')); $context = stream_context_create($opts); $bravo = microtime(true); $handle = fopen($nowplayingurl, 'rb', false, $context); if ($handle !== false && $nowplayingurl === file_get_contents('../d/nowplayingurl.txt')) { $bursttimer = microtime(true); $bursthassleeped = false; while (!feof($handle) && $nowplayingurl === file_get_contents('../d/nowplayingurl.txt')) { $offset = dothelistenerscount($radioname, $server, $radiodescription, $labelgenres, $radiohasyp, $statid, $expire - microtime(true)); $secondtimer = microtime(true); $bytestoread = $bytestosend + intval($bytetosend * (microtime(true) - $thirdtimer)); $bytesread = 0; $content = ''; $position = ftell($handle); while ($bytesread <= $bytestoread && !feof($handle)) { $content .= fread($handle, 8192); if (!feof($handle)) { $bytesread = $bytesread + 8192; } else { $bytesread = ftell($handle) - $position; } } echo $content; ob_flush(); flush(); if ($initialburstcounter >= 10) { //we send an initial burst of data upon client connection to fill in the cache and prevent cutoff in the first seconds if (!$bursthassleeped) { usleep(1000000); $bursthassleeped = true; } $secondoffset = microtime(true) - $secondtimer; usleep(intval($bytesread / $bytestosend * 1000000 - $offset * 1000000 - $secondoffset * 1000000)); } else { $initialburstcounter++; $burstbytesent = $burstbytesent + $bytesread; } $thirdtimer = microtime(true); } fclose($handle); //and now let's resync just in case eof was reached befor the station clock says next song while (microtime(true) < floatval($expire) && $nowplayingurl === file_get_contents('../d/nowplayingurl.txt')) { $silenttimer = microtime(true); fpassthru('../silence.mp3'); //all I found. Quite hugly ob_flush(); flush(); } } } $isinitial = false; play($radioname, $server, $radiodescription, $labelgenres, $radiohasyp, $statid, $bytessent, $isinitial); }
*/ /* case 'addTracksTitle': $mySqueezeCLI = new SqueezeCLI(addTracksTitle($parameter)); break; */ //action type player: active/désactive met en pause la lecture + le son------------------------------------------------------------------------- case 'playerStatus': echo playerStatus(); break; case 'currentTitle': currentTitle(); break; case 'play': //lance le player exemple: play ->ok $mySqueezeCLI = new SqueezeCLI(play()); break; case 'pause': //met en pause le player exemple: pause ->ok $mySqueezeCLI = new SqueezeCLI(pause()); break; case 'stop': //stop le player exemple: stop ->ok $mySqueezeCLI = new SqueezeCLI(stop()); break; case 'volumeUp': //augmente le volume du mixer de +5 ->ok $mySqueezeCLI = new SqueezeCLI(volumeUp()); break; case 'volumeDown': //réduit le volume du mixer de -5 ->ok
<?php // hidden iframe to process streaming include "includes/grammafone.php"; include_once "includes/sessions.php"; // Play the Music if (isset($_GET['type'])) { if ($_GET['type'] == 'artists' || $_GET['type'] == 'genre' || $_GET['type'] == 'albums' || $_GET['type'] == 'all') { echo randPlay($_SESSION['sess_playmode'], $_GET['type'], $_GET['num'], $_GET['items']); } else { echo play($_SESSION['sess_playmode'], $_GET['type'], $_GET['id']); } } ?>
/** * function play( $id, $id_param, $back_url ) * @param int $id contains the resource id * @param int $id_param contains the id needed for params retriving * @param string $back_url contain the back url * @return nothing return **/ function play($id, $id_param, $back_url) { require_once $GLOBALS['where_lms'] . '/modules/glossary/do.glossary.php'; $this->id = $id; $this->back_url = $back_url; play($this, $id_param); }
$boss = ["hitpoints" => 109, "damage" => 8, "armor" => 2]; $weapons = ["Dagger" => [8, 4, 0], "Shortsword" => [10, 5, 0], "Warhammer" => [25, 6, 0], "Longsword" => [40, 7, 0], "Greataxe" => [74, 8, 0]]; $armors = ["Nothing" => [0, 0, 0], "Leather" => [13, 0, 1], "Chainmail" => [31, 0, 2], "Splintmail" => [53, 0, 3], "Bandedmail" => [75, 0, 4], "Platemail" => [102, 0, 5]]; $rings = ["Nothing" => [0, 0, 0], "Damage1" => [25, 1, 0], "Damage2" => [50, 2, 0], "Damage3" => [100, 3, 0], "Defense1" => [20, 0, 1], "Defense2" => [40, 0, 2], "Defense3" => [80, 0, 3]]; $minCost = PHP_INT_MAX; $maxCost = 0; foreach ($weapons as $weapon) { foreach ($armors as $armor) { foreach ($rings as $k => $ring) { foreach ($rings as $l => $r) { if ($l == $k && $l != "Nothing") { continue; } $me = ["hitpoints" => 100, "damage" => $weapon[1] + $ring[1] + $r[1], "armor" => $armor[2] + $ring[2] + $r[2]]; $cost = $weapon[0] + $armor[0] + $ring[0] + $r[0]; if (play($me, $boss)) { $minCost = min($minCost, $cost); } else { $maxCost = max($maxCost, $cost); } } } } } echo "Part 1: " . $minCost . "\n"; echo "Part 2: " . $maxCost . "\n"; function play($me, $boss) { $myturn = true; while ($me["hitpoints"] > 0 && $boss["hitpoints"] > 0) { if ($myturn) {
function playPollDispatch($object_poll, $id_param) { //-kb-play-// if(!checkPerm('view', true, 'organization') && !checkPerm('view', true, 'storage')) die("You can't access"); require_once _base_ . '/lib/lib.form.php'; require_once $GLOBALS['where_lms'] . '/class.module/track.poll.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.param.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.poll.php'; $id_poll = $object_poll->getId(); $id_reference = getLoParam($id_param, 'idReference'); $url_coded = urlencode(serialize($object_poll->back_url)); $id_track = retriveTrack($id_reference, $id_poll, getLogUserId()); if (isset($_POST['show_result'])) { // continue a poll completed, show the result showResult($object_poll, $id_param); } else { // play poll play($object_poll, $id_param); } }
<?php require_once "../Utilities/functions.php"; error_reporting(E_ALL); ini_set('display_errors', 1); session_start(); header("Access-Control-Allow-Origin: *"); $cmd = getValue("cmd"); if ($cmd == "play") { $response = play(); header('Content-type: application/json'); echo json_encode($response); } else { echo "\n <html>\n <body>\n <h1>API</h1>\n <ul>\n <li>\n <h2>A game that asks you to guess the lucky color.</h2>\n\n <h3>Parameters:</h3>\n <ul>\n <li>cmd=play</li>\n <li>guess[]=color&guess[]=color&...</li>\n </ul>\n\n <h3>Returns:</h3>\n <p>Returns a string telling you if you guessed the lucky color.</p>\n\n <h3>Example:</h3>\n <p><a href='luckyColor.php?cmd=play&guess[]=red&guess[]=green'>?cmd=play&guess[]=red&guess[]=green</a></p>\n <pre>\n ['Try again!']\n </pre>\n </li>\n </ul>\n </body>\n </html>\n "; } function play() { // handle command... $response = "Try again!"; $guesses = getValue("guess"); for ($i = 0; $i < count($guesses); $i++) { if ($guesses[$i] == "pink") { $response = "You win!"; } } return $response; }
function playTestDispatch($object_test, $id_param) { if (!checkPerm('view', true, 'organization') && !checkPerm('view', true, 'storage')) { die("You can't access"); } require_once _base_ . '/lib/lib.form.php'; require_once $GLOBALS['where_lms'] . '/class.module/track.test.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.param.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.test.php'; $lang =& DoceboLanguage::createInstance('test'); $id_test = $object_test->getId(); $id_reference = getLoParam($id_param, 'idReference'); $url_coded = urlencode(serialize($object_test->back_url)); $id_track = retriveTrack($id_reference, $id_test, Docebo::user()->getIdst()); if (isset($_POST['restart'])) { //delete existing track and begin the test $test_man = new TestManagement($id_test); $play_man = new PlayTestManagement($id_test, Docebo::user()->getIdst(), $id_track, $test_man); $score_status = $play_man->getScoreStatus(); $max_attempt = $test_man->getTestInfo('max_attempt'); if ($max_attempt > 0) { $track_info = Track_Test::getTrackInfoById($id_track); if ($max_attempt - $track_info['number_of_attempt'] <= 0) { //$GLOBALS['page']->add($lang->def('_MAX_ATTEMPT_REACH'), 'content'); $GLOBALS['page']->add(Lang::t('_MAX_ATTEMPT_REACH', 'test'), 'content'); $GLOBALS['page']->add(Form::closeForm() . '</div>', 'content'); return; } } $is_end = $score_status == 'valid' || $score_status == 'not_checked' || $score_status == 'passed' || $score_status == 'not_passed'; if ($score_status == 'not_complete' || $is_end) { resetTrack($object_test->getId(), importVar('idTrack', true, 0)); } play($object_test, $id_param); } elseif (isset($_POST['test_save_keep'])) { // continue a test completed, show the result saveAndExit($object_test, $id_param); } elseif (isset($_POST['show_result'])) { // continue a test completed, show the result showResult($object_test, $id_param); } elseif (isset($_POST['time_elapsed']) && $_POST['time_elapsed'] == '1') { // continue a test completed, show the result showResult($object_test, $id_param); } else { // play test play($object_test, $id_param); } }
function play($w, $b, $spells, $hardmode, $init = false) { static $minCost; if ($init) { $minCost = PHP_INT_MAX; } if ($w->getCost() >= $minCost) { return $minCost; } logger("\n-- Wizard's turn --\n"); if ($hardmode) { $w->hit(1); if (!$w->alive()) { return $minCost; } } $w->dump(); $b->dump(); $w->attack($b); if (!$b->alive()) { logger("Boss is dead!\n"); if ($w->getCost() < $minCost) { $minCost = $w->getCost(); } return $minCost; } $affordableSpells = array_filter($spells, function ($spell) use($w) { return $w->getMana() >= $spell->price(); }); if (count($affordableSpells) == 0) { logger("Can't afford any spells. Wizard is dead."); return $minCost; } foreach ($affordableSpells as $spell) { logger("SPELL: " . $spell->getName() . "\n"); $wizard = clone $w; $boss = clone $b; if (!$wizard->buySpell($spell, $boss)) { continue; } if ($wizard->getCost() >= $minCost) { continue; } logger("\n-- Boss turn --\n"); $wizard->dump(); $boss->dump(); $wizard->attack($boss); if (!$boss->alive()) { logger("Boss is dead!\n"); if ($wizard->getCost() < $minCost) { $minCost = $wizard->getCost(); } continue; } $boss->attack($wizard); if (!$wizard->alive()) { logger("Wizard is dead!\n"); continue; } $minCost = play($wizard, $boss, $spells, $hardmode); #echo "mincost: $minCost, " . $wizard->getCost() . "\n"; } return $minCost; }
* Play the numbers game * * @param sting|int $number * @return string */ function play($number) { $ret = ''; $last = null; $counter = 0; for ($i = 0, $j = strlen($number); $i < $j; $i++) { // Start if ($last === null) { $last = $number[$i]; } else { if ($last !== $number[$i]) { // Process $ret .= $counter . $last; $last = $number[$i]; $counter = 0; } } $counter++; } return $ret . $counter . $last; } $input = '1113122113'; for ($i = 0; $i < 40; $i++) { $input = play($input); } echo 'Total number length after 40 turns: ' . strlen($input) . PHP_EOL;
Note: you cannot form multiple digit numbers from the supplied digits, so an answer of 12+12 when given 1, 2, 2, and 1 would not be allowed. <?php while (true) { $numbers = make_numbers(); for ($iteration_num = 1;; $iteration_num++) { echo "Expresion {$iteration_num}: "; $entry = rtrim(fgets(STDIN)); if ($entry === '!') { break; } if ($entry === 'q') { exit; } $result = play($numbers, $entry); if ($result === null) { echo "That's not valid\n"; continue; } elseif ($result != 24) { echo "Sorry, that's {$result}\n"; continue; } else { echo "That's right! 24!!\n"; exit; } } } function make_numbers() { $numbers = array();
/** * @param int $id contains the resource id * @param int $id_param contains the id needed for params retriving * @param string $back_url contain the back url */ function play($id, $id_param, $back_url) { require_once _lms_ . '/modules/item/do.item.php'; $this->id = $id; $this->back_url = $back_url; play($id, $id_param, $back_url); }