Init
201
hrm/editor.php
Executable file
@ -0,0 +1,201 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
||||||
|
<?
|
||||||
|
include("functions.php");
|
||||||
|
include("../levels.php");
|
||||||
|
|
||||||
|
|
||||||
|
if ( isset( $_GET['level'] ) && !empty( $_GET['level'] ) && is_numeric( $_GET['level'] )){
|
||||||
|
$level = $_GET['level'];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("level value invalid<br>");
|
||||||
|
$level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level_description = "level_" . $level . "_description"; //build function name, see http://php.net/manual/de/functions.variable-functions.php
|
||||||
|
// echo("Function name: \"$level_description\"<br>");
|
||||||
|
if(is_callable($level_description)) { // The function exists
|
||||||
|
$parameters_valid = true;
|
||||||
|
list($title, $description, $example, $criteria, $passcode) = $level_description();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$parameters_valid = false;
|
||||||
|
$passcode = "";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<title><? echo("$GC_ID: $GC_NAME"); ?> - Code Editor (Level <? echo("$level: \"$title\""); ?>)</title>
|
||||||
|
<head>
|
||||||
|
<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>
|
||||||
|
</head>
|
||||||
|
<body onload="page_loaded();">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var hrmv;
|
||||||
|
var default_source = "-- Füge deinen Programm-Code in den Code Editor ein.\n-- Zum Beispiel:\n\tINBOX\n\tOUTBOX\n-- Wenn Du danach auf Play drückst, wird dein Programm in einem neuen Fenster ausgeführt!";
|
||||||
|
|
||||||
|
function page_loaded(){
|
||||||
|
var program = "";
|
||||||
|
|
||||||
|
try{
|
||||||
|
// Store
|
||||||
|
localStorage.setItem("local_storage_test", "1234567890");
|
||||||
|
// retrieve again
|
||||||
|
if(localStorage.getItem("local_storage_test") == "1234567890"){ //local storage is working
|
||||||
|
console.log("local storage is working");
|
||||||
|
document.getElementById("local_storage_check").innerHTML = "";
|
||||||
|
program = localStorage.getItem("<? echo($GC_ID); ?>_Level_<? echo($level); ?>"); //load program from storage
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.log("Local storage is NOT working!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e){ //fail, local storage doesnt work
|
||||||
|
console.log("Local storage is NOT working!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(program != ""){
|
||||||
|
console.log("Loaded program:");
|
||||||
|
console.log(program);
|
||||||
|
$('#code_editor').val(program); //load program from local storrage and put it into the editor field
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#code_editor').val(default_source); //load default program
|
||||||
|
}
|
||||||
|
font_loaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function font_loaded() {
|
||||||
|
// if($('#code_editor').val() != ""){
|
||||||
|
source = $('#code_editor').val() + "\n";
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// source = default_source;
|
||||||
|
// }
|
||||||
|
hrmv = new HRMViewer('code', source);
|
||||||
|
|
||||||
|
$('#code_editor').bind('input propertychange', function() {
|
||||||
|
// if(this.value != ""){
|
||||||
|
source = this.value + "\n";
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// source = default_source;
|
||||||
|
// }
|
||||||
|
hrmv = new HRMViewer('code', source);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#code_editor").keydown(function(e) {
|
||||||
|
console.log("tab");
|
||||||
|
if(e.keyCode === 9) { // tab was pressed
|
||||||
|
// get caret position/selection
|
||||||
|
var start = this.selectionStart;
|
||||||
|
end = this.selectionEnd;
|
||||||
|
|
||||||
|
var $this = $(this);
|
||||||
|
|
||||||
|
// set textarea value to: text before caret + tab + text after caret
|
||||||
|
$this.val($this.val().substring(0, start)
|
||||||
|
+ "\t"
|
||||||
|
+ $this.val().substring(end));
|
||||||
|
|
||||||
|
// put caret at right position again
|
||||||
|
this.selectionStart = this.selectionEnd = start + 1;
|
||||||
|
|
||||||
|
// prevent the focus lose
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WebFont.load({
|
||||||
|
google: { families: ['Passion One'] },
|
||||||
|
active: font_loaded,
|
||||||
|
inactive: font_loaded,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function save_program(){
|
||||||
|
//Use local storage, see http://www.w3schools.com/html/html5_webstorage.asp
|
||||||
|
localStorage.setItem("<? echo($GC_ID); ?>_Level_<? echo($level); ?>", $('#code_editor').val());
|
||||||
|
console.log("Program saved to LocalStorage Facility of Level <? echo($level); ?>");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div style="width: 800px">
|
||||||
|
<h1><nobr><? echo("$GC_ID: $GC_NAME"); ?> - Code Editor (Level <? echo("$level: \"$title\""); ?>)</nobr></h1>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?
|
||||||
|
// echo("Passcode: $passcode, given: " . $_GET['passcode'] . "<br>");
|
||||||
|
if($passcode != $_GET['passcode']){ //passcode is wrong, level not allowed
|
||||||
|
?>
|
||||||
|
<h2><font color=darkred>Der Pacsscode für das angegebene Level ist ungültig!<br>
|
||||||
|
Versuchs mal mit <a href="editor.php?level=1">Level 1</a>.</font></h3>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
else if($parameters_valid == true){
|
||||||
|
?>
|
||||||
|
<h2>Aufgabe</h2>
|
||||||
|
<div class="hrmcode"> <?echo($description); ?></div>
|
||||||
|
|
||||||
|
<h2>Beispiel (Die erste Box ist jeweils die Box ganz rechts)</h2>
|
||||||
|
<div class="hrmcode box_float_left"><? echo($example); ?></div><div style="clear: both;"></div>
|
||||||
|
|
||||||
|
<h2>Test-Kriterien</h2>
|
||||||
|
<div class="hrmcode"><? echo($criteria); ?></div><br>
|
||||||
|
|
||||||
|
<div id="local_storage_check" style="margin:0px;"><font color=darkred>Hmm, dein Browser unterstützt leider kein <a href="https://de.wikipedia.org/wiki/Web_Storage" target="_blank">lokales speichern</a>. D.h., Du musst selber dafür sorgen, dass Du dein Programm zwischenspeicherst, befor Du es ausführst!</font></div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<table><tr>
|
||||||
|
<td valign=top>
|
||||||
|
<h2>Programm-Code Editor</h2>
|
||||||
|
<form id=CodeEditorForm action="run.php?level=<? echo($level); ?>&passcode=<? echo($passcode); ?>" method="post" target="_self">
|
||||||
|
<button id="play" title="Play" onclick="save_program()"><img src="images/play.png" height=40px><br>Play</button>
|
||||||
|
<div style="float: right; margin: 10px"><a href="help.htm" target="_blank"><img src="images/help.png" height=50px></a></div> <br>
|
||||||
|
|
||||||
|
<textarea id=code_editor name=asm autocomplete="off" rows="30" cols="40" placeholder="-- Füge deinen Programm-Code in den Code Editor ein.">
|
||||||
|
</textarea >
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</td><td valign=top>
|
||||||
|
<h2>Formatierter Programm-Code</h2>
|
||||||
|
<div class="hrmcode" id="code" style="width: 400px;">Lade Programm...</div>
|
||||||
|
</td><td valign=top>
|
||||||
|
<h2></h2>
|
||||||
|
<div style="width: 100px;"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
else{//level does not exist
|
||||||
|
?>
|
||||||
|
Das angegebene Level existiert nicht!<br>
|
||||||
|
Versuchs mal mit <a href="editor.php?level=1">Level 1</a>.
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
134
hrm/functions.js
Executable file
@ -0,0 +1,134 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function changeSpeed(value){
|
||||||
|
speed = value;
|
||||||
|
console.log("speed is now: " + speed);
|
||||||
|
if(running == true){
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(next_instruction, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function next_instruction(){
|
||||||
|
if(step == (steps.length)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
show_instruction();
|
||||||
|
|
||||||
|
step = step + 1;
|
||||||
|
if(step < (steps.length )){
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(next_instruction, speed);
|
||||||
|
}
|
||||||
|
else{ //end
|
||||||
|
step = step - 1;
|
||||||
|
// console.log("last step");
|
||||||
|
// show_instruction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function show_instruction(){
|
||||||
|
|
||||||
|
// document.getElementById("next").disabled = true;
|
||||||
|
// $("#next").disabled = true;
|
||||||
|
|
||||||
|
var active_line;
|
||||||
|
var shown_step;
|
||||||
|
$("#init_box_content").hide();
|
||||||
|
$(".step_boxes").hide();
|
||||||
|
|
||||||
|
if(step < steps.length){
|
||||||
|
active_line = steps[step];
|
||||||
|
shown_step = step + 1;
|
||||||
|
}
|
||||||
|
else{ //end
|
||||||
|
active_line = 0;
|
||||||
|
shown_step = step;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#step_" + (step + 1) + "_box").show();
|
||||||
|
|
||||||
|
if(shown_step == 1){
|
||||||
|
document.getElementById("previous").disabled = true;
|
||||||
|
}
|
||||||
|
else if(shown_step == steps.length){
|
||||||
|
document.getElementById("next").disabled = true;
|
||||||
|
console.log("last step (" + shown_step + "/" + steps.length + ": \"" + steps[step] + "\"), disable 'next' button");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
document.getElementById("previous").disabled = false;
|
||||||
|
document.getElementById("next").disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hrmv.setActiveLine(active_line);
|
||||||
|
console.log("current step: " + shown_step + "/" + steps.length + ": \"" + steps[step] + "\" => Set active line to " + active_line + " and show step " + shown_step + " => " + "#step_" + (shown_step) + "_box");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function init_cpu(summary, program_quality){
|
||||||
|
var init_box_content = $("#init_box_content").html();
|
||||||
|
var style ="<div class=\"hrmcode\">";
|
||||||
|
|
||||||
|
// if(init_step == 0){
|
||||||
|
// init_box_content = init_box_content + "<br>Initializing CPU...<br>";
|
||||||
|
// }
|
||||||
|
if(init_step == 1){
|
||||||
|
init_box_content = init_box_content + style + "Überprüfe Hand...<br>";
|
||||||
|
}
|
||||||
|
else if(init_step == 2){
|
||||||
|
init_box_content = init_box_content + style + "Überprüfe Daten-Register...<br>";
|
||||||
|
}
|
||||||
|
// else if(init_step == 2){
|
||||||
|
// init_box_content = init_box_content + "1... ";
|
||||||
|
// }
|
||||||
|
// else if(init_step == 3){
|
||||||
|
// init_box_content = init_box_content + "2... ";
|
||||||
|
// }
|
||||||
|
// else if(init_step == 4){
|
||||||
|
// init_box_content = init_box_content + "3... </br>";
|
||||||
|
// }
|
||||||
|
else if(init_step == 3){
|
||||||
|
init_box_content = init_box_content + style + "Überprüfe Inbox...<br>";
|
||||||
|
}
|
||||||
|
else if(init_step == 4){
|
||||||
|
init_box_content = init_box_content + style + "Überprüfe Outbox...<br>";
|
||||||
|
}
|
||||||
|
else if(init_step == 5){
|
||||||
|
init_box_content = init_box_content + style + "Lade Programm...<br>";
|
||||||
|
}
|
||||||
|
else if(init_step == 6){
|
||||||
|
init_box_content = init_box_content + style + summary + "<br>";
|
||||||
|
if(program_quality == 0){
|
||||||
|
$("#init_box_content").html(init_box_content);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //last step
|
||||||
|
init_box_content = init_box_content + style + "Drücke Play um das Programm zu starten";
|
||||||
|
$("#init_box_content").html(init_box_content);
|
||||||
|
$("#play").show();
|
||||||
|
// $("#pause").show();
|
||||||
|
$("#reset").show();
|
||||||
|
$("#previous").show();
|
||||||
|
$("#next").show();
|
||||||
|
$("#slider_control").show();
|
||||||
|
document.getElementById("previous").disabled = true;
|
||||||
|
document.getElementById("next").disabled = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#init_box_content").html(init_box_content);
|
||||||
|
|
||||||
|
init_step = init_step + 1;
|
||||||
|
timer = setTimeout(init_cpu, 500, summary, program_quality);
|
||||||
|
}
|
||||||
|
|
888
hrm/functions.php
Executable file
@ -0,0 +1,888 @@
|
|||||||
|
<?
|
||||||
|
|
||||||
|
|
||||||
|
define("PROGRAM_IS_CORRECT", "PROGRAM_IS_CORRECT");
|
||||||
|
define("PROGRAM_TAKES_TOO_MANY_EFFECTIVE_STEPS", "PROGRAM_TAKES_TOO_MANY_EFFECTIVE_STEPS");
|
||||||
|
define("PROGRAM_IS_WRONG", "PROGRAM_IS_WRONG");
|
||||||
|
|
||||||
|
define("SUCCESS", "SUCCESS");
|
||||||
|
define("FAIL", "FAIL");
|
||||||
|
|
||||||
|
error_reporting(E_ERROR | E_PARSE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize the program
|
||||||
|
* Count the effective program lines (without empty/labels)
|
||||||
|
*/
|
||||||
|
function init_program($arr_asm, $level, $passcode){
|
||||||
|
$back_to_editor = "<br><br>Gehe wieder zum Editor-Fenster <a href=editor.php?level=$level&passcode=$passcode>zurück</a>, um deinen Programm-Code zu verbessern. Viel Glück!";
|
||||||
|
$program = array();
|
||||||
|
|
||||||
|
// $inbox = array_reverse($inbox);
|
||||||
|
|
||||||
|
// echo("<h3>Parse Program</h3>");
|
||||||
|
// echo("<div class=frame>");
|
||||||
|
|
||||||
|
$instruction_counter = 0;
|
||||||
|
$program_line_counter = 0;
|
||||||
|
$comments_counter = 0;
|
||||||
|
$labels_counter = 0;
|
||||||
|
foreach($arr_asm as $line){
|
||||||
|
$line = trim($line);
|
||||||
|
$line = preg_replace('!\s+!', ' ', $line); // Replacing multiple spaces with a single space
|
||||||
|
@list($cmd, $param) = explode(" ", $line);
|
||||||
|
|
||||||
|
|
||||||
|
// echo($program_line_counter + 1 . ": cmd = \"$cmd\", param = \"$param\"<br>\n");
|
||||||
|
|
||||||
|
$program_line_counter = $program_line_counter + 1;
|
||||||
|
switch($cmd){
|
||||||
|
case "inbox":
|
||||||
|
case "outbox":
|
||||||
|
case "jump":
|
||||||
|
case "jumpz":
|
||||||
|
case "jumpn":
|
||||||
|
case "copyto":
|
||||||
|
case "copyfrom":
|
||||||
|
case "add":
|
||||||
|
case "sub":
|
||||||
|
case "bumpup":
|
||||||
|
case "bumpdn":
|
||||||
|
array_push($program, ['cmd' => $cmd, 'param' => $param, 'instruction' => $instruction_counter]);
|
||||||
|
$instruction_counter = $instruction_counter + 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if(substr($cmd, 0, 2) == "--"){ //comment
|
||||||
|
$comments_counter = $comments_counter + 1;
|
||||||
|
array_push($program, ['cmd' => "comment", 'comment' => $line]);
|
||||||
|
}
|
||||||
|
else if(strlen($cmd) == 0){ //empty line
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
else if(substr($cmd, -1, 1) == ":"){ //label, cutting off appending character (":")
|
||||||
|
$label = substr(trim("$cmd"), 0, -1);
|
||||||
|
// echo "Label: $label<br>";
|
||||||
|
if(!preg_match("/^[a-zA-Z]+$/", $label)){ //found invalid character in label
|
||||||
|
// echo("Parse error on line $program_line_counter: $line!\n");
|
||||||
|
$program_summary = "<font color=darkred>Fehler in Programm-Code, Zeile $program_line_counter: $line! $back_to_editor</font><br>";
|
||||||
|
array_push($program, ['cmd' => $cmd, 'param' => $param, 'instruction' => $instruction_counter]);
|
||||||
|
return array(0, $program, $program_summary, $instruction_counter, $labels_counter, ($comments_counter - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
$labels_counter = $labels_counter + 1;
|
||||||
|
array_push($program, ['cmd' => "label", 'label' => "$label"]);
|
||||||
|
}
|
||||||
|
else{ //error
|
||||||
|
// echo("Parse error on line $program_line_counter: $line!\n");
|
||||||
|
$program_summary = "<font color=darkred>Fehler in Programm-Code, Zeile $program_line_counter: $line! $back_to_editor</font><br>";
|
||||||
|
array_push($program, ['cmd' => $cmd, 'param' => $param, 'instruction' => $instruction_counter]);
|
||||||
|
return array(0, $program, $program_summary, $instruction_counter, $labels_counter, ($comments_counter - 1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$program_summary = "Total $program_line_counter Zeile(n) mit $instruction_counter Instruktion(en), $labels_counter Ziel(en) und $comments_counter Kommentar(en).";
|
||||||
|
|
||||||
|
return array(true, $program, $program_summary, $instruction_counter, $labels_counter, ($comments_counter - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Tests the given program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function test_program($program, $inbox, $expected_outbox, $hand, $data_registers, $max_allowed_steps){
|
||||||
|
// echo("$max_allowed_steps");
|
||||||
|
|
||||||
|
$outbox = array();
|
||||||
|
// $step_boxes = array();
|
||||||
|
|
||||||
|
$instructions_line_counter = 0;
|
||||||
|
$used_steps = 0;
|
||||||
|
$hand = "";
|
||||||
|
|
||||||
|
// print_r($program);
|
||||||
|
|
||||||
|
// echo("max_allowed_steps: $max_allowed_steps");
|
||||||
|
|
||||||
|
while($instructions_line_counter < count($program)){
|
||||||
|
// echo("($instructions_line_counter < ".count($program).") and (".count($outbox)." < ".count($inbox).")<br>");
|
||||||
|
$used_steps++;
|
||||||
|
|
||||||
|
/* Check if output is still correct
|
||||||
|
* todo: only run after a OUTPUT command
|
||||||
|
*/
|
||||||
|
// echo("Current Inbox: [");
|
||||||
|
// foreach($inbox as $element){ echo("$element, "); }; echo("]<br>");
|
||||||
|
// echo("Hand: $hand, Data registers: [");
|
||||||
|
// foreach($data_registers as $element){ echo("$element, "); }
|
||||||
|
// echo("]<br>");
|
||||||
|
// echo("Current Outbox: [");
|
||||||
|
// foreach($outbox as $element){ echo("$element, "); } echo("] , Expected Outbox: [");
|
||||||
|
// foreach($expected_outbox as $element){ echo("$element, "); }; echo("]<br>");
|
||||||
|
|
||||||
|
for($i = count($outbox) - 1; $i >= 0; $i--){
|
||||||
|
// echo($outbox[$i] . " <=> " . $expected_outbox[count($expected_outbox) - count($outbox) + $i] . " | ");
|
||||||
|
if($outbox[$i] != ($expected_outbox[count($expected_outbox)- count($outbox) + $i])){ //mismatch, outbox is wrong
|
||||||
|
// echo("<pre>Program is incorrect</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// echo("<br><hr>");
|
||||||
|
|
||||||
|
if(count($outbox) == count($expected_outbox)){ //outbox is full, program completed successfully
|
||||||
|
// echo("Program is correct<br>");
|
||||||
|
return [PROGRAM_IS_CORRECT, $used_steps - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// array_push($step_boxes, $instructions_line_counter);
|
||||||
|
if($used_steps > $max_allowed_steps){
|
||||||
|
// echo("<pre>Maximum steps reached (" . ($used_steps -1 ) . "/$max_allowed_steps)</pre>");
|
||||||
|
return [PROGRAM_TAKES_TOO_MANY_EFFECTIVE_STEPS, $used_steps - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$line = $program[$instructions_line_counter];
|
||||||
|
$cmd = $line['cmd'];
|
||||||
|
$param = $line['param'];
|
||||||
|
$label = $line['label'];
|
||||||
|
$comment = $line['comment'];
|
||||||
|
|
||||||
|
// echo("$used_steps: $cmd $param$label$comment<br>");
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
switch($cmd){
|
||||||
|
case "inbox":
|
||||||
|
if(count($inbox) > 0){ //Check: Inbox is not empty
|
||||||
|
$hand = array_pop($inbox);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>inbox: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "outbox":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty
|
||||||
|
array_unshift($outbox, $hand);
|
||||||
|
$hand = "";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>outbox: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jump":
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>: jumpcommand is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jumpz":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty;
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
if($hand == 0){ //hand is 0
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{ //continue on next line
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>jumpz: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>jumpz: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jumpn":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty;
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
if($hand < 0){ //hand is < 0
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{ //continue on next line
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>jumpn: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "copyto":
|
||||||
|
if(($hand !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand is not empty;
|
||||||
|
$data_registers[$param] = $hand;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>copyto: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "copyfrom":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>copyfrom: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "add":
|
||||||
|
if(($hand !== "") and ($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand and data register are not empty
|
||||||
|
$hand = $hand + $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>add: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "sub":
|
||||||
|
if(($hand !== "") and ($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand and data register are not empty
|
||||||
|
$hand = $hand - $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>: subcommand is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "bumpup":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
$data_registers[$param] = $data_registers[$param] + 1;
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>bumpup: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "bumpdn":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
$data_registers[$param] = $data_registers[$param] - 1;
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("<pre>bumpdn: command is NOT valid with current registers/boxes</pre>");
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "label": //label
|
||||||
|
$used_steps--; //A label doesn't count as a step real step, so decrement it again
|
||||||
|
break;
|
||||||
|
case "comment": //comment
|
||||||
|
$used_steps--; //A comment doesn't count as a step real step, so decrement it again
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
default: //unknown command
|
||||||
|
return [PROGRAM_IS_WRONG, $used_steps - 1];
|
||||||
|
}
|
||||||
|
$instructions_line_counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function test_program_with_iterations($program, $level_configuration){
|
||||||
|
$average_used_steps = 0;
|
||||||
|
$max_used_steps = 0;
|
||||||
|
$test_iteration = 0;
|
||||||
|
|
||||||
|
while($test_iteration < $level_configuration['test_runs']){ // run many iterations of the users program to check if it works under all conditions
|
||||||
|
$test_iteration++;
|
||||||
|
$inbox = $level_configuration["inbox_preparation_function"]($level_configuration);
|
||||||
|
$expected_outbox = $level_configuration["reference_program"]($inbox, $level_configuration);
|
||||||
|
|
||||||
|
list($program_quality, $used_steps, $step_prints) = test_program(
|
||||||
|
$program,
|
||||||
|
$inbox,
|
||||||
|
$expected_outbox,
|
||||||
|
$level_configuration['hand'],
|
||||||
|
$level_configuration['data_registers'],
|
||||||
|
$level_configuration['max_allowed_steps']
|
||||||
|
);
|
||||||
|
// echo("<pre>$used_steps</pre>");
|
||||||
|
$average_used_steps = $average_used_steps + $used_steps;
|
||||||
|
If($used_steps > $max_used_steps) {
|
||||||
|
$max_used_steps = $used_steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($program_quality != PROGRAM_IS_CORRECT){
|
||||||
|
return [FAIL, $inbox, $expected_outbox, round($average_used_steps / $test_iteration), $max_used_steps, $program_quality];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [SUCCESS, $inbox, $expected_outbox, round($average_used_steps / $test_iteration), $max_used_steps];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function outbox_contains_no_errors($inbox, $expected_outbox, $outbox, $hand, $data_registers,$used_steps, $inbox_size, $outbox_size, $level, $passcode){
|
||||||
|
$back_to_editor = "<br><br>Gehe wieder zum Editor-Fenster <a href=editor.php?level=$level&passcode=$passcode>zurück</a>, um deinen Programm-Code zu verbessern. Viel Glück!";
|
||||||
|
for($i = count($outbox) - 1; $i >= 0; $i--){
|
||||||
|
// echo($outbox[$i] . " != " . $expected_outbox[count($expected_outbox)- count($outbox) + $i] . "<br>");
|
||||||
|
if($outbox[$i] != $expected_outbox[count($expected_outbox)- count($outbox) + $i]){ //mismatch, outbox is wrong
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Fehler nach Schritt ". ($used_steps - 1) .": Die Outbox enthält ein falsches Element
|
||||||
|
(Erwartet: ". box($expected_outbox[count($expected_outbox) - count($outbox)]) . ", Erhalten: ". box($outbox[0]) . ")! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
// echo("Die Outbox enthält ein falsches Element<br>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function generate_program_steps($program, $inbox, $expected_outbox, $hand, $data_registers, $max_allowed_steps, $average_effective_steps, $maximum_allowed_instruction, $instruction_counter, $inbox_size, $outbox_size, $reward, $show_outbox_as_coordinate, $level, $passcode){
|
||||||
|
$back_to_editor = "<br>Gehe wieder zum Editor-Fenster <a href=editor.php?level=$level&passcode=$passcode>zurück</a>, um deinen Programm-Code zu verbessern. Viel Glück!";
|
||||||
|
$outbox = array();
|
||||||
|
$step_boxes = array();
|
||||||
|
|
||||||
|
$instructions_line_counter = 0;
|
||||||
|
$visual_step = 0; //includes lables (since the target is also shown as a step point). It gets automatically incremented in print_step()
|
||||||
|
$used_steps = 0; //exclusive target since this is no real step
|
||||||
|
$hand = "";
|
||||||
|
|
||||||
|
while($instructions_line_counter < count($program)){
|
||||||
|
|
||||||
|
// echo("Visual Step: $visual_step: ($instructions_line_counter < ".count($program).") and (".count($outbox)." < ".count($inbox).")<br>");
|
||||||
|
|
||||||
|
$used_steps++;
|
||||||
|
|
||||||
|
|
||||||
|
if(outbox_contains_no_errors($inbox, $expected_outbox, $outbox, $hand, $data_registers, $used_steps, $inbox_size, $outbox_size, $level, $passcode) != true){
|
||||||
|
array_push($step_boxes, -4);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(count($outbox) == count($expected_outbox)){ //outbox is full, program completed successfully
|
||||||
|
goto PROGRAM_END;
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo($instructions_line_counter);
|
||||||
|
|
||||||
|
|
||||||
|
array_push($step_boxes, $instructions_line_counter);
|
||||||
|
if($used_steps > $max_allowed_steps){
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: Fehler: Maximale Anzahl Schritte ($max_allowed_steps) erreicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$line = $program[$instructions_line_counter];
|
||||||
|
$cmd = $line['cmd'];
|
||||||
|
$param = $line['param'];
|
||||||
|
$label = $line['label'];
|
||||||
|
$comment = $line['comment'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
switch($cmd){
|
||||||
|
case "inbox":
|
||||||
|
if(count($inbox) > 0){ //Check: Inbox is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$hand = array_pop($inbox);
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span><br>
|
||||||
|
Fehler: Inbox ist leer! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "outbox":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
array_unshift($outbox, $hand);
|
||||||
|
$hand = "";
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span><br>
|
||||||
|
Fehler: Hand ist leer! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jump":
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Ziel existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jumpz":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty;
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
//
|
||||||
|
if($hand == 0){ //hand is 0
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{ //continue on next line
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Ziel existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span><br>
|
||||||
|
Fehler: Hand ist leer! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "jumpn":
|
||||||
|
if($hand !== ""){ //Check: Hand is not empty;
|
||||||
|
$lable_is_on_line = "";
|
||||||
|
//find matching lable
|
||||||
|
foreach($program as $line_no => $line2){
|
||||||
|
if($line2['label'] == $param){
|
||||||
|
$lable_is_on_line = $line_no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($lable_is_on_line !== ""){ //Check: lable got found
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
//
|
||||||
|
if($hand < 0){ //hand is < 0
|
||||||
|
$instructions_line_counter = $lable_is_on_line - 1; //set program counter to line containing the LABEL
|
||||||
|
}
|
||||||
|
else{ //continue on next line
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Ziel existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span><br>
|
||||||
|
Fehler: Hand ist leer! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "copyto":
|
||||||
|
if(($hand !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$data_registers[$param] = $hand;
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Hand ist leer oder das Daten-Register existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "copyfrom":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Data Register ist leer oder existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "add":
|
||||||
|
if(($hand !== "") and ($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand and data register are not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$hand = $hand + $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Hand oder Data Register ist leer oder das Daten-Register existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "sub":
|
||||||
|
if(($hand !== "") and ($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Hand and data register are not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$hand = $hand - $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Hand oder Data Register ist leer oder das Daten-Register existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "bumpup":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$data_registers[$param] = $data_registers[$param] + 1;
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Data Register ist leer oder existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "bumpdn":
|
||||||
|
if(($data_registers[$param] !== "") and (is_numeric($param)) and ($param >= 0) and ($param < count($data_registers))){ //Check: Register is not empty
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$data_registers[$param] = $data_registers[$param] - 1;
|
||||||
|
$hand = $data_registers[$param];
|
||||||
|
}
|
||||||
|
else{ //command is NOT valid with current registers/boxes
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Data Register ist leer oder existiert nicht! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
case "label": //label
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Ziel <span class=\"jumpdst cmd\">$label</span>", "black", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
$used_steps--; //A label doesn't count as a step real step, so decrement it again
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "comment": //comment
|
||||||
|
array_pop($step_boxes); //remove step again from steps array, a comment is no instruction
|
||||||
|
$used_steps--; //A comment doesn't count as a step real step, so decrement it again
|
||||||
|
break;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
default: //unknown command
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Schritt $used_steps: <span class=\"$cmd cmd\">$cmd</span> <span class=\"$cmd cmd\">$param</span><br>
|
||||||
|
Fehler: Unbekannter Befehl auf Zeile $instructions_line_counter: \"$cmd $param$label$comment\"! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$instructions_line_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reached last line of program.
|
||||||
|
* Is the outbox as expected?
|
||||||
|
*/
|
||||||
|
if(count($outbox) != count($expected_outbox)){
|
||||||
|
array_push($step_boxes, -2);
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, "Letzte Zeile des Programms erreicht, aber die Outbox ist nicht korrekt! $back_to_editor", "DarkRed", $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
// echo("End of program reached! but outbox incomplete<br>");
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PROGRAM_END:
|
||||||
|
if(($average_effective_steps <= $max_allowed_steps) and ($instruction_counter <= $maximum_allowed_instruction)){ //ok, meet one of both requirements
|
||||||
|
$text = "Programm erfolgreich abgearbeitet (Du hast " . ($used_steps - 1) . " Schritte benötigt).<br><br>$reward";
|
||||||
|
$color = "green";
|
||||||
|
}
|
||||||
|
else if($instruction_counter > $maximum_allowed_instruction){ //fail, used too many instructions
|
||||||
|
$text = "Programm erfolgreich abgearbeitet, aber Du hast zu viele Instruktionen ($instruction_counter) verwendet. Programm-Speicher ist sehr kostbar, daher muss die Programm-Grösse auf dem Minimum gehalten werden! Versuche mit $maximum_allowed_instruction Instruktionen auszukommen! $back_to_editor";
|
||||||
|
$color = "OrangeRed";
|
||||||
|
}
|
||||||
|
else{//fail, used too many steps
|
||||||
|
$text = "Programm erfolgreich abgearbeitet, aber Du hast im Durchschnitt zu viele Schritte ($average_effective_steps) benötigt. Je mehr Programm-Schritte ein Auftrag benötigt, desto mehr Zeit braucht das Programm. Und Zeit ist bekanntlich Geld. Versuche mit $max_allowed_steps Schritten auszukommen! $back_to_editor";
|
||||||
|
$color = "OrangeRed";
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($step_boxes, -3);
|
||||||
|
print_step($hand, $data_registers, $inbox, $outbox, $text, $color, $inbox_size, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
return $step_boxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* This command is run before the execution of the instruction.
|
||||||
|
* It shows the situation the instruction is applied to!
|
||||||
|
*/
|
||||||
|
function print_step($hand, $data_registers, $inbox, $outbox, $text, $color, $inbox_size, $outbox_size, $show_outbox_as_coordinate){
|
||||||
|
global $visual_step;
|
||||||
|
|
||||||
|
$visual_step++;
|
||||||
|
?>
|
||||||
|
<!-- <? echo("$visual_step"); ?> -->
|
||||||
|
<div style="margin-bottom: 10px;"></div>
|
||||||
|
<div class=step_boxes id="step_<? echo($visual_step); ?>_box">
|
||||||
|
<div class=hrmcode style="margin-left: 20px; margin-top: 15px; z-index:10;"><font color="<? echo($color); ?>"><? echo("$text"); ?></font></div>
|
||||||
|
<hr>
|
||||||
|
<?
|
||||||
|
print_inbox($inbox, $inbox_size);
|
||||||
|
echo("<hr>\n");
|
||||||
|
print_registers($hand, $data_registers);
|
||||||
|
echo("<hr>\n");
|
||||||
|
print_outbox($outbox, $outbox_size, $show_outbox_as_coordinate);
|
||||||
|
echo("\n");
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function box($value){
|
||||||
|
return "<span class=\"inbox\">$value</span> ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function print_box($value){
|
||||||
|
if($value !== ""){
|
||||||
|
echo("<div class=\"hrmcode box_float_left\">" . box($value) . "</div>");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
echo("<div class=\"empty_box\"></div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function print_registers($hand, $data_registers){
|
||||||
|
?>
|
||||||
|
<div style="margin-top: 20px; margin-left: 20px; height: 40px">
|
||||||
|
<div class="box_float_left">
|
||||||
|
<div class="box_float_left" style="margin-top: 0px">
|
||||||
|
<img src="images/hand.png" height=28px>
|
||||||
|
</div>
|
||||||
|
<?
|
||||||
|
print_box($hand);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="box_float_left">
|
||||||
|
<h3 style="margin-left: 30px; margin-top: 10px">Daten-Register:</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box_float_left">
|
||||||
|
<?
|
||||||
|
$i = 0;
|
||||||
|
foreach($data_registers as $item){
|
||||||
|
?>
|
||||||
|
<div class="DataRegister">
|
||||||
|
<? print_box($item); ?><br>
|
||||||
|
<p><? echo($i);?></p>
|
||||||
|
</div>
|
||||||
|
<?
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="clear: both; margin-bottom: 30px;"></div>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function print_inbox($inbox, $inbox_size){
|
||||||
|
$inbox_size = 8; //limit
|
||||||
|
?>
|
||||||
|
<div style="margin-top: 20px; margin-left: 20px; height: 70px">
|
||||||
|
<h3>Inbox =></h3>
|
||||||
|
<div style="clear: both;">
|
||||||
|
<?
|
||||||
|
|
||||||
|
if(count($inbox) <= $inbox_size){
|
||||||
|
for($i = 0; $i < ($inbox_size - count($inbox)); $i++){ //less boxes than space, show as empty
|
||||||
|
print_box("");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($inbox as $item){
|
||||||
|
print_box($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //too many elements in the inbox, only print first ones
|
||||||
|
echo("<div class=\"hrmcode box_float_left\">...</div>");
|
||||||
|
for($i = $inbox_size; $i > 0; $i--){
|
||||||
|
print_box($inbox[count($inbox) - $i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div style="clear: both; margin-bottom: 30px;"></div>
|
||||||
|
</div>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function print_outbox($outbox, $outbox_size, $show_outbox_as_coordinate){
|
||||||
|
// $outbox_size = 8; //limit
|
||||||
|
?>
|
||||||
|
<div style="margin-left: 20px; height: 50px">
|
||||||
|
<h3>=> Outbox</h3>
|
||||||
|
<?
|
||||||
|
if($show_outbox_as_coordinate != true){ //normal
|
||||||
|
foreach($outbox as $item){
|
||||||
|
print_box($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
for($i = 0; $i < ($outbox_size - count($outbox)); $i++){ //less boxes than space, show as empty
|
||||||
|
print_box("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ //coordinate
|
||||||
|
$position = 0;
|
||||||
|
echo("<div class=\"hrmcode box_float_left\">N</div>");
|
||||||
|
|
||||||
|
foreach($outbox as $item){
|
||||||
|
print_box($item);
|
||||||
|
coordinate_formating($position);
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for($i = 0; $i < ($outbox_size - count($outbox)); $i++){ //less boxes than space, show as empty
|
||||||
|
print_box("");
|
||||||
|
coordinate_formating($position);
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div style="clear: both; margin-bottom: 25px;"></div>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function coordinate_formating($position){
|
||||||
|
if(($position == 6)){ echo("<div style=\"clear: both;\"></div><div class=\"hrmcode box_float_left\">E</div>");}
|
||||||
|
elseif(($position == 1) or ($position == 9)){ echo("<div class=\"hrmcode box_float_left\">°</div>");}
|
||||||
|
else if(($position == 3) or ($position == 11)){ echo("<div class=\"hrmcode box_float_left\">,</div>");}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanup_asm_array(&$value)
|
||||||
|
{
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
if(substr($value, 0, 2) == "--"){ //comment
|
||||||
|
//nothing to do
|
||||||
|
}
|
||||||
|
else{ //all other commands/lables, change to upper case
|
||||||
|
$value = strtolower($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
68
hrm/help.htm
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
||||||
|
<title>Code Editor Help</title>
|
||||||
|
<head>
|
||||||
|
<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>
|
||||||
|
<script src="human-resource-machine-viewer/hrm.js"></script>
|
||||||
|
<link href="human-resource-machine-viewer/hrm.css" rel="stylesheet">
|
||||||
|
<link href="stylesheet.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body{ font-size: 130%; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function font_loaded() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WebFont.load({
|
||||||
|
google: { families: ['Passion One'] },
|
||||||
|
active: font_loaded,
|
||||||
|
inactive: font_loaded,
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1>Code Editor Help</h1>
|
||||||
|
|
||||||
|
<h2>Allgemein</h2>
|
||||||
|
Die Gross-/Kleinschreibung bei den Befehlen wird ignoriert (nicht aber bei den Sprungzielen).<br>
|
||||||
|
Leerzeilen sowie Leerzeichen am Anfang/Ende einer Zeile werden ignoriert.<br>
|
||||||
|
Jeder Befehl zählt als eine Instruktion.
|
||||||
|
Sprungziele und Kommentare zählen nicht als Befehle.<br><br>
|
||||||
|
Aus der Inbox kannst Du nur Boxen entnehmen und in die Outbox kannst Du nur Boxen ablegen.<br>
|
||||||
|
Du kannst jeweils eine Box in der Hand halten.<br>
|
||||||
|
Je nach Level hast du mehrere Daten-Register, welche Du als Zwischenspeicher verwenden kannst.
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Befehle</h2>
|
||||||
|
<table style="max-width: 800px">
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="inbox cmd">INBOX</span></div></td><td>Nimmt die nächste Box aus der Inbox in die Hand.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="outbox cmd">OUTBOX</span></div></td><td>Legt die Box aus der Hand in die Outbox.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="copyfrom cmd">COPYFROM</span> <span class="copyfrom cmd">0</span></div></td><td>Kopiert die Box aus dem ausgewählten Daten-Register in die Hand.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="copyto cmd">COPYTO</span> <span class="copyto cmd">0</span></div></td><td>Kopiert die Box aus der Hand in das ausgewählte Daten-Register.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="add cmd">ADD</span> <span class="add cmd">0</span></div></td><td>Der Wert der Box in der Hand und der Wert der Box im ausgewählten Daten-Register werden addiert und in die Hand kopiert.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="sub cmd">SUB</span> <span class="sub cmd">0</span></div></td><td>Der Wert der Box im ausgewählten Daten-Register wird vom Wert der Box in der Hand subtrahiert und das Ergebnis in die Hand kopiert.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="bumpup cmd">BUMPUP</span> <span class="bumpup cmd">0</span></div></td><td>Addiert 1 zur Box im ausgewählten Daten-Register. Anschliessend wird die neue Box in die Hand kopiert.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="bumpdn cmd">BUMPDN</span> <span class="bumpdn cmd">0</span></div></td><td>Subtrahiert 1 von der Box im ausgewählten Daten-Register. Anschliessend wird die neue Box in die Hand kopiert.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="jumpdst cmd"><SPRUNGZIEL>:</span></div></td><td>Ein Bezeichner, zu dem mit einem der nachfolgenden Sprung-Befehlen gesprungen werden kann. Ein Bezeichner kann einen beliebigen Namen haben und wird mit einem Doppelpunkt abgeschlossen. Beispiel: "PositiveWerte:". Eine Sprungziel-Bezeichnung muss einmalig sein und darf nur Zeichen von A-Z und a-z enthalten. Die Gross-/Kleinschreibung ist relevant.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><nobr><span class="jump cmd">JUMP</span> <span class="jumpdst cmd"><SPRUNGZIEL></span></nobr></div></td><td>Springe an das angegebene Sprungziel.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><nobr><span class="jumpn cmd">JUMPN</span> <span class="jumpdst cmd"><SPRUNGZIEL></span></nobr></div></td><td>Springe an das angegebene Sprungziel, wenn der Wert der Box in der Hand negativ ist. Sonst fahre mit der nächsten Zeile weiter.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><nobr><span class="jumpz cmd">JUMPZ</span> <span class="jumpdst cmd"><SPRUNGZIEL></span></nobr></div></td><td>Springe an das angegebene Sprungziel, wenn der Wert der Box in der Hand 0 ist. Sonst fahre mit der nächsten Zeile weiter.</td></tr>
|
||||||
|
<tr><td valign=top><div class=hrmcode><span class="asm_comment cmd"><Kommentar></span></div></td><td>Ein Kommentar ist eine Notiz als Hilfe für dich. Er muss mit zwei Minus-Zeichen anfangen und kann beliebigen Text enthalten.<br>Beispiel: "-- Das ist ein Kommentar".</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Über</h2>
|
||||||
|
Website und Algorithmus: ©2018 by <a href="http://ruinelli.ch">George Ruinelli</a>.<br>
|
||||||
|
Grafische Darstellung (Human Resource Machine Program Viewer) ©2015 <a href="https://github.com/AlanDeSmet/human-resource-machine-viewer">Alan De Smet</a>.<br>
|
||||||
|
Einige Levels und Ideen sind aus dem Spiel <a href="http://tomorrowcorporation.com/humanresourcemachine">Human Ressource Machine</a> entnommen.
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
679
hrm/human-resource-machine-viewer/GPLv3-LICENSE.md
Executable file
@ -0,0 +1,679 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
--------
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
### 0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
### 1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
### 2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
### 4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
### 5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
- a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
- b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section 7.
|
||||||
|
This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
- c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
- d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
### 6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
- a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
- b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
- c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
- d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
- e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
### 7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
- a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
- b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
- c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
- d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
- e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
- f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
### 8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
### 9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
### 10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
### 11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
### 12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
### 13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
### 14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
### 15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
### 16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
### 17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
---------------------------------------------
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
38
hrm/human-resource-machine-viewer/README.md
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
This is a Javascript program that takes a program copied out of [Human Resource Machine](http://tomorrowcorporation.com/humanresourcemachine) and renders it similarly to the original game.
|
||||||
|
|
||||||
|
Documentation and a live previous are available at https://alandesmet.github.io/human-resource-machine-viewer/
|
||||||
|
|
||||||
|
human-resource-machine-viewer License
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
This file is part of human-resource-machine-viewer,
|
||||||
|
copyright 2015 Alan De Smet.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is free software you can
|
||||||
|
redistribute it and/or modify it under the terms of the GNU
|
||||||
|
General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is distributed in the hope that it
|
||||||
|
will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||||
|
implied warranty of 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
pako\_inflate.min.js License
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
pako\_inflate.min.js is from the [pako port of zlib](https://nodeca.github.io/pako/). Copyright 2014-2015 by Vitaly Puzrin and is subject to the MIT License:
|
||||||
|
|
||||||
|
> Copyright (C) 2014-2015 by Vitaly Puzrin
|
||||||
|
|
||||||
|
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
29
hrm/human-resource-machine-viewer/TODO
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
- If a label (jumpdst) has nothing jumping to it, delete it.
|
||||||
|
|
||||||
|
- If a jump has no matching label (jumpdst), show the label's name.
|
||||||
|
|
||||||
|
- Hovering over a jumpdst should show the label's name.
|
||||||
|
|
||||||
|
- Hovering over a jump should cause the argument with the label to show.
|
||||||
|
|
||||||
|
- Hovering over a jump, jumpdst, or the jump line should highlight all three.
|
||||||
|
|
||||||
|
- Set alt text for memory labels so a copy/paste is reasonableish
|
||||||
|
|
||||||
|
- Arc algorithm, gives pretty square corners for very short jumps and very flat ones for long jumps. How I calculate the control points should change. Perhaps I do want quadratic curves instead of cubic?
|
||||||
|
|
||||||
|
- Cleanup hrm.js.
|
||||||
|
|
||||||
|
- The load of the program causes a "syntax error" in the console log. I think it's because Firefox (possibly via jQuery) tried to parse it as JSON or XML. May just be jQuery trying to autodetect and nothing we can do about it.
|
||||||
|
|
||||||
|
- Give the label SVG's lines a class to set the color.
|
||||||
|
|
||||||
|
- Better errors if can't load file.
|
||||||
|
|
||||||
|
- Handle arrow space better. Somehow.
|
||||||
|
|
||||||
|
- Move jump SVG behind table? Currently obscures attempts to click/hover on instructions.
|
||||||
|
|
||||||
|
- Should inbox and outbox arrows be handled through :before{content: "➡";}? Lets user restyle easily, even if they want the emoji version, or nothing at all.
|
||||||
|
|
||||||
|
- Test serving external CSS really slowrly; like 2 second lag. Ensure that doesn't cause arrow misalignment.
|
12
hrm/human-resource-machine-viewer/hrm-comments.md
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
Comments in Human Resource Machine
|
||||||
|
|
||||||
|
The comments/labels in Human Resource Machine are Base64 encoded. Inside that it's raw zlib compressed. Inside that is a stream of little-endian 16-bit unsigned integers. The uncompressed data will be at most 514 bytes long.
|
||||||
|
|
||||||
|
The first number is the number of elements that follow. It will never exceed 255. The second is always zero. Beyond that are pairs of x and y coordinates. Lines should be be drawn between the pairs. Each coordinate ranges from 0 through 65535 (2^16-1), even though the aspect ratio of the comment is not square. If x and y are both zero, that indicates a break; don't connect that point and the next point (if any) is a new start point. 0,0 is the upper left corner of the label, 65535,65535 is the lower right.
|
||||||
|
|
||||||
|
A label is roughly 3:1. The strokes have a diameter of about 1/10th or 1/11th of the height.
|
||||||
|
|
||||||
|
When displayed, the label is zoomed in on the area with actual strokes. The label will be made narrower to fit the strokes, but never shorter.
|
||||||
|
|
||||||
|
On 1920x1080 screenshot comments are about 235-237 by 77-78. The exact size is unclear; due to scaling/sub-pixel positioning, the edges are fuzzy. In that same screenshot a single dot is about 7-8 by 7-9, again with fuzzy edges.
|
||||||
|
|
154
hrm/human-resource-machine-viewer/hrm.css
Executable file
@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
This file is part of human-resource-machine-viewer,
|
||||||
|
copyright 2015 Alan De Smet.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is free software you can
|
||||||
|
redistribute it and/or modify it under the terms of the GNU
|
||||||
|
General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is distributed in the hope that it
|
||||||
|
will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||||
|
implied warranty of 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 human-resource-machine-view. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hrmcode {
|
||||||
|
font-family: 'Passion One', sans-serif, Impact;
|
||||||
|
font-size: 130%;
|
||||||
|
/* background-color: #bca08b; */
|
||||||
|
/* background-color: linen; */
|
||||||
|
color: black;
|
||||||
|
position: relative;
|
||||||
|
/* z-index: -2; */
|
||||||
|
text-transform: none;
|
||||||
|
|
||||||
|
}
|
||||||
|
.hrmcode table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
position: absolute;
|
||||||
|
z-index: -1;
|
||||||
|
|
||||||
|
background-color: #bca08b;
|
||||||
|
|
||||||
|
min-width: 300px;
|
||||||
|
border: 2px solid #7B6456;
|
||||||
|
}
|
||||||
|
.hrmcode > svg {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.hrmcode div {
|
||||||
|
margin: .3em;
|
||||||
|
}
|
||||||
|
.hrmcode td {
|
||||||
|
padding: 0.2em 0.3em;
|
||||||
|
}
|
||||||
|
.hrmcode span {
|
||||||
|
text-transform: lowercase;
|
||||||
|
padding: 0.1em 0.2em;
|
||||||
|
border-radius: 0.1em;
|
||||||
|
box-shadow: 0.1em 0.1em 0.05em #ac907b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hrmcode span.asm_comment {
|
||||||
|
text-transform: none;
|
||||||
|
}
|
||||||
|
.hrmcode .unknown {
|
||||||
|
}
|
||||||
|
.hrmcode .copyfrom,.hrmcode .copyto {
|
||||||
|
background-color: #c96a52;
|
||||||
|
color: #5f2b1d;
|
||||||
|
}
|
||||||
|
.hrmcode .comment {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
.hrmcode .comment svg {
|
||||||
|
vertical-align: middle;
|
||||||
|
height: 3em;
|
||||||
|
max-width: 9em;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
.hrmcode .arg svg {
|
||||||
|
vertical-align: middle;
|
||||||
|
height: 1em;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
.hrmcode .asm_comment, .hrmcode .arg svg, .hrmcode .comment {
|
||||||
|
background-color: #ede6c5;
|
||||||
|
}
|
||||||
|
.hrmcode .cmd {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.hrmcode .inbox,.hrmcode .outbox {
|
||||||
|
background-color: #9cb65b;
|
||||||
|
color: #474f2c;
|
||||||
|
}
|
||||||
|
.hrmcode .bumpup,.hrmcode .bumpdn,.hrmcode .add,.hrmcode .sub {
|
||||||
|
background-color: #c48d63;
|
||||||
|
color: #5b3d27;
|
||||||
|
}
|
||||||
|
.hrmcode .jump,.hrmcode .jumpn,.hrmcode .jumpz,.hrmcode .jumpdst {
|
||||||
|
background-color: #8d8dc1;
|
||||||
|
color: #3d3c5a;
|
||||||
|
}
|
||||||
|
.hrmcode .jumptype {
|
||||||
|
font-size: 70%;
|
||||||
|
line-height: 60%;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
padding: 0;
|
||||||
|
padding-left: 0.1em;
|
||||||
|
margin: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
.hrmcode .jumpdst {
|
||||||
|
/* color: #8d8dc1; */
|
||||||
|
/*color: #5d5d91;*/
|
||||||
|
min-width: 1.5em;
|
||||||
|
font-style:italic;
|
||||||
|
}
|
||||||
|
.hrmcode .asm_comment {
|
||||||
|
color: #666;
|
||||||
|
font-style:italic;
|
||||||
|
}
|
||||||
|
.hrmcode td.linenum {
|
||||||
|
background-color: #a48a78;
|
||||||
|
color: #7b6456;
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
.hrmcode .jumppath {
|
||||||
|
stroke: #8d8dc1;
|
||||||
|
stroke-width: 0.3em;
|
||||||
|
fill: transparent;
|
||||||
|
}
|
||||||
|
.hrmcode .jumppatharrow {
|
||||||
|
stroke: #8d8dc1;
|
||||||
|
fill: #8d8dc1;
|
||||||
|
stroke-width: 0;
|
||||||
|
}
|
||||||
|
.hrmcode > svg {
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hrmcode svg circle.stroke{
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hrmcode svg polyline.stroke{
|
||||||
|
color: black;
|
||||||
|
stroke: black;
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
fill: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hrmcode tr.active td {
|
||||||
|
background-color: #DABAA1;
|
||||||
|
}
|
677
hrm/human-resource-machine-viewer/hrm.js
Executable file
@ -0,0 +1,677 @@
|
|||||||
|
/*
|
||||||
|
This file is part of human-resource-machine-viewer,
|
||||||
|
copyright 2015 Alan De Smet.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is free software you can
|
||||||
|
redistribute it and/or modify it under the terms of the GNU
|
||||||
|
General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
human-resource-machine-viewer is distributed in the hope that it
|
||||||
|
will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||||
|
implied warranty of 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 human-resource-machine-view. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// HRMLabel
|
||||||
|
//
|
||||||
|
// Takes a Human Resource Machine encoded label and optional height, width, and
|
||||||
|
// brush diameter for the output. If not specified, the height is 40, the
|
||||||
|
// width is 3*height, and the brush diameter is height/11.
|
||||||
|
//
|
||||||
|
// Resulting object has .strokes, a list of strokes. Each stroke is a list of
|
||||||
|
// points that should be connected with straight line segments. Each point is
|
||||||
|
// a list of two elements [x,y], scaled to the specified height and width.
|
||||||
|
//
|
||||||
|
// Resulting object also has .extents, which contains the extents
|
||||||
|
// (.extents.min_x, .extents.min_y, .extents.max_x, .extents.max_y) and size
|
||||||
|
// (.extents.width and .extends.height). The extents are the smallest extents
|
||||||
|
// that encompass all of the strokes, including accounting for the brush
|
||||||
|
// diameter. However, the extents will never go outside of the range 0,0
|
||||||
|
// through width,height; strokes near the edge will be clipped, comforming to
|
||||||
|
// Human Resource Machine's behavior.
|
||||||
|
//
|
||||||
|
// The height, width, and brush diameter, either the defaults or the specified
|
||||||
|
// ones, are available as .height, .width, and .brush_diameter
|
||||||
|
function HRMLabel(encoded_label, height, width, brush_diameter) {
|
||||||
|
"use strict";
|
||||||
|
function rescale(x, oldmax, newmax) { return x * newmax / oldmax; }
|
||||||
|
|
||||||
|
this.height = height || 40;
|
||||||
|
this.width = width || this.height*3;
|
||||||
|
this.brush_diameter = brush_diameter || this.height / 11;
|
||||||
|
|
||||||
|
var hrm_max = 65535;
|
||||||
|
|
||||||
|
var zlib = window.atob(encoded_label);
|
||||||
|
var zlibu8 = new Uint8Array(zlib.length);
|
||||||
|
for(var i = 0; i < zlib.length; i++) {
|
||||||
|
zlibu8[i] = zlib.charCodeAt(i);
|
||||||
|
}
|
||||||
|
var raw = pako.inflate(zlibu8);
|
||||||
|
|
||||||
|
var dv = new DataView(raw.buffer);
|
||||||
|
var elements = dv.getUint16(0, true);
|
||||||
|
var points = [];
|
||||||
|
this.strokes = [];
|
||||||
|
|
||||||
|
var min_x = this.width;
|
||||||
|
var max_x = 0;
|
||||||
|
var min_y = this.height;
|
||||||
|
var max_y = 0;
|
||||||
|
for(var i = 0; i < elements && (i*4+6)<= raw.length; i++) {
|
||||||
|
var index = i*4+4;
|
||||||
|
var x = dv.getUint16(index, true);
|
||||||
|
var y = dv.getUint16(index+2, true);
|
||||||
|
if(x == 0 && y == 0) {
|
||||||
|
this.strokes.push(points);
|
||||||
|
points = [];
|
||||||
|
} else {
|
||||||
|
x = rescale(x, hrm_max, this.width);
|
||||||
|
y = rescale(y, hrm_max, this.height);
|
||||||
|
points.push([x,y]);
|
||||||
|
max_x = Math.max(max_x, x);
|
||||||
|
min_x = Math.min(min_x, x);
|
||||||
|
max_y = Math.max(max_y, y);
|
||||||
|
min_y = Math.min(min_y, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.extents = {
|
||||||
|
min_x: Math.max(min_x-this.brush_diameter/2, 0),
|
||||||
|
min_y: Math.max(min_y-this.brush_diameter/2, 0),
|
||||||
|
max_x: Math.min(max_x+this.brush_diameter/2, this.width),
|
||||||
|
max_y: Math.min(max_y+this.brush_diameter/2, this.height),
|
||||||
|
}
|
||||||
|
this.extents.width = this.extents.max_x - this.extents.min_x;
|
||||||
|
this.extents.height = this.extents.max_y - this.extents.min_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// HRMParser
|
||||||
|
//
|
||||||
|
// Pass in an HRM program in assembly format, either an as array of strings,
|
||||||
|
// with each element representing a single line, or as a single string with
|
||||||
|
// embedded newlines (prefixed with optional carriage returns).
|
||||||
|
//
|
||||||
|
// The "-- HUMAN RESOURCE MACHINE PROGRAM --" header is optional; if present
|
||||||
|
// it will be discarded.
|
||||||
|
//
|
||||||
|
// The returned object will have:
|
||||||
|
//
|
||||||
|
// .comments - Object of the various code comments, indexed on the comment
|
||||||
|
// identifier. So example.comments["3"] retrieves comment 3.
|
||||||
|
// These are the encoded, text form!
|
||||||
|
//
|
||||||
|
// .labels - Same as .comments, but for labels for memory addresses.
|
||||||
|
//
|
||||||
|
// .code - Array of objects describing lines in the source file. Contains:
|
||||||
|
// .code[NUM].cmd - String. The command. One of copyfrom, copyto,
|
||||||
|
// bumpup, bumpdn, jump, jumpn, jumpz, add, sub,
|
||||||
|
// inbox, outbox, comment, blank, asm_comment,
|
||||||
|
// jumpdst, or error
|
||||||
|
// .code[NUM].arg - The argument to the command. Only present for
|
||||||
|
// copyfrom, copyto, bumpup, bumpdn, jump,
|
||||||
|
// jumpn, jumpz, add, sub, comment, asm_comment,
|
||||||
|
// and invalid. For comment it's the identifier
|
||||||
|
// for the image, available through
|
||||||
|
// .comments[.code[NUM].arg]. For asm_comment,
|
||||||
|
// it's the text of the comment, including the
|
||||||
|
// leading "--". For invalid, it's the entire line.
|
||||||
|
// .code[NUM].line_num - Integer. The line number, as Human
|
||||||
|
// Resource Machine counts them. Not present
|
||||||
|
// for invalid, blank, jumpdst, asm_comment or
|
||||||
|
// comment.
|
||||||
|
|
||||||
|
|
||||||
|
function HRMParser(lines) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function is_code(cmd) {
|
||||||
|
if(cmd == 'invalid' ||
|
||||||
|
cmd == 'blank' ||
|
||||||
|
cmd == 'jumpdst' ||
|
||||||
|
cmd == 'asm_comment' ||
|
||||||
|
cmd == 'comment') { return 0; }
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenize_line(line) {
|
||||||
|
var re_asm_comment = /^--/;
|
||||||
|
var re_jump_dst = /^(\S+):/;
|
||||||
|
var re_whitespace = /\s+/;
|
||||||
|
|
||||||
|
var match;
|
||||||
|
|
||||||
|
line = line.replace(/^\s+/, '');
|
||||||
|
line = line.replace(/\s+$/, '');
|
||||||
|
|
||||||
|
if(line == "") { return [ 'blank' ]; }
|
||||||
|
if(match = re_jump_dst.exec(line)) { return ['jumpdst', match[1]]; }
|
||||||
|
if(re_asm_comment.test(line)) { return ['asm_comment', line]; }
|
||||||
|
|
||||||
|
var tokens = line.split(re_whitespace);
|
||||||
|
|
||||||
|
var cmd = tokens[0].toLowerCase();
|
||||||
|
|
||||||
|
var onearg = ['copyfrom', 'copyto', 'bumpup', 'bumpdn', 'jump', 'jumpn', 'jumpz', 'add', 'sub', 'comment'];
|
||||||
|
var zeroarg = ['inbox', 'outbox'];
|
||||||
|
|
||||||
|
if(tokens.length == 2) {
|
||||||
|
for(var i = 0; i < onearg.length; i++) {
|
||||||
|
if(cmd == onearg[i]) { return [cmd, tokens[1]]; }
|
||||||
|
}
|
||||||
|
} else if(tokens.length == 1) {
|
||||||
|
for(var i = 0; i < zeroarg.length; i++) {
|
||||||
|
if(cmd == zeroarg[i]) { return [cmd]; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [ 'invalid', line ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if((typeof lines) === "string") { lines = lines.split(/\r?\n/); }
|
||||||
|
|
||||||
|
// Discard header.
|
||||||
|
var line_number_offset = 0;
|
||||||
|
if(lines[0] == "-- HUMAN RESOURCE MACHINE PROGRAM --") {
|
||||||
|
lines.shift();
|
||||||
|
line_number_offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts = this.extract_labels(lines);
|
||||||
|
this.comments = parts.labels['comment'];
|
||||||
|
this.labels = parts.labels['label'];
|
||||||
|
|
||||||
|
var asm_lines = parts.olines;
|
||||||
|
this.code = [];
|
||||||
|
var code_line_num = 0;
|
||||||
|
var tokens;
|
||||||
|
var lineobj;
|
||||||
|
for(var line = 0; line < asm_lines.length; line++) {
|
||||||
|
tokens = tokenize_line(asm_lines[line]);
|
||||||
|
lineobj = {
|
||||||
|
cmd: tokens[0],
|
||||||
|
src_line_num: line + line_number_offset
|
||||||
|
};
|
||||||
|
if(is_code(lineobj.cmd)) {
|
||||||
|
code_line_num++;
|
||||||
|
lineobj.line_num = code_line_num;
|
||||||
|
}
|
||||||
|
if(tokens.length == 2) { lineobj.arg = tokens[1]; }
|
||||||
|
this.code.push(lineobj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Given an array of strings representing lines in an HRM program,
|
||||||
|
// break out the graphic labels. Returns an object:
|
||||||
|
// .olines - The input lines minus any used by the labels.
|
||||||
|
// .labels['comment'][NUMBER] = encoded_comment_number
|
||||||
|
// .labels['label'][NUMBER] = encoded_label_number (the memory address)
|
||||||
|
HRMParser.prototype.extract_labels = function(ilines) {
|
||||||
|
"use strict";
|
||||||
|
var out = {};
|
||||||
|
out.olines = [];
|
||||||
|
out.labels = {};
|
||||||
|
out.labels['comment'] = {};
|
||||||
|
out.labels['label'] = {};
|
||||||
|
for(var i = 0; i < ilines.length; i++) {
|
||||||
|
var thisline = ilines[i];
|
||||||
|
var match
|
||||||
|
//console.log(i,thisline);
|
||||||
|
if(match = this.re_define.exec(thisline)) {
|
||||||
|
//console.log('hit');
|
||||||
|
var body = '';
|
||||||
|
var more = 1;
|
||||||
|
while(more) {
|
||||||
|
i++;
|
||||||
|
var line = ilines[i];
|
||||||
|
line = line.replace(/^\s+/, '');
|
||||||
|
line = line.replace(/\s+$/, '');
|
||||||
|
if(/;$/.test(line)) {
|
||||||
|
line = line.replace(/;$/, '');
|
||||||
|
more = 0;
|
||||||
|
}
|
||||||
|
body += line;
|
||||||
|
if(i >= ilines.length) { more = 0; }
|
||||||
|
}
|
||||||
|
var mytype = match[1].toLowerCase();
|
||||||
|
out.labels[mytype][match[2]] = body;
|
||||||
|
//console.log(mytype,">"+match[2]+"->",body);
|
||||||
|
} else {
|
||||||
|
//console.log('miss');
|
||||||
|
out.olines.push(thisline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRMParser.prototype.re_define = /^DEFINE\s+(\S+)\s+(\S+)/i;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// HRMViewer
|
||||||
|
//
|
||||||
|
// Inserts a view of Human Resource Machine assembly into current document.
|
||||||
|
// Take the id of an HTML element into which the view should be inserted, as
|
||||||
|
// well as either the HRM assembly as a single string a URL to HRM assembly.
|
||||||
|
// Relative URLs should work. If it's HRM assembly, not a URL, the assembly
|
||||||
|
// _must_ contain at least one newline; it's used to identify it. Conversely,
|
||||||
|
// a URL may not contain any newlines.
|
||||||
|
function HRMViewer(id, source) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// If nothing is passed in, assume the user will call
|
||||||
|
// download_and_append_code_table or append_code_table themselves, although
|
||||||
|
// that's deprecated.
|
||||||
|
if(id === undefined) { return; }
|
||||||
|
|
||||||
|
if(source.indexOf("\n") >= 0) {
|
||||||
|
this.append_code_table(id, source);
|
||||||
|
} else {
|
||||||
|
this.download_and_append_code_table(id, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HRMViewer.prototype.simple_svg = function(width, height, view_min_x, view_min_y, view_width, view_height) {
|
||||||
|
"use strict";
|
||||||
|
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||||
|
svg.setAttribute('version', '1.1');
|
||||||
|
svg.setAttribute('baseProfile', 'full');
|
||||||
|
if(typeof view_min_x == 'undefined') {
|
||||||
|
svg.setAttribute('width', width);
|
||||||
|
svg.setAttribute('height', height);
|
||||||
|
} else {
|
||||||
|
svg.setAttribute('viewBox', view_min_x + " " + view_min_y + " " +
|
||||||
|
view_width + " " + view_height);
|
||||||
|
}
|
||||||
|
svg.setAttribute('xmlns', "http://www.w3.org/2000/svg");
|
||||||
|
this.svg = svg;
|
||||||
|
|
||||||
|
|
||||||
|
this.new_el = function(name) {
|
||||||
|
return document.createElementNS(this.svg.namespaceURI,name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var marker_size = 2.75;
|
||||||
|
var path = this.new_el('path');
|
||||||
|
path.setAttribute('d', "M0,0"+" "+
|
||||||
|
"L0,"+marker_size+" "+
|
||||||
|
"L"+marker_size+","+(marker_size/2)+" "+
|
||||||
|
"Z");
|
||||||
|
//path.setAttribute('stroke', 'red');
|
||||||
|
path.setAttribute('stroke-width', 0);
|
||||||
|
path.setAttribute('class', 'jumppatharrow');
|
||||||
|
|
||||||
|
var marker = this.new_el('marker');
|
||||||
|
marker.setAttribute('id', 'markerArrow');
|
||||||
|
marker.setAttribute('markerWidth', marker_size);
|
||||||
|
marker.setAttribute('markerHeight', marker_size);
|
||||||
|
marker.setAttribute('refX', '0');
|
||||||
|
marker.setAttribute('refY', marker_size/2);
|
||||||
|
marker.setAttribute('orient', 'auto');
|
||||||
|
marker.setAttribute('markerUnits', 'strokeWidth');
|
||||||
|
marker.appendChild(path);
|
||||||
|
|
||||||
|
var defs = this.new_el('defs');
|
||||||
|
defs.appendChild(marker);
|
||||||
|
this.svg.appendChild(defs);
|
||||||
|
|
||||||
|
this.rect = function(x,y,width,height, color) {
|
||||||
|
var e = this.new_el('rect');
|
||||||
|
e.setAttribute('x',x);
|
||||||
|
e.setAttribute('y',y);
|
||||||
|
e.setAttribute('width',width);
|
||||||
|
e.setAttribute('height',height);
|
||||||
|
e.setAttribute('fill',color);
|
||||||
|
this.svg.appendChild(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.circle = function(x, y, radius, newclass) {
|
||||||
|
var e = this.new_el('circle');
|
||||||
|
e.setAttribute('cx',x);
|
||||||
|
e.setAttribute('cy',y);
|
||||||
|
e.setAttribute('r',radius);
|
||||||
|
e.setAttribute('class',newclass);
|
||||||
|
this.svg.appendChild(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.polyline = function(points, width, newclass) {
|
||||||
|
var e = this.new_el('polyline');
|
||||||
|
var pts = "";
|
||||||
|
for(var i = 0; i < points.length; i++) {
|
||||||
|
pts += points[i][0] + " " + points[i][1] + " ";
|
||||||
|
}
|
||||||
|
e.setAttribute('points', pts);
|
||||||
|
e.setAttribute('class', newclass);
|
||||||
|
e.setAttribute('fill', 'transparent');
|
||||||
|
e.setAttribute('stroke-width', width);
|
||||||
|
this.svg.appendChild(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.path = function(command, thisclass) {
|
||||||
|
var e = this.new_el('path');
|
||||||
|
e.setAttribute('d', command);
|
||||||
|
e.setAttribute('class', thisclass);
|
||||||
|
e.setAttribute('style', 'marker-end: url(#markerArrow)');
|
||||||
|
this.svg.appendChild(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
HRMViewer.prototype.new_hrm_label_svg = function(enclabel) {
|
||||||
|
"use strict";
|
||||||
|
var label = new HRMLabel(enclabel);
|
||||||
|
|
||||||
|
var new_svg = new this.simple_svg(label.width, label.height,
|
||||||
|
label.extents.min_x, label.extents.min_y,
|
||||||
|
label.extents.width, label.extents.height);
|
||||||
|
for(var i = 0; i < label.strokes.length; i++) {
|
||||||
|
var points = label.strokes[i];
|
||||||
|
if(points.length == 0) {
|
||||||
|
} else if(points.length == 1) {
|
||||||
|
new_svg.circle(points[0][0], points[0][1], label.brush_diameter/2, 'stroke');
|
||||||
|
} else {
|
||||||
|
new_svg.polyline(points, label.brush_diameter, 'stroke');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_svg.svg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HRMViewer.prototype.create_jump_diagram = function(width, height, offset_left, offset_top, srcs, dsts) {
|
||||||
|
"use strict";
|
||||||
|
var new_svg = new this.simple_svg(width, height);
|
||||||
|
//new_svg.rect(0,0,table_width,table_height, 'green');
|
||||||
|
|
||||||
|
var max_start_x = 0;
|
||||||
|
var gaps = [];
|
||||||
|
for(var i = 0; i < srcs.length; i++) {
|
||||||
|
var src = srcs[i]['el'];
|
||||||
|
var start_x = src.offset().left + src.outerWidth() - offset_left;
|
||||||
|
if(max_start_x < start_x) { max_start_x = start_x; }
|
||||||
|
var sy = src.offset().top;
|
||||||
|
|
||||||
|
var label = srcs[i]['dst'];
|
||||||
|
if(label in dsts) {
|
||||||
|
var dst = dsts[label];
|
||||||
|
var dy = dst.offset().top;
|
||||||
|
gaps.push(Math.abs(dy-sy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gaps.sort(function(a,b){ return a-b; });
|
||||||
|
|
||||||
|
// A "transit" is the point on the arc furthest to the right. We try to
|
||||||
|
// space them out evenly.
|
||||||
|
var first_transit = max_start_x + 0;
|
||||||
|
var transit_width = 10;
|
||||||
|
var last_transit = width - transit_width;
|
||||||
|
var num_transits = Math.floor((last_transit - first_transit)/transit_width + 1);
|
||||||
|
|
||||||
|
var transit_breaks = [];
|
||||||
|
var gaps_per_transit = gaps.length / num_transits;
|
||||||
|
for(var i = 0; i < num_transits; i++) {
|
||||||
|
transit_breaks.push(gaps[Math.floor(gaps_per_transit*i)]);
|
||||||
|
}
|
||||||
|
//console.log("transits",num_transits);
|
||||||
|
//console.log("gaps_per_transit",gaps_per_transit);
|
||||||
|
//console.log("gaps", gaps);
|
||||||
|
//console.log("transit_breaks", transit_breaks);
|
||||||
|
|
||||||
|
for(var i = 0; i < srcs.length; i++) {
|
||||||
|
var label = srcs[i]['dst'];
|
||||||
|
var src = srcs[i]['el'];
|
||||||
|
if(label in dsts) {
|
||||||
|
var dst = dsts[label];
|
||||||
|
|
||||||
|
var startx = src.offset().left-offset_left + src.outerWidth();
|
||||||
|
var starty = src.offset().top-offset_top + src.outerHeight()/2;
|
||||||
|
|
||||||
|
var endx = dst.offset().left-offset_left + dst.outerWidth() + 25;
|
||||||
|
var endy = dst.offset().top-offset_top + dst.outerHeight()/2;
|
||||||
|
|
||||||
|
var gap_y = Math.abs(endy-starty);
|
||||||
|
var transit = 0;
|
||||||
|
for(transit = 0; transit < transit_breaks.length; transit++) {
|
||||||
|
if(gap_y < transit_breaks[transit]) { break; }
|
||||||
|
}
|
||||||
|
var mid_x = first_transit + transit*transit_width;
|
||||||
|
//console.log("(gap:",gap_y,")",first_transit,"+",transit,"*",transit_width,"=",mid_x);
|
||||||
|
|
||||||
|
var mid_y = (starty + endy) / 2;
|
||||||
|
var bcurve_y = (starty - endy) / 2;
|
||||||
|
var path_cmd = ["M", startx, starty,
|
||||||
|
"C", startx + 20, starty,
|
||||||
|
mid_x, mid_y + bcurve_y,
|
||||||
|
mid_x, mid_y,
|
||||||
|
"C", mid_x, mid_y - bcurve_y,
|
||||||
|
endx + 20, endy,
|
||||||
|
endx, endy
|
||||||
|
].join(" ");
|
||||||
|
new_svg.path(path_cmd,'jumppath');
|
||||||
|
} else {
|
||||||
|
console.log("jump label", label, "lacks a matching destination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_svg.svg;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRMViewer.prototype.append_code_table = function(id, data) {
|
||||||
|
"use strict";
|
||||||
|
this.root_div = $('#'+id);
|
||||||
|
|
||||||
|
this.root_div.empty();
|
||||||
|
|
||||||
|
var parser = new HRMParser(data);
|
||||||
|
|
||||||
|
this.root = $(document.createElement('table'));
|
||||||
|
|
||||||
|
// fe0e means "render preceeding as text, do not substitute a color emoji.
|
||||||
|
// Fixes overly helpful behavior on Safari.
|
||||||
|
var rightarrow = '➡\ufe0e';
|
||||||
|
|
||||||
|
this.dsts = {};
|
||||||
|
this.srcs = [];
|
||||||
|
this.line_to_row = {};
|
||||||
|
|
||||||
|
var num_len = 2;
|
||||||
|
var pad = "00000";
|
||||||
|
var code_lines = parser.code.length;
|
||||||
|
if(code_lines.length > 9999) { num_len = 5; }
|
||||||
|
else if(code_lines.length > 999) { num_len = 4; }
|
||||||
|
else if(code_lines.length > 99) { num_len = 3; }
|
||||||
|
var line_number = 0;
|
||||||
|
for(var i = 0; i < parser.code.length; i++) {
|
||||||
|
var linecode = parser.code[i];
|
||||||
|
var cmd = linecode.cmd;
|
||||||
|
var arg = linecode.arg;
|
||||||
|
if(cmd == 'blank') { continue; }
|
||||||
|
var newclass = cmd;
|
||||||
|
|
||||||
|
var text = cmd;
|
||||||
|
var jmpdst;
|
||||||
|
if(cmd == 'bumpup') { text = 'bump +'; }
|
||||||
|
else if(cmd == 'bumpdn') { text = 'bump −'; }
|
||||||
|
// else if(cmd == 'inbox') { text = rightarrow + ' inbox'; }
|
||||||
|
// else if(cmd == 'outbox') { text = 'outbox ' + rightarrow; }
|
||||||
|
else if(cmd == 'inbox') { text = 'inbox'; }
|
||||||
|
else if(cmd == 'outbox') { text = 'outbox'; }
|
||||||
|
else if(cmd == 'asm_comment') {
|
||||||
|
text = arg;
|
||||||
|
arg = undefined;
|
||||||
|
} else if(cmd == 'jumpdst') {
|
||||||
|
text = arg;
|
||||||
|
arg = undefined;
|
||||||
|
} else if(cmd == 'jump' || cmd == 'jumpn' || cmd == 'jumpz') {
|
||||||
|
jmpdst = arg;
|
||||||
|
arg = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
var comment_id;
|
||||||
|
if(cmd == 'comment') {
|
||||||
|
comment_id = arg;
|
||||||
|
if(comment_id in parser.comments) {
|
||||||
|
text = '';
|
||||||
|
arg = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var e_cmd = $(document.createElement('span'));
|
||||||
|
if(cmd == "jumpn" || cmd == "jumpz") {
|
||||||
|
e_cmd.append(document.createTextNode("jump"));
|
||||||
|
var overunder = $(document.createElement('div'));
|
||||||
|
overunder.addClass("jumptype");
|
||||||
|
overunder.append(document.createTextNode("if"));
|
||||||
|
overunder.append(document.createElement('br'));
|
||||||
|
if(text == "jumpn") {
|
||||||
|
overunder.append(document.createTextNode("negative"));
|
||||||
|
} else if(text == "jumpz") {
|
||||||
|
overunder.append(document.createTextNode("zero"));
|
||||||
|
} else {
|
||||||
|
overunder.append(document.createTextNode("unknown"));
|
||||||
|
}
|
||||||
|
e_cmd.append(overunder);
|
||||||
|
} else {
|
||||||
|
e_cmd.text(text);
|
||||||
|
}
|
||||||
|
e_cmd.addClass(newclass);
|
||||||
|
e_cmd.addClass('cmd');
|
||||||
|
|
||||||
|
if(cmd == 'jumpdst') {
|
||||||
|
this.dsts[text] = e_cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(cmd == "comment") {
|
||||||
|
if(comment_id in parser.comments) {
|
||||||
|
var svg = this.new_hrm_label_svg(parser.comments[comment_id]);
|
||||||
|
svg = $(svg);
|
||||||
|
e_cmd.append(svg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var re_memory_addr = /^\d+$/;
|
||||||
|
var e_arg = 0;
|
||||||
|
if(arg !== undefined) {
|
||||||
|
e_arg = $(document.createElement('span'));
|
||||||
|
e_arg.addClass(newclass);
|
||||||
|
e_arg.addClass('arg');
|
||||||
|
var tmp;
|
||||||
|
if(re_memory_addr.test(arg)) {
|
||||||
|
if(arg in parser.labels) {
|
||||||
|
var svg = this.new_hrm_label_svg(parser.labels[arg]);
|
||||||
|
svg = $(svg);
|
||||||
|
e_arg.append(svg);
|
||||||
|
} else {
|
||||||
|
e_arg.text(arg);
|
||||||
|
}
|
||||||
|
} else if(tmp = /\[(\d+)\]/.exec(arg)) {
|
||||||
|
var num = tmp[1];
|
||||||
|
if(num in parser.labels) {
|
||||||
|
e_arg.append(document.createTextNode("[ "));
|
||||||
|
var svg = this.new_hrm_label_svg(parser.labels[num]);
|
||||||
|
svg = $(svg);
|
||||||
|
e_arg.append(svg);
|
||||||
|
e_arg.append(document.createTextNode(" ]"));
|
||||||
|
} else {
|
||||||
|
e_arg.text(arg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e_arg.text(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(newclass=='jump' || newclass=='jumpn' || newclass=="jumpz") {
|
||||||
|
this.srcs.push({dst:jmpdst, el:e_cmd});
|
||||||
|
}
|
||||||
|
|
||||||
|
var new_td_num = $(document.createElement('td'));
|
||||||
|
if(linecode.line_num) {
|
||||||
|
var linenum = (pad+linecode.line_num).slice(-num_len);
|
||||||
|
new_td_num.text(linenum);
|
||||||
|
}
|
||||||
|
new_td_num.addClass('linenum');
|
||||||
|
|
||||||
|
var new_td_code = $(document.createElement('td'));
|
||||||
|
new_td_code.append(e_cmd);
|
||||||
|
if(e_arg) {
|
||||||
|
new_td_code.append($(document.createTextNode(' ')));
|
||||||
|
new_td_code.append(e_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var new_row = $(document.createElement('tr'));
|
||||||
|
new_row.append(new_td_num);
|
||||||
|
new_row.append(new_td_code);
|
||||||
|
this.root.append(new_row);
|
||||||
|
this.line_to_row[linecode.src_line_num] = new_row;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root_div.append(this.root);
|
||||||
|
|
||||||
|
var that=this;
|
||||||
|
setTimeout(function(){that.updateJumpArrows()}, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
HRMViewer.prototype.updateJumpArrows = function() {
|
||||||
|
"use strict";
|
||||||
|
if(this.svg) { this.svg.remove(); }
|
||||||
|
var table_width = this.root.outerWidth() - 70;
|
||||||
|
var table_height = this.root.outerHeight();
|
||||||
|
this.svg = this.create_jump_diagram(
|
||||||
|
table_width + 50, table_height,
|
||||||
|
this.root_div.offset().left, this.root_div.offset().top,
|
||||||
|
this.srcs, this.dsts);
|
||||||
|
this.root_div.append(this.svg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always clears the current active line. If line_num
|
||||||
|
// is defined, that line will be highlighted by adding
|
||||||
|
// the "active" class to the <tr>
|
||||||
|
HRMViewer.prototype.setActiveLine = function(line_num) {
|
||||||
|
if(this.active_row) { this.active_row.removeClass("active"); }
|
||||||
|
if(line_num === undefined) { return; }
|
||||||
|
this.active_row = this.line_to_row[line_num];
|
||||||
|
if(this.active_row) { this.active_row.addClass("active"); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HRMViewer.prototype.download_and_append_code_table = function (id, url) {
|
||||||
|
"use strict";
|
||||||
|
var t = this;
|
||||||
|
function code_arrived(data) {
|
||||||
|
t.append_code_table(id, data);
|
||||||
|
}
|
||||||
|
function failure(xhr,tstatus,err) {
|
||||||
|
$('#'+id).empty();
|
||||||
|
$('#'+id).text("Error loading "+url+". " + tstatus + " " + err);
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
success: code_arrived,
|
||||||
|
error: failure,
|
||||||
|
dataType: 'text',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backward compatibility interface. Deprecated. Prefer HRMViewer.
|
||||||
|
var hrm_viewer = HRMViewer;
|
51
hrm/human-resource-machine-viewer/label-test.asm
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
-- HUMAN RESOURCE MACHINE PROGRAM --
|
||||||
|
|
||||||
|
COMMENT 0
|
||||||
|
COMMENT 1
|
||||||
|
COMMENT 2
|
||||||
|
COMMENT 3
|
||||||
|
COMMENT 4
|
||||||
|
COMMENT 5
|
||||||
|
COMMENT 6
|
||||||
|
COMMENT 7
|
||||||
|
COMMENT 8
|
||||||
|
|
||||||
|
-- Dot center --
|
||||||
|
DEFINE COMMENT 0
|
||||||
|
eJxjYmBgUGueXscwCkbBKBiRAAABSgHB;
|
||||||
|
|
||||||
|
-- dot upper left --
|
||||||
|
DEFINE COMMENT 1
|
||||||
|
eJxjYmBgcGPMZWEYBaNgFIxIAADrQwC7;
|
||||||
|
|
||||||
|
-- dot upper right --
|
||||||
|
DEFINE COMMENT 2
|
||||||
|
eJxjYmBgmPX3PSvDKBgFo2BEAgA1uAKO;
|
||||||
|
|
||||||
|
-- dot lower left --
|
||||||
|
DEFINE COMMENT 3
|
||||||
|
eJxjYmBgqGUx/8gwCkbBKBiRAACtIQGs;
|
||||||
|
|
||||||
|
-- dot lower right --
|
||||||
|
DEFINE COMMENT 4
|
||||||
|
eJxjYmBgiPj35wvDKBgFo2BEAgAe/QNJ;
|
||||||
|
|
||||||
|
-- Three horizontal dots --
|
||||||
|
DEFINE COMMENT 5
|
||||||
|
eJxjY2Bg2C1zsgRIMQh39VeAaPa3dTkMo2AUjIIRAQBBHwWd;
|
||||||
|
|
||||||
|
-- horizontal stroke --
|
||||||
|
DEFINE COMMENT 6
|
||||||
|
eJxjZmBg0LOMCbH2iQlhGAWjYBSMOAAAP84CUg;
|
||||||
|
|
||||||
|
-- two horizontalish strokes --
|
||||||
|
DEFINE COMMENT 7
|
||||||
|
eJxjZ2BgeGN51Dklh8UZyGSQdrhWy5R4rzkn814zwygYBaNg2AMAYrEI9A;
|
||||||
|
|
||||||
|
-- two halfass circles --
|
||||||
|
DEFINE COMMENT 8
|
||||||
|
eJxTZ2BgKDY/6mxmJupfYRpSk2d5bukTm8db5trr7b3iZH64yfPPMfPUvcfl88wPXy3U23upaMnWS0Wi
|
||||||
|
q6cWNs1VzL3V8DaDIc88VS/xQGJC+OWoSz5JoYI+uoERgUBjGZacYilcdYKlsOKwaG3DgcdtbvuMJnnv
|
||||||
|
4Vh0Zvf0NWd2L9nasXfLwSP7fhyuPbjziP+lnUd+39xycN2993tXPtDa9eJB6jaGUTAKRgHNAQBQ6k+y
|
||||||
|
;
|
||||||
|
|
2
hrm/human-resource-machine-viewer/pako_inflate.min.js
vendored
Executable file
26
hrm/human-resource-machine-viewer/simple.asm
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
-- HUMAN RESOURCE MACHINE PROGRAM --
|
||||||
|
-- This is a simple example
|
||||||
|
COMMENT 4
|
||||||
|
b:
|
||||||
|
a:
|
||||||
|
INBOX
|
||||||
|
JUMPN a
|
||||||
|
COPYTO 22
|
||||||
|
ADD 22
|
||||||
|
OUTBOX
|
||||||
|
JUMP b
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE COMMENT 4
|
||||||
|
eJwzZmBg2C2Ta2Qqv0JPSlNN11Nfz5jJyNqmzrjL/b9RiN889czYs7qlaQ1GRwurTS5V2Zgotv030upp
|
||||||
|
M3jf3yM2eSVQO8O0SEWt8y6y6v0uKTq9roWmrh5HnQ968nhu9JcNTQ/ekrokRLRWIzihdX3A6x5nz70z
|
||||||
|
Q53aFoD1Lfhjc3h5pfWRfZXWLPsZHLI3RNQbrsvsLl67ZTJInuNqpXX8mb22S04ddJhzdk289LkNSZcv
|
||||||
|
GKUIXPqe7n+Jo+Tyhel10ufUOpec2jCh9EjVdIZRMApGAckAACnAUx0;
|
||||||
|
|
||||||
|
DEFINE LABEL 22
|
||||||
|
eJxTZ2Bg2GE6vW6rWcTarWa5r4BcBjMzjpL3Fgx5Nx2qMjndqzKdPRny/nmdLPnnldrB6LVhArPnlsls
|
||||||
|
Hj+mSjscnPPcumkuSI9UxHvjOeH29nPCjVJmRniXTYl63tkT+77/WLzRpMbEzO6/SbcaQOqM/QO8TdL6
|
||||||
|
vEDswGKjFP4SrR7PssLko+WKEQ2VEYG1Vdf8VzVe85foiAlhGAWjYBTQHAAAToc78w;
|
||||||
|
|
BIN
hrm/images/bg_tiles.png
Executable file
After Width: | Height: | Size: 21 KiB |
BIN
hrm/images/hand.png
Executable file
After Width: | Height: | Size: 20 KiB |
BIN
hrm/images/help.png
Executable file
After Width: | Height: | Size: 30 KiB |
BIN
hrm/images/next.png
Executable file
After Width: | Height: | Size: 29 KiB |
BIN
hrm/images/pause.png
Executable file
After Width: | Height: | Size: 20 KiB |
BIN
hrm/images/play.png
Executable file
After Width: | Height: | Size: 18 KiB |
BIN
hrm/images/previous.png
Executable file
After Width: | Height: | Size: 30 KiB |
BIN
hrm/images/reset.png
Executable file
After Width: | Height: | Size: 53 KiB |
BIN
hrm/images/screenshot.png
Executable file
After Width: | Height: | Size: 76 KiB |
368
hrm/run.php
Executable file
@ -0,0 +1,368 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
<?
|
||||||
|
|
||||||
|
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;
|
||||||
|
if($program[0][cmd] == 'comment'){
|
||||||
|
if($program[0][comment] == '--debug'){
|
||||||
|
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(){
|
||||||
|
<?
|
||||||
|
if(($program[0][cmd] == "comment") && ($program[0][comment] == "--debug")){ //we are in debug mode
|
||||||
|
?>
|
||||||
|
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>
|
||||||
|
|
||||||
|
|
153
hrm/stylesheet.css
Executable file
@ -0,0 +1,153 @@
|
|||||||
|
body {
|
||||||
|
font-family: 'Passion One', sans-serif, Impact;
|
||||||
|
/* font-size: 130%; */
|
||||||
|
/* background-color: linen; */
|
||||||
|
/* background-color: #bca08b; */
|
||||||
|
/* position: relative; */
|
||||||
|
|
||||||
|
|
||||||
|
background-image: url("images/bg_tiles.png");
|
||||||
|
background-repeat: repeat;
|
||||||
|
background-attachment: fixed;
|
||||||
|
|
||||||
|
color: black;
|
||||||
|
z-index: -2;
|
||||||
|
text-transform: none;
|
||||||
|
|
||||||
|
/* font-weight: 100; */
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,h2,h3,h4{
|
||||||
|
font-weight: normal;
|
||||||
|
/* font-family: 'Passion One', sans-serif, Impact; */
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* p {
|
||||||
|
font-family: "Times New Roman", Times, serif;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
pre {
|
||||||
|
margin-left: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* table, th, td {
|
||||||
|
border: 1px solid black;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font-family: "Monospace";
|
||||||
|
} */
|
||||||
|
|
||||||
|
.frame {
|
||||||
|
border:1px solid black;
|
||||||
|
background-color: linen;
|
||||||
|
max-width: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box {
|
||||||
|
min-width: 25px;
|
||||||
|
width: 50px;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.step_boxes{
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 2px solid #7B6456;
|
||||||
|
/* padding: 5px; */
|
||||||
|
width: 600px;
|
||||||
|
/* height: 150px; */
|
||||||
|
|
||||||
|
background-color: #bca08b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.init_box{
|
||||||
|
display: block;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.control_box{
|
||||||
|
display: block;
|
||||||
|
height: 100px;
|
||||||
|
|
||||||
|
margin-top: 0px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 2px solid #7B6456;
|
||||||
|
/* padding: 5px; */
|
||||||
|
width: 600px;
|
||||||
|
/* height: 150px; */
|
||||||
|
|
||||||
|
background-color: #bca08b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box_float_left{
|
||||||
|
float: left;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-left: 3px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.DataRegister{
|
||||||
|
float: left;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-left: 3px;
|
||||||
|
padding-right: 5px;
|
||||||
|
text-align: center;
|
||||||
|
width: 38px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.empty_box{
|
||||||
|
background-color: #DABAA1;
|
||||||
|
border: 2px solid #73AD21;
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
width: 20px;
|
||||||
|
height: 22px;
|
||||||
|
float: left;
|
||||||
|
padding: 0.1em 0.2em;
|
||||||
|
border-radius: 0.1em;
|
||||||
|
box-shadow: 0.1em 0.1em 0.05em #ac907b;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr{
|
||||||
|
color: #7B6456;
|
||||||
|
background-color:#7B6456;
|
||||||
|
height:2px;
|
||||||
|
border-width:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
font-family: 'Passion One', sans-serif, Impact;
|
||||||
|
/* -moz-tab-size:4; */
|
||||||
|
/* tab-width:4; */
|
||||||
|
}
|
||||||
|
|
||||||
|
button{
|
||||||
|
padding: 5px;
|
||||||
|
width: 90px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#speed_slider{
|
||||||
|
width: 120px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
a.button {
|
||||||
|
-webkit-appearance: button;
|
||||||
|
-moz-appearance: button;
|
||||||
|
appearance: button;
|
||||||
|
|
||||||
|
text-decoration: none;
|
||||||
|
color: initial;
|
||||||
|
|
||||||
|
padding: 5px;
|
||||||
|
width: 70px;
|
||||||
|
}
|
||||||
|
|
132
index.php
Executable file
@ -0,0 +1,132 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
||||||
|
<?
|
||||||
|
include("hrm/functions.php");
|
||||||
|
include("levels.php");
|
||||||
|
|
||||||
|
|
||||||
|
if ( isset( $_GET['level'] ) && !empty( $_GET['level'] ) && is_numeric( $_GET['level'] )){
|
||||||
|
$level = $_GET['level'];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// echo("level value invalid<br>");
|
||||||
|
$level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level_description = "level_" . $level . "_description"; //build function name, see http://php.net/manual/de/functions.variable-functions.php
|
||||||
|
// echo("Function name: \"$level_description\"<br>");
|
||||||
|
if(is_callable($level_description)) { // The function exists
|
||||||
|
$parameters_valid = true;
|
||||||
|
list($title, $description, $example, $criteria, $passcode) = $level_description();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$parameters_valid = false;
|
||||||
|
$passcode = "";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<title><? echo("$GC_ID: $GC_NAME"); ?></title>
|
||||||
|
<head>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>
|
||||||
|
<script src="hrm/human-resource-machine-viewer/pako_inflate.min.js"></script>
|
||||||
|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||||
|
<link href="hrm/human-resource-machine-viewer/hrm.css" rel="stylesheet">
|
||||||
|
<link href="hrm/stylesheet.css" rel="stylesheet">
|
||||||
|
<script src="hrm/human-resource-machine-viewer/hrm.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="hrmcode">
|
||||||
|
<div style="width: 800px">
|
||||||
|
<h1><nobr><? echo("$GC_ID: $GC_NAME"); ?> - Willkommen</nobr></h1>
|
||||||
|
Willkommen im Rechenzentrum des Verwaltungssitzes von Geotanien.<br>
|
||||||
|
Hier werden alle wichtigen Dinge für unser Land gesteuert.
|
||||||
|
Das beginnt bei der monatlichen Verteilung der Löhne über die Steuerung der Ampeln bis hin zur Bestellung von genügend Futter für alle Meerschweinchen in unserem Kleintierzoo.<br><br>
|
||||||
|
|
||||||
|
Hier, in diesem Einführungskurs, könntest Du normalerweise zuschauen und lernen, wie unsere CPU (Central Processing Unit, Zentrale Recheneinheit) funktioniert.
|
||||||
|
Leider ist aber nun genau diese kaputt gegangen, so dass wir nun ein Problem haben...<br><br>
|
||||||
|
|
||||||
|
Um genau zu sein, wir brauchen dringenst deine Hilfe!<br>
|
||||||
|
Kannst Du als Ersatz für die CPU einspringen?<br>
|
||||||
|
Wir wissen, dass ein Mensch nicht gerade gut geeignet ist, eine CPU zu ersetzen und ohne Widerrede hunderte Befehle entgenzunehmen und auszuführen.
|
||||||
|
Wir hoffen aber dennoch, dass Du uns hilfst!<br><br>
|
||||||
|
|
||||||
|
Es ist eigentlich ganz einfach:
|
||||||
|
<ul>
|
||||||
|
<li>Auf der linken Seite hast Du eine Inbox, welche Boxen mit Zahlen enthält,</li>
|
||||||
|
<li>Auf der rechten Seite hast Du eine Outbox, in welche die verarbeiteten Boxen abgelegt werden sollen,</li>
|
||||||
|
<li>In der Mitte hast Du mehrere Daten-Register, welche Du als Zwischenablage verwenden kannst. Sie sind von 0 an durchnummeriert. Um vom ersten Daten-Register lesen zu können, musst Du z.B. den Befehl <span class="copyfrom cmd">COPYFROM</span> <span class="copyfrom cmd">0</span> ausführen.</li>
|
||||||
|
<li>In deiner Hand kannst du auch jeweils eine Box halten,</li>
|
||||||
|
<li>Weitere Erläuterungen findest Du in der <a href="hrm/help.htm" target="_blank">Hilfe</a>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<img src=hrm/images/screenshot.png><br><br>
|
||||||
|
|
||||||
|
Damit die CPU (bzw. jetzt neu ja Du) weisst, was mit den Boxen aus der Inbox zu machen ist, müssen wir eine Befehlsliste (ein Programm) abarbeiten.
|
||||||
|
Mit dem Defekt der CPU sind jedoch leider auch alle Programme verloren gegangen, so dass Du zuerst ein passendes Programm schreiben musst.<br>
|
||||||
|
|
||||||
|
Die dafür benötigten Befehle sind in der <a href="hrm/help.htm" target="_blank">Hilfe</a> erläutert.<br><br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div id="local_storage_check" style="margin:0px;"><font color=darkred>Hmm, dein Browser unterstützt leider kein <a href="https://de.wikipedia.org/wiki/Web_Storage" target="_blank">lokales speichern</a>. D.h., Du musst selber dafür sorgen, dass Du dein Programm zwischenspeicherst, befor Du es ausführst!</font></div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
Der Geocache wurde mit einem aktuellen Firefox, Chrome und Safari erfolgreich getestet. Falls Du denkt, dass es nicht korrekt läuft, empfehle ich dir, den Browser zu wechseln.
|
||||||
|
<font color=red>Nicht korrekt funktioniert hat es mit dem <b>Internet Explorer</b> und <b>Opera</b>!</font>
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
Alles klar?<br>
|
||||||
|
Dann begib dich bitte zu deiner <a href="hrm/editor.php">ersten Aufgabe</a>.<br><br>
|
||||||
|
|
||||||
|
<form action="hrm/editor.php" method="get">
|
||||||
|
Oder springe direkt zum Level <input type="number" value="2" name="level" min="1" max="5" maxlength=1 style="width: 50px;">
|
||||||
|
Passcode: <input type="number" name="passcode" style="width: 120px;">
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function font_loaded() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WebFont.load({
|
||||||
|
google: { families: ['Passion One'] },
|
||||||
|
active: font_loaded,
|
||||||
|
inactive: font_loaded,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check browser support
|
||||||
|
if (typeof(Storage) !== "undefined") {
|
||||||
|
// Store
|
||||||
|
localStorage.setItem("local_storage_test", "1234567890");
|
||||||
|
// Retrieve
|
||||||
|
if(localStorage.getItem("local_storage_test") == "1234567890"){
|
||||||
|
document.getElementById("local_storage_check").innerHTML = "Dein Programm wird jeweils zwischengespeichert. D.h. wenn Du zum Editor zurückkehren musst, ist das Programm noch da.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
557
levels.php
Executable file
@ -0,0 +1,557 @@
|
|||||||
|
<?
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* GC7R0TA - Level 1-5
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Zum debuggen muss die erste Zeile
|
||||||
|
* --debug
|
||||||
|
* heissen
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* geocache ID and name
|
||||||
|
*/
|
||||||
|
$GC_ID = "GC7R0TA";
|
||||||
|
$GC_NAME = "Rechenzentrum (Für Einsteiger)";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The final coordinate is calculated in level 5
|
||||||
|
*/
|
||||||
|
$level_5_coordinates = array( 4,7, 1,9, 4,0,6, // N 47° 19.406'
|
||||||
|
0,0,8, 4,7, 2,0,2); // E 8° 47.202', total 15 digits
|
||||||
|
|
||||||
|
// N 47° 19.463' E 008° 46.837'
|
||||||
|
$level_5_coordinates = array( 4,7, 1,9, 4,6,3,
|
||||||
|
0,0,8, 4,6, 8,3,7); // total 15 digits
|
||||||
|
|
||||||
|
/* Inbox
|
||||||
|
* ---------------------------------
|
||||||
|
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | => Take
|
||||||
|
* --------------------------------- (array_pop)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Outbox
|
||||||
|
* ---------------------------------
|
||||||
|
* Add => | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
||||||
|
* (unshift) ---------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Level Beispiele:
|
||||||
|
// https://github.com/atesgoral/hrm-level-data/blob/master/index.json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Level 1
|
||||||
|
* Shift Inbox to Outbox
|
||||||
|
* Test-Code:
|
||||||
|
--debug
|
||||||
|
start:
|
||||||
|
inbox
|
||||||
|
outbox
|
||||||
|
jump start
|
||||||
|
*******************************************************************/
|
||||||
|
function level_1_description(){
|
||||||
|
$title = "Verschieben";
|
||||||
|
$description = "In der Inbox hat es einige Boxen mit Zahlen, welche in die Outbox verschoben werden sollen.<br>" .
|
||||||
|
"Schreibe ein Programm, welches das für dich macht!<br>" .
|
||||||
|
"Du brauchst dazu nur die Befehle <span class=\"inbox cmd\">INBOX</span>, <span class=\"inbox cmd\">OUTBOX</span>, " .
|
||||||
|
"<span class=\"jump cmd\">JUMP</span> sowie das dazu passende Ziel <span class=\"jumpdst cmd\"><ZIEL>:</span>.<br>" .
|
||||||
|
"Du hast 4 Daten-Register zur Verfügung (nummeriert von 0 bis 3), brauchst aber eigentlich keins.<br>" .
|
||||||
|
"Du musst dir auch keine Gedanken darüber machen, wann die Aufgabe erledigt ist. Das Programm wird automatisch beendet, wenn die Outbox korrekt gefüllt ist.";
|
||||||
|
// $example = "Inbox: " . print_box(5) . "<br>Erwartete Outbox: ";
|
||||||
|
$example = "Inbox: " . box(3) . box(28). box(7) . " , " .
|
||||||
|
"Erwartete Outbox: " . box(3) . box(28). box(7) . ".";
|
||||||
|
$criteria = "Verwende maximal 3 Instruktionen und maximal 17 Schritte."; //Make sure it matches the values in the init function!
|
||||||
|
$passcode_for_this_level = ""; //no passcode needed for level 1
|
||||||
|
return [$title, $description, $example, $criteria, $passcode_for_this_level];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function level_1_configuration(){
|
||||||
|
$configuration = array(
|
||||||
|
"level" => 1,
|
||||||
|
"inbox_size" => 6, //elements in inbox, use even number!
|
||||||
|
"show_outbox_as_coordinate" => false, // only last level should set this to true
|
||||||
|
"max_allowed_instruction" => 3, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"max_allowed_steps" => 17, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"hand" => "", // content of the hand, single value
|
||||||
|
"data_registers" => array("", "", "", ""), // content of the 4 data registers
|
||||||
|
"passcode_for_next_level" => 20685401, // passcode for next level
|
||||||
|
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=2&passcode=20685401\">nächsten Level</a> weiter. Der Passcode ist 20685401.", // shown text if level successes
|
||||||
|
"test_runs" => 1000, // test runs to check if the program works with any input data
|
||||||
|
"inbox_preparation_function" => "level_1_prepare_inbox", // function name of function to prepare inbox
|
||||||
|
"reference_program" => "level_1_reference_program" // function name of the reference program
|
||||||
|
);
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 1 Inbox preparations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_1_prepare_inbox($level_configuration) {
|
||||||
|
$inbox = array();
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
|
||||||
|
array_push($inbox, mt_rand(-9, 29));
|
||||||
|
}
|
||||||
|
return $inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 1 Reference Program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_1_reference_program($inbox, $level_configuration) {
|
||||||
|
$expected_outbox = array();
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
|
||||||
|
$a = array_pop($inbox);
|
||||||
|
array_unshift($expected_outbox, $a);
|
||||||
|
}
|
||||||
|
return $expected_outbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Level 2
|
||||||
|
* Sort 2 numbers, add higher first
|
||||||
|
* Test-Code:
|
||||||
|
--debug
|
||||||
|
-- Sort 2 Numbers
|
||||||
|
start:
|
||||||
|
INBOX
|
||||||
|
COPYTO 0
|
||||||
|
INBOX
|
||||||
|
COPYTO 1
|
||||||
|
SUB 0
|
||||||
|
JUMPN neg
|
||||||
|
--pos
|
||||||
|
COPYFROM 1
|
||||||
|
OUTBOX
|
||||||
|
COPYFROM 0
|
||||||
|
OUTBOX
|
||||||
|
JUMP start
|
||||||
|
|
||||||
|
--neg
|
||||||
|
neg:
|
||||||
|
COPYFROM 0
|
||||||
|
OUTBOX
|
||||||
|
COPYFROM 1
|
||||||
|
OUTBOX
|
||||||
|
JUMP start
|
||||||
|
*******************************************************************/
|
||||||
|
function level_2_description(){
|
||||||
|
$title = "Sortieren";
|
||||||
|
$description = "Nimm jeweils nacheinander zwei Boxen aus der Inbox. Sortiere sie der Reihe nach und lege zuerst die Grössere, danach die Kleinere in die Outbox.<br>" .
|
||||||
|
"Tipp: Verwende die Daten-Register, um eine Box zwischenzulagern, Du hast total 4 Daten-Register zur Verfügung (nummeriert von 0 bis 3).";
|
||||||
|
// $example = "Inbox: " . print_box(5) . "<br>Erwartete Outbox: ";
|
||||||
|
$example = "Inbox: " . box(3) . box(7). box(16) . box(11) . " , " .
|
||||||
|
"Erwartete Outbox: " . box(3) . box(7) . box(11) . box(16) . ".";
|
||||||
|
$criteria = "Verwende maximal 43 Instruktionen und maximal 16 Schritte."; //Make sure it matches the values in the init function!
|
||||||
|
$passcode_for_this_level = "20685401"; //given in level 1 reward
|
||||||
|
return [$title, $description, $example, $criteria, $passcode_for_this_level];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function level_2_configuration(){
|
||||||
|
$configuration = array(
|
||||||
|
"level" => 2,
|
||||||
|
"inbox_size" => 8, //elements in inbox, use even number!
|
||||||
|
"show_outbox_as_coordinate" => false, // only last level should set this to true
|
||||||
|
"max_allowed_instruction" => 16, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"max_allowed_steps" => 43, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"hand" => "", // content of the hand, single value
|
||||||
|
"data_registers" => array("", "", "", ""), // content of the 4 data registers
|
||||||
|
"passcode_for_next_level" => 301861, // passcode for next level
|
||||||
|
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=3&passcode=301861\">nächsten Level</a> weiter. Der Passcode ist 301861.", // shown text if level successes
|
||||||
|
"test_runs" => 1000, // test runs to check if the program works with any input data
|
||||||
|
"inbox_preparation_function" => "level_2_prepare_inbox", // function name of function to prepare inbox
|
||||||
|
"reference_program" => "level_2_reference_program" // function name of the reference program
|
||||||
|
);
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 2 Inbox preparations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_2_prepare_inbox($level_configuration) {
|
||||||
|
$inbox = array();
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
|
||||||
|
array_push($inbox, mt_rand(-9, 29));
|
||||||
|
}
|
||||||
|
return $inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 2 Reference Program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_2_reference_program($inbox, $level_configuration) {
|
||||||
|
$expected_outbox = array();
|
||||||
|
//*******************************************/
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
|
||||||
|
$a = array_pop($inbox);
|
||||||
|
$b = array_pop($inbox);
|
||||||
|
if($a > $b){
|
||||||
|
array_unshift($expected_outbox, $a);
|
||||||
|
array_unshift($expected_outbox, $b);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
array_unshift($expected_outbox, $b);
|
||||||
|
array_unshift($expected_outbox, $a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*******************************************/
|
||||||
|
return $expected_outbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Level 3
|
||||||
|
* Modulo
|
||||||
|
* Test-Code:
|
||||||
|
--debug
|
||||||
|
-- Modulo
|
||||||
|
start:
|
||||||
|
copyfrom 3
|
||||||
|
copyto 2
|
||||||
|
|
||||||
|
INBOX
|
||||||
|
COPYTO 0
|
||||||
|
INBOX
|
||||||
|
COPYTO 1
|
||||||
|
count:
|
||||||
|
copyfrom 0
|
||||||
|
sub 1
|
||||||
|
jumpn done
|
||||||
|
copyto 0
|
||||||
|
bumpup 2
|
||||||
|
jump count
|
||||||
|
done:
|
||||||
|
copyfrom 0
|
||||||
|
outbox
|
||||||
|
jump start
|
||||||
|
*******************************************************************/
|
||||||
|
function level_3_description(){
|
||||||
|
$title = "Modulo";
|
||||||
|
$description = "Nimm jeweils nacheinander zwei Boxen aus der Inbox, dividiere die erste Box durch die Zweite und verschiebe den Rest in die Outbox.
|
||||||
|
Keine Angst, Du musst nicht wirklich dividieren! Und keine Angst, die Inbox enthält weder Boxen mit Nullen noch Boxen mit negativen Zahlen.<br>" .
|
||||||
|
"Du hast 4 Daten-Register zur Verfügung. " .
|
||||||
|
"Zur Unterstützung habe ich Dir ins Daten-Register 3 eine Box mit Wert " . box(0) . " gelegt!";
|
||||||
|
$example = "Inbox: " . box(3) . box(9). box(5) . box(27). " , " .
|
||||||
|
"Erwartete Outbox: " . box(0) . box(2) . ".";
|
||||||
|
$criteria = "Verwende maximal 15 Instruktionen und maximal 260 Schritte."; //Make sure it matches the values in the init function!
|
||||||
|
$passcode_for_this_level = "301861"; //given in level 2 reward
|
||||||
|
return [$title, $description, $example, $criteria, $passcode_for_this_level];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function level_3_configuration(){
|
||||||
|
$configuration = array(
|
||||||
|
"level" => 3,
|
||||||
|
"inbox_size" => 8, //elements in inbox, use even number!
|
||||||
|
"show_outbox_as_coordinate" => false, // only last level should set this to true
|
||||||
|
"max_allowed_instruction" => 15, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"max_allowed_steps" => 350, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"hand" => "", // content of the hand, single value
|
||||||
|
"data_registers" => array("", "", "", "0"), // content of the 4 data registers
|
||||||
|
"passcode_for_next_level" => 405435, // passcode for next level
|
||||||
|
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=4&passcode=405435\">nächsten Level</a> weiter. Der Passcode ist 405435.", // shown text if level successes
|
||||||
|
"test_runs" => 1000, // test runs to check if the program works with any input data
|
||||||
|
"inbox_preparation_function" => "level_3_prepare_inbox", // function name of function to prepare inbox
|
||||||
|
"reference_program" => "level_3_reference_program" // function name of the reference program
|
||||||
|
);
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 3 Inbox preparations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_3_prepare_inbox($level_configuration) {
|
||||||
|
$inbox = array();
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
|
||||||
|
array_push($inbox, mt_rand(2, 9));
|
||||||
|
array_push($inbox, mt_rand(9, 29));
|
||||||
|
}
|
||||||
|
return $inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 3 Reference Program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_3_reference_program($inbox, $level_configuration) {
|
||||||
|
$expected_outbox = array();
|
||||||
|
//*******************************************/
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
|
||||||
|
$a = array_pop($inbox);
|
||||||
|
$b = array_pop($inbox);
|
||||||
|
$c = $a % $b;
|
||||||
|
array_unshift($expected_outbox, $c);
|
||||||
|
}
|
||||||
|
//*******************************************/
|
||||||
|
return $expected_outbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Level 4
|
||||||
|
* Die kleinste Zahl (HRM Level 23)
|
||||||
|
* For each zero terminated string in the INBOX, send to the OUTBOX only the SMALLEST number you've seen in that string. You will never be given an empty string. Reset and repeat for each string.\n\nWhat's a \"zero terminated string\"? Go ask your boss on the previous floor!
|
||||||
|
* Test-Code:
|
||||||
|
--debug
|
||||||
|
-- Die grösste Zahl
|
||||||
|
start:
|
||||||
|
INBOX
|
||||||
|
COPYTO 0
|
||||||
|
pos:
|
||||||
|
INBOX
|
||||||
|
JUMPZ terminator
|
||||||
|
copyto 1
|
||||||
|
copyfrom 0
|
||||||
|
SUB 1
|
||||||
|
JUMPN neg
|
||||||
|
JUMP pos
|
||||||
|
-- zweite ist grösser
|
||||||
|
neg:
|
||||||
|
--undo sub
|
||||||
|
copyfrom 1
|
||||||
|
COPYTO 0
|
||||||
|
JUMP pos
|
||||||
|
--Ende der Gruppe
|
||||||
|
terminator:
|
||||||
|
COPYFROM 0
|
||||||
|
OUTBOX
|
||||||
|
JUMP start
|
||||||
|
*******************************************************************/
|
||||||
|
function level_4_description(){
|
||||||
|
$title = "Die grösste Zahl";
|
||||||
|
$description = "Die Inbox enthält mehrere Zahlen-Gruppen, welche jeweils mit einer Box mit Wert 0 abgeschlossen (terminiert) wird. Für jede Gruppe, lege diejenige Box mit der grössten Zahl in die Outbox.<br>
|
||||||
|
Eine Zahlen-Gruppe enthält mindestens eine Zahlen-Box und eine Terminator-Box.<br>" .
|
||||||
|
"Du hast 4 Daten-Register zur Verfügung. ";
|
||||||
|
$example = "Inbox: " . box(0) . box(8) . box(5) . box(27) .
|
||||||
|
box(0) . box(19) . box(3) . " , " .
|
||||||
|
"Erwartete Outbox: " . box(27) . box(19) . ".";
|
||||||
|
$criteria = "Verwende maximal 15 Instruktionen und maximal 100 Schritte."; //Make sure it matches the values in the init function!
|
||||||
|
$passcode_for_this_level = "405435"; //given in level 3 reward
|
||||||
|
return [$title, $description, $example, $criteria, $passcode_for_this_level];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function level_4_configuration(){
|
||||||
|
$configuration = array(
|
||||||
|
"level" => 4,
|
||||||
|
"inbox_size" => 6, //elements in inbox, use even number!
|
||||||
|
"show_outbox_as_coordinate" => false, // only last level should set this to true
|
||||||
|
"max_allowed_instruction" => 15, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"max_allowed_steps" => 70, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"hand" => "", // content of the hand, single value
|
||||||
|
"data_registers" => array("", "", "", ""), // content of the 4 data registers
|
||||||
|
"passcode_for_next_level" => 5018676, // passcode for next level
|
||||||
|
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=5&passcode=5018676\">nächsten Level</a> weiter. Der Passcode ist 5018676.", // shown text if level successes
|
||||||
|
"test_runs" => 1000, // test runs to check if the program works with any input data
|
||||||
|
"inbox_preparation_function" => "level_4_prepare_inbox", // function name of function to prepare inbox
|
||||||
|
"reference_program" => "level_4_reference_program" // function name of the reference program
|
||||||
|
);
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 4 Inbox preparations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_4_prepare_inbox($level_configuration) {
|
||||||
|
$inbox = array();
|
||||||
|
while(count($inbox) < $level_configuration['inbox_size']){
|
||||||
|
array_push($inbox, 0);
|
||||||
|
$l = mt_rand(1, 4);
|
||||||
|
for($j = 0; $j < $l; $j++){
|
||||||
|
array_push($inbox, mt_rand(1, 29));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 4 Reference Program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_4_reference_program($inbox, $level_configuration) {
|
||||||
|
$expected_outbox = array();
|
||||||
|
//*******************************************/
|
||||||
|
start4:
|
||||||
|
$a = array_pop($inbox);
|
||||||
|
do{
|
||||||
|
$b = array_pop($inbox);
|
||||||
|
if(($b > $a) and ($b !== 0)){
|
||||||
|
$a = $b;
|
||||||
|
}
|
||||||
|
}while($b !== 0);
|
||||||
|
array_unshift($expected_outbox, $a);
|
||||||
|
if(count($inbox) > 0){
|
||||||
|
goto start4;
|
||||||
|
}
|
||||||
|
//*******************************************/
|
||||||
|
return $expected_outbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Level 5
|
||||||
|
* Der Funkspruch
|
||||||
|
* Test-Code:
|
||||||
|
--debug
|
||||||
|
--Der Funkspruch
|
||||||
|
nextWord:
|
||||||
|
--get counter
|
||||||
|
inbox
|
||||||
|
copyto 0
|
||||||
|
nextBox:
|
||||||
|
--get box (and drop it, if zero)
|
||||||
|
inbox
|
||||||
|
jumpz nextBox
|
||||||
|
--decrement counter
|
||||||
|
bumpdn 0
|
||||||
|
jumpz NextIsHot
|
||||||
|
jump nextBox
|
||||||
|
-- counter is zero, Next box is hot
|
||||||
|
NextIsHot:
|
||||||
|
--hot box
|
||||||
|
inbox
|
||||||
|
outbox
|
||||||
|
jump nextWord
|
||||||
|
*******************************************************************/
|
||||||
|
function level_5_description(){
|
||||||
|
$title = "Der Funkspruch";
|
||||||
|
$description = "Vom ausländischen Geheimdienst konnte ein Funkspruch abgefangen, aber noch nicht entschlüsselt werden.
|
||||||
|
Wir haben eine lange Zahlen-Kette, von der wir lediglich wissen, dass die erste Box angibt, wieviele Boxen verworfen werden müssen, bis eine Box
|
||||||
|
mit sinnvollem Inhalt auftaucht (welche wir dann in die Outbox legen sollten). Die Box danach wiederum scheint die Anzahl der nächsten \"Verwerfungen\" zu enthalten.
|
||||||
|
Leider ist dem noch nicht genug; Soll eine Box verworfen werden, welche 0 enthält, gilt sie als Platzhalter und darf nicht mitgezählt werden.
|
||||||
|
Die letzte zu verwerfende Box enthält jedoch nie eine 0!<br>
|
||||||
|
Der Funkspruch ist so aufgebaut, dass immer mindestens eine Box verworfen werden muss.<br>".
|
||||||
|
"Du hast 4 Daten-Register zur Verfügung. ";
|
||||||
|
$example = "Inbox: " . box(0) . box(1) . box(4) . box(9). box(6). box(2). box(5). box(4) . box(5) . box(0) . box(3) . box(2) .
|
||||||
|
box(7) . box(9) . box(1) . " , " .
|
||||||
|
"Erwartete Outbox: " . box(0) . box(4) . box(7) . ".";
|
||||||
|
// $criteria = "Verwende maximal 10 Instruktionen und maximal 315 Schritte."; //Make sure it matches the values in the init function!
|
||||||
|
$criteria = "Funkspruch korrekt entschlüsseln."; //Make sure it matches the values in the init function!
|
||||||
|
$passcode_for_this_level = "5018676"; //given in level 4 reward
|
||||||
|
return [$title, $description, $example, $criteria, $passcode_for_this_level];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function level_5_configuration(){
|
||||||
|
global $level_5_coordinates;
|
||||||
|
$configuration = array(
|
||||||
|
"level" => 5,
|
||||||
|
"inbox_size" => count($level_5_coordinates), //elements in inbox, use even number!
|
||||||
|
"show_outbox_as_coordinate" => true, // only last level should set this to true
|
||||||
|
"max_allowed_instruction" => 99, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"max_allowed_steps" => 999, // counting only true instructions, no comments, labels or empty lines
|
||||||
|
"hand" => "", // content of the hand, single value
|
||||||
|
"data_registers" => array("", "", "", ""), // content of the 4 data registers
|
||||||
|
"passcode_for_next_level" => "", // passcode for next level
|
||||||
|
"reward" => "Herzliche Gratulation!<br>Du kannst die Koordinate des Geocaches in der Outbox ablesen.", // shown text if level successes
|
||||||
|
"test_runs" => 1, // test runs to check if the program works with any input data. Since the inbox is always the same one run is enough
|
||||||
|
"inbox_preparation_function" => "level_5_prepare_inbox", // function name of function to prepare inbox
|
||||||
|
"reference_program" => "level_5_reference_program" // function name of the reference program
|
||||||
|
);
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 5 Inbox preparations
|
||||||
|
* The inbox is always the same!
|
||||||
|
*/
|
||||||
|
function level_5_prepare_inbox($level_configuration) {
|
||||||
|
global $level_5_coordinates;
|
||||||
|
$level_5_coordinates_copy = $level_5_coordinates;
|
||||||
|
$inbox = array();
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
|
||||||
|
//add hot Box
|
||||||
|
// $hot_box = mt_rand(10, 19);
|
||||||
|
$hot_box = array_shift($level_5_coordinates_copy);
|
||||||
|
array_push($inbox, $hot_box);
|
||||||
|
// echo("$hot_box, ");
|
||||||
|
array_push($expected_outbox, $hot_box); //also add it to outbox
|
||||||
|
|
||||||
|
//add dropping values
|
||||||
|
$drops = mt_rand(1, 5); //min 1 max 5
|
||||||
|
for($i = 0; $i < $drops; $i++){ //add dropping values
|
||||||
|
if(mt_rand(0, 9) < 5){ //5 out of 10 should be a zero,
|
||||||
|
if($i > 0){ //but only if not the last drop
|
||||||
|
array_push($inbox, 0); //add zero
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_push($inbox, mt_rand(1, 9));
|
||||||
|
}
|
||||||
|
array_push($inbox, $drops); //add counter
|
||||||
|
}
|
||||||
|
return $inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 5 Reference Program
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function level_5_reference_program($inbox, $level_configuration) {
|
||||||
|
global $level_5_coordinates;
|
||||||
|
$level_5_coordinates_copy = $level_5_coordinates;
|
||||||
|
$expected_outbox = array();
|
||||||
|
//*******************************************/
|
||||||
|
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
|
||||||
|
//add hot Box
|
||||||
|
// $hot_box = mt_rand(10, 19);
|
||||||
|
$hot_box = array_shift($level_5_coordinates_copy);
|
||||||
|
array_push($inbox, $hot_box);
|
||||||
|
// echo("$hot_box, ");
|
||||||
|
array_push($expected_outbox, $hot_box); //also add it to outbox
|
||||||
|
|
||||||
|
//add dropping values
|
||||||
|
$drops = mt_rand(1, 5); //min 1 max 5
|
||||||
|
for($i = 0; $i < $drops; $i++){ //add dropping values
|
||||||
|
if(mt_rand(0, 9) < 5){ //5 out of 10 should be a zero,
|
||||||
|
if($i > 0){ //but only if not the last drop
|
||||||
|
array_push($inbox, 0); //add zero
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_push($inbox, mt_rand(1, 9));
|
||||||
|
}
|
||||||
|
array_push($inbox, $drops); //add counter
|
||||||
|
}
|
||||||
|
//*******************************************/
|
||||||
|
// print_r($expected_outbox);
|
||||||
|
return $expected_outbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|