2024-05-04 07:40:23 +00:00
|
|
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width">
|
|
|
|
<?
|
|
|
|
|
2024-05-04 07:44:54 +00:00
|
|
|
// ini_set('display_errors', 1);
|
|
|
|
// ini_set('display_startup_errors', 1);
|
|
|
|
// error_reporting(E_ALL);
|
|
|
|
|
2024-05-04 07:40:23 +00:00
|
|
|
include("functions.php");
|
|
|
|
include("../levels.php");
|
|
|
|
|
|
|
|
$parameters_valid = true;
|
|
|
|
$program_valid = 0;
|
|
|
|
|
|
|
|
if ( isset( $_GET['level'] ) && !empty( $_GET['level'] )){
|
|
|
|
if(is_numeric( $_GET['level'] )){
|
|
|
|
$level = $_GET['level'];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// echo("level value invalid<br>");
|
|
|
|
$level = 1;
|
|
|
|
$parameters_valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{ //no level given
|
|
|
|
$level = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $_POST['asm'] ) && !empty( $_POST['asm'] )){
|
|
|
|
$asm = $_POST['asm'];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// echo("asm invalid<br>");
|
|
|
|
$parameters_valid = false;
|
|
|
|
$asm = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
$level_configuration_function = "level_" . $level . "_configuration"; //build function name, see http://php.net/manual/de/functions.variable-functions.php
|
|
|
|
$level_description_function = "";
|
|
|
|
$level_test_function = "";
|
|
|
|
if(is_callable($level_configuration_function)) { // The function does not exists
|
|
|
|
$level_description_function = "level_" . $level . "_description"; //build function name, see http://php.net/manual/de/functions.variable-functions.php
|
|
|
|
$level_test_function = "level_" . $level . "_test"; //build function name, see http://php.net/manual/de/functions.variable-functions.php
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// echo("level $level_configuration_function unknown<br>");
|
|
|
|
$parameters_valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if($parameters_valid == true){ //parameters are ok, level is known
|
|
|
|
list($title, $description, $example, $criteria, $passcode) = $level_description_function(); // call function level_*_description()
|
|
|
|
// echo("$title, $description, $example, $criteria, $passcode<br>");
|
|
|
|
// }
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<title><? echo("$GC_ID: $GC_NAME"); ?> - Programm ausführen (Level <? echo("$level: \"$title\""); ?>)</title>
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>
|
|
|
|
<script src="human-resource-machine-viewer/pako_inflate.min.js"></script>
|
|
|
|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
|
|
|
<link href="human-resource-machine-viewer/hrm.css" rel="stylesheet">
|
|
|
|
<link href="stylesheet.css" rel="stylesheet">
|
|
|
|
<script src="human-resource-machine-viewer/hrm.js"></script>
|
|
|
|
<script src="functions.js"></script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
<body onload="page_loaded();">
|
|
|
|
<h1><? echo("$GC_ID: $GC_NAME"); ?> - Programm ausführen (Level <? echo("$level: \"$title\""); ?>)</h1>
|
|
|
|
<div class="hrmcode">
|
|
|
|
<a href="editor.php?level=<? echo($level); ?>&passcode=<? echo($_GET['passcode']); ?>">< Zurück zum Code Editor</a>
|
|
|
|
</div>
|
|
|
|
<?
|
|
|
|
|
|
|
|
// echo("Level: \"$level\"<br>");
|
|
|
|
// echo("$title, $description, $example, $criteria<br>");
|
|
|
|
// $parameters_valid = true;
|
|
|
|
|
|
|
|
|
|
|
|
// echo("Passcode: $passcode, given: " . $_GET['passcode'] . "<br>");
|
|
|
|
if($passcode != $_GET['passcode']){ //passcode is wrong, level not allowed
|
|
|
|
?>
|
|
|
|
<h2><font color=darkred>Der Passcode für das angegebene Level ist ungültig!<br>
|
|
|
|
Versuchs mal mit <a href="editor.php?level=1">Level 1</a>.</font></h2>
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
else if($asm == ""){
|
|
|
|
?>
|
|
|
|
<h2><font color=darkred>Kein Programm-Code übergeben!</font></h2>
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
else if($parameters_valid == false){
|
|
|
|
echo("Level: $level<br>");
|
|
|
|
?>
|
|
|
|
<h2><font color=darkred>Das angegebene Level existiert nicht!<br>
|
|
|
|
Versuchs mal mit <a href="editor.php?level=1">Level 1</a>.</font></h2>
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
else{ //parameters are ok, level is known
|
|
|
|
$arr_asm = preg_split('/[\r\n]+/', $asm);
|
|
|
|
|
|
|
|
//Workaround, see https://github.com/AlanDeSmet/human-resource-machine-viewer/issues/7
|
|
|
|
// if(strpos($asm, "-- HUMAN RESOURCE MACHINE PROGRAM --") === FALSE){ //line missing, add it
|
|
|
|
// array_unshift($arr_asm, "-- HUMAN RESOURCE MACHINE PROGRAM --");
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// echo("<pre>");
|
|
|
|
// print_r($arr_asm);
|
|
|
|
// echo("</pre>");
|
|
|
|
array_walk($arr_asm, 'cleanup_asm_array');
|
|
|
|
$arr_asm = array_slice(array_diff($arr_asm, array('')), 0); //Remove all empty lines from array
|
|
|
|
// echo("<pre>");
|
|
|
|
// print_r($arr_asm);
|
|
|
|
// echo("</pre>");
|
|
|
|
|
|
|
|
|
|
|
|
list($program_valid, $program, $program_summary, $instruction_counter, $labels_counter, $comments_counter) = init_program($arr_asm, $level, $passcode);
|
|
|
|
// if($program_valid != true){$program_valid = 0; }
|
|
|
|
// echo("instruction_counter: $instruction_counter, <br>");
|
|
|
|
// echo("program_valid: \"$program_valid\"<br>");
|
|
|
|
|
|
|
|
$debug = false;
|
2024-05-04 07:44:54 +00:00
|
|
|
if($program[0]['cmd'] == 'comment'){
|
|
|
|
if($program[0]['comment'] == '--debug'){
|
2024-05-04 07:40:23 +00:00
|
|
|
echo("<h1><font color=red>DEBUG Modus</font></h1>");
|
|
|
|
$debug = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($debug == true){
|
|
|
|
echo("<pre>Program Data:\nUsed Instruction: $instruction_counter\n");
|
|
|
|
echo("Program: ");
|
|
|
|
print_r($program);
|
|
|
|
echo("</pre>");
|
|
|
|
echo("<hr>");
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Initialize the level and test it with several random inputs
|
|
|
|
***********************************************************/
|
|
|
|
// list($inbox_size, $max_allowed_steps, $maximum_allowed_instruction, $hand, $data_registers, $test_runs, $reward, $show_outbox_as_coordinate) = $level_configuration_function(); // call function level_*_configuration()
|
|
|
|
$level_configuration = $level_configuration_function(); // call function level_*_configuration()
|
|
|
|
|
|
|
|
if($debug == true){
|
|
|
|
echo "<pre>Level Configuration: ";
|
|
|
|
print_r($level_configuration);
|
|
|
|
echo("</pre>");
|
|
|
|
echo("<hr>");
|
|
|
|
}
|
|
|
|
|
|
|
|
// echo("Reward: $reward<br>");
|
|
|
|
|
|
|
|
|
|
|
|
// list($program_outcome, $inbox, $expected_outbox, $outbox, $hand, $data_registers, $effectively_used_steps, $max_used_steps) =
|
|
|
|
// $level_test_function($program, $max_allowed_steps, $inbox_size, $hand, $data_registers, $test_runs); // call function level_*_test()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Test the program with many iterations
|
|
|
|
***********************************************************/
|
|
|
|
if($debug == true){
|
|
|
|
echo "<pre>Testing program with many iterations...</pre>";
|
|
|
|
}
|
|
|
|
|
|
|
|
list($program_outcome, $inbox, $expected_outbox, $average_effectively_used_steps, $max_used_steps, $program_quality) =
|
|
|
|
test_program_with_iterations($program, $level_configuration);
|
|
|
|
|
|
|
|
if($debug == true){
|
|
|
|
echo "<pre>Level Status: $program_outcome ($program_quality)\n";
|
|
|
|
echo("Run iterations: " . $level_configuration["test_runs"] . " (level setting)\n");
|
|
|
|
echo("Average effectively used steps: $average_effectively_used_steps\n");
|
|
|
|
echo("Maximum used steps: $max_used_steps\n");
|
|
|
|
echo("Max allowed steps: " . $level_configuration["max_allowed_steps"] . " (level setting)\n");
|
|
|
|
echo("</pre>");
|
|
|
|
echo("<hr>");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Test the program for the specific level with the shown inputs
|
|
|
|
***********************************************************/
|
|
|
|
if($debug == true){
|
|
|
|
echo "<pre>Testing the program with the shown inputs...</pre>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// list($program_outcome, $effectively_used_steps) = test_program($program, $inbox, $expected_outbox, $hand, $data_registers, $max_allowed_steps);
|
|
|
|
list($program_outcome, $effectively_used_steps) = test_program($program, $inbox, $expected_outbox, $level_configuration["hand"], $level_configuration["data_registers"], $level_configuration["max_allowed_steps"]);
|
|
|
|
|
|
|
|
if($debug == true){
|
|
|
|
echo "<pre>Level Status: $program_outcome\n";
|
|
|
|
echo("Inbox: ");
|
|
|
|
print_r($inbox);
|
|
|
|
echo("Expected Outbox: ");
|
|
|
|
print_r($expected_outbox);
|
|
|
|
echo("</pre>");
|
|
|
|
echo("<hr>");
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<table><tr>
|
|
|
|
<td valign="top">
|
|
|
|
<h2>Sandbox</h2>
|
|
|
|
<div class="control_box">
|
|
|
|
<div style="margin-left: 10px; margin-top: 10px;">
|
|
|
|
<table><tr>
|
|
|
|
<td><button id="play" title="Play" hidden><img src="images/play.png" height=40px><br>Play</button></td>
|
|
|
|
<td><button id="pause" title="Pause" hidden><img src="images/pause.png" height=40px><br>Pause</button></td>
|
|
|
|
<td><button id="reset" title="Neustart" hidden><img src="images/reset.png" height=40px><br>Neustart</button></td>
|
|
|
|
<td><button id="previous" title="Vorhergehender Schritt" hidden><img src="images/previous.png" height=40px><br>Zurück</button></td>
|
|
|
|
<td><button id="next" title="Nächster Schritt" hidden><img src="images/next.png" height=40px><br>Weiter</button></td>
|
|
|
|
<td><span id="slider_control" hidden>Geschwindigkeit:<br>
|
|
|
|
<input type="range" id="speed_slider" min="100" max="2100" step="500" value="600" autocomplete="off" onchange="changeSpeed(2100-this.value);"><br>< Langsam .... Schnell ></span></td>
|
|
|
|
</tr></table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<?
|
|
|
|
/***********************************************************
|
|
|
|
* Prepare and show the shown version of the program execution
|
|
|
|
***********************************************************/
|
|
|
|
// $step_boxes = generate_program_steps($program, $inbox, $expected_outbox, $hand, $data_registers, $max_allowed_steps, $effectively_used_steps, $maximum_allowed_instruction, $instruction_counter, count($inbox), count($expected_outbox), $reward, $show_outbox_as_coordinate, $level, $passcode);
|
|
|
|
$step_boxes = generate_program_steps($program, $inbox, $expected_outbox, $level_configuration["hand"], $level_configuration["data_registers"], $level_configuration["max_allowed_steps"], $effectively_used_steps, $level_configuration["max_allowed_instruction"], $instruction_counter, count($inbox), count($expected_outbox), $level_configuration["reward"], $level_configuration["show_outbox_as_coordinate"], $level, $passcode);
|
|
|
|
|
|
|
|
if($debug == true){
|
|
|
|
echo("<pre>Program Steps: ");
|
|
|
|
foreach($step_boxes as $step){ echo("$step, "); };
|
|
|
|
echo("</pre>");
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
<div class="step_boxes init_box" id="step_box_init_0">
|
|
|
|
<div style="padding-left: 20px;" id="init_box_content">
|
|
|
|
<div style="margin-top: 30px;"><div class="hrmcode">Initialisiere CPU...<br></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</td><td valign="top">
|
|
|
|
<div style="margin-left: 50px;">
|
|
|
|
<h2>Formatierter Programm-Code</h2>
|
|
|
|
<div class="hrmcode" id="code" style="width: 400px;">Laden...</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr></table>
|
|
|
|
|
|
|
|
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var hrmv;
|
|
|
|
var step = 0;
|
|
|
|
var init_step = 1;
|
|
|
|
var speed = 2100-600;
|
|
|
|
var timer;
|
|
|
|
var running = false;
|
|
|
|
var steps = [ <? foreach($step_boxes as $step){ echo("$step, "); }; ?> ];
|
|
|
|
|
|
|
|
console.log("Steps: " + steps);
|
|
|
|
console.log("Speed: " + speed);
|
|
|
|
|
|
|
|
|
|
|
|
function page_loaded(){
|
|
|
|
<?
|
2024-05-04 07:44:54 +00:00
|
|
|
if(($program[0]['cmd'] == "comment") && ($program[0]['comment'] == "--debug")){ //we are in debug mode
|
2024-05-04 07:40:23 +00:00
|
|
|
?>
|
|
|
|
console.log("### We are in DEBUG Mode!!!");
|
|
|
|
$("#init_box_content").html(init_box_content);
|
|
|
|
$("#play").show();
|
|
|
|
// $("#pause").show();
|
|
|
|
$("#reset").show();
|
|
|
|
$("#previous").show();
|
|
|
|
$("#next").show();
|
|
|
|
$("#slider_control").show();
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
}
|
|
|
|
|
|
|
|
function fonts_loaded() {
|
|
|
|
var asm = <? foreach($arr_asm as $line){ echo("'$line\\n' +\n"); } echo("''"); ?>;
|
|
|
|
hrmv = new HRMViewer('code', asm );
|
|
|
|
|
|
|
|
|
|
|
|
//Start showing boot procedure
|
|
|
|
timer = setTimeout(init_cpu, 1000, "<? echo($program_summary); ?>", <? echo($program_valid); ?>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$( "#play" ).click(function() {
|
|
|
|
console.log( "play clicked, speed is: " + speed);
|
|
|
|
$("#play").hide();
|
|
|
|
$("#pause").show();
|
|
|
|
running = true;
|
|
|
|
next_instruction(); //start it
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#pause" ).click(function() {
|
|
|
|
console.log( "pause clicked" );
|
|
|
|
$("#play").show();
|
|
|
|
$("#pause").hide();
|
|
|
|
running = false;
|
|
|
|
clearTimeout(timer);
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#reset" ).click(function() {
|
|
|
|
console.log( "reset clicked" );
|
|
|
|
$("#play").show();
|
|
|
|
$("#pause").hide();
|
|
|
|
running = false;
|
|
|
|
clearTimeout(timer);
|
|
|
|
step = 0;
|
|
|
|
show_instruction();
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#previous" ).click(function() {
|
|
|
|
console.log( "previous clicked" );
|
|
|
|
$("#play").show();
|
|
|
|
$("#pause").hide();
|
|
|
|
running = false;
|
|
|
|
clearTimeout(timer);
|
|
|
|
step = step - 1;
|
|
|
|
if(step < 0){
|
|
|
|
step = 0;
|
|
|
|
}
|
|
|
|
show_instruction();
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#next" ).click(function() {
|
|
|
|
console.log( "next clicked" );
|
|
|
|
$("#play").show();
|
|
|
|
$("#pause").hide();
|
|
|
|
running = false;
|
|
|
|
clearTimeout(timer);
|
|
|
|
step = step + 1;
|
|
|
|
if(step >= (steps.length)){
|
|
|
|
step = steps.length - 1;
|
|
|
|
}
|
|
|
|
show_instruction();
|
|
|
|
});
|
|
|
|
|
|
|
|
// $( "#speed_slider" ).slider(function() {
|
|
|
|
// speed = $("#speed_slider").val();
|
|
|
|
// console.log( "speed is now: " + speed);
|
|
|
|
// });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WebFont.load({
|
|
|
|
google: { families: ['Passion One'] },
|
|
|
|
active: fonts_loaded,
|
|
|
|
inactive: fonts_loaded,
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
|