commit ea6898503364bade67f3d83558fa258dfa7a799b Author: CaCO3 Date: Sat May 4 09:40:23 2024 +0200 Init diff --git a/hrm/editor.php b/hrm/editor.php new file mode 100755 index 0000000..d5c20ca --- /dev/null +++ b/hrm/editor.php @@ -0,0 +1,201 @@ + + + +"); + $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\"
"); +if(is_callable($level_description)) { // The function exists + $parameters_valid = true; + list($title, $description, $example, $criteria, $passcode) = $level_description(); +} +else{ + $parameters_valid = false; + $passcode = ""; +} +?> + + +<? echo("$GC_ID: $GC_NAME"); ?> - Code Editor (Level <? echo("$level: \"$title\""); ?>) + + + + + + + + + + + + + + + + + + +
+

- Code Editor (Level )

+ + + +"); + if($passcode != $_GET['passcode']){ //passcode is wrong, level not allowed +?> +

Der Pacsscode für das angegebene Level ist ungültig!
+ Versuchs mal mit Level 1.

+ +

Aufgabe

+
+ +

Beispiel (Die erste Box ist jeweils die Box ganz rechts)

+
+ +

Test-Kriterien

+

+ +
Hmm, dein Browser unterstützt leider kein lokales speichern. D.h., Du musst selber dafür sorgen, dass Du dein Programm zwischenspeicherst, befor Du es ausführst!
+
+ + +
+ + + +
+

Programm-Code Editor

+
+ +

+ + +
+ +
+

Formatierter Programm-Code

+
Lade Programm...
+
+

+
+
+ + + Das angegebene Level existiert nicht!
+ Versuchs mal mit Level 1. + + + diff --git a/hrm/functions.js b/hrm/functions.js new file mode 100755 index 0000000..20fc03c --- /dev/null +++ b/hrm/functions.js @@ -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 ="
"; + +// if(init_step == 0){ +// init_box_content = init_box_content + "
Initializing CPU...
"; +// } + if(init_step == 1){ + init_box_content = init_box_content + style + "Überprüfe Hand...
"; + } + else if(init_step == 2){ + init_box_content = init_box_content + style + "Überprüfe Daten-Register...
"; + } +// 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...
"; +// } + else if(init_step == 3){ + init_box_content = init_box_content + style + "Überprüfe Inbox...
"; + } + else if(init_step == 4){ + init_box_content = init_box_content + style + "Überprüfe Outbox...
"; + } + else if(init_step == 5){ + init_box_content = init_box_content + style + "Lade Programm...
"; + } + else if(init_step == 6){ + init_box_content = init_box_content + style + summary + "
"; + 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); +} + diff --git a/hrm/functions.php b/hrm/functions.php new file mode 100755 index 0000000..650ae87 --- /dev/null +++ b/hrm/functions.php @@ -0,0 +1,888 @@ +
Gehe wieder zum Editor-Fenster zurück, um deinen Programm-Code zu verbessern. Viel Glück!"; + $program = array(); + +// $inbox = array_reverse($inbox); + +// echo("

Parse Program

"); +// echo("
"); + + $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\"
\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
"; + if(!preg_match("/^[a-zA-Z]+$/", $label)){ //found invalid character in label +// echo("Parse error on line $program_line_counter: $line!\n"); + $program_summary = "Fehler in Programm-Code, Zeile $program_line_counter: $line! $back_to_editor
"; + 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 = "Fehler in Programm-Code, Zeile $program_line_counter: $line! $back_to_editor
"; + 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).")
"); + $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("]
"); +// echo("Hand: $hand, Data registers: ["); +// foreach($data_registers as $element){ echo("$element, "); } +// echo("]
"); +// echo("Current Outbox: ["); +// foreach($outbox as $element){ echo("$element, "); } echo("] , Expected Outbox: ["); +// foreach($expected_outbox as $element){ echo("$element, "); }; echo("]
"); + + 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("
Program is incorrect
"); + return [PROGRAM_IS_WRONG, $used_steps - 1]; + } + } +// echo("

"); + + if(count($outbox) == count($expected_outbox)){ //outbox is full, program completed successfully +// echo("Program is correct
"); + return [PROGRAM_IS_CORRECT, $used_steps - 1]; + } + + +// array_push($step_boxes, $instructions_line_counter); + if($used_steps > $max_allowed_steps){ +// echo("
Maximum steps reached (" . ($used_steps -1 ) . "/$max_allowed_steps)
"); + 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
"); + +//-------------------------------------------------------------------------- + switch($cmd){ + case "inbox": + if(count($inbox) > 0){ //Check: Inbox is not empty + $hand = array_pop($inbox); + } + else{ +// echo("
inbox: command is NOT valid with current registers/boxes
"); + return [PROGRAM_IS_WRONG, $used_steps - 1]; + } + break; + +//-------------------------------------------------------------------------- + case "outbox": + if($hand !== ""){ //Check: Hand is not empty + array_unshift($outbox, $hand); + $hand = ""; + } + else{ +// echo("
outbox: command is NOT valid with current registers/boxes
"); + 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("
: jumpcommand is NOT valid with current registers/boxes
"); + 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("
jumpz: command is NOT valid with current registers/boxes
"); + return [PROGRAM_IS_WRONG, $used_steps - 1]; + } + } + else{ +// echo("
jumpz: command is NOT valid with current registers/boxes
"); + 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("
jumpn: command is NOT valid with current registers/boxes
"); + return [PROGRAM_IS_WRONG, $used_steps - 1]; + } + } + else{ +// echo("
command is NOT valid with current registers/boxes
"); + 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("
copyto: command is NOT valid with current registers/boxes
"); + 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("
copyfrom: command is NOT valid with current registers/boxes
"); + 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("
add: command is NOT valid with current registers/boxes
"); + 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("
: subcommand is NOT valid with current registers/boxes
"); + 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("
bumpup: command is NOT valid with current registers/boxes
"); + 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("
bumpdn: command is NOT valid with current registers/boxes
"); + 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("
$used_steps
"); + $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 = "

Gehe wieder zum Editor-Fenster zurück, 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] . "
"); + 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
"); + 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 = "
Gehe wieder zum Editor-Fenster zurück, 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).")
"); + + $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: $cmd", "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: $cmd
+ 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: $cmd", "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: $cmd
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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: $cmd $param", "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: $cmd $param
+ 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 $label", "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: $cmd $param
+ 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
"); + 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).

$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++; +?> + +
+
+
+
+\n"); + print_registers($hand, $data_registers); + echo("
\n"); + print_outbox($outbox, $outbox_size, $show_outbox_as_coordinate); + echo("\n"); +?> +
+ +$value "; +} + + + + +function print_box($value){ + if($value !== ""){ + echo("
" . box($value) . "
"); + } + else{ + echo("
"); + } +} + + + +function print_registers($hand, $data_registers){ +?> +
+
+
+ +
+ +
+
+

Daten-Register:

+
+
+ +
+
+

+
+ +
+
+
+ +
+

Inbox =>

+
+...
"); + for($i = $inbox_size; $i > 0; $i--){ + print_box($inbox[count($inbox) - $i]); + } + } +?> +
+
+
+ +
+

=> Outbox

+N
"); + + 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++; + } + } +?> +
+
+
E
");} + elseif(($position == 1) or ($position == 9)){ echo("
°
");} + else if(($position == 3) or ($position == 11)){ echo("
,
");} +} + + + + +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); + } +} + + + + + + + +?> diff --git a/hrm/help.htm b/hrm/help.htm new file mode 100755 index 0000000..0f74f81 --- /dev/null +++ b/hrm/help.htm @@ -0,0 +1,68 @@ + + + +Code Editor Help + + + + + + + + + + + + + + + +

Code Editor Help

+ +

Allgemein

+ Die Gross-/Kleinschreibung bei den Befehlen wird ignoriert (nicht aber bei den Sprungzielen).
+ Leerzeilen sowie Leerzeichen am Anfang/Ende einer Zeile werden ignoriert.
+ Jeder Befehl zählt als eine Instruktion. + Sprungziele und Kommentare zählen nicht als Befehle.

+ Aus der Inbox kannst Du nur Boxen entnehmen und in die Outbox kannst Du nur Boxen ablegen.
+ Du kannst jeweils eine Box in der Hand halten.
+ Je nach Level hast du mehrere Daten-Register, welche Du als Zwischenspeicher verwenden kannst. + + +

Befehle

+ + + + + + + + + + + + + + +
INBOX
Nimmt die nächste Box aus der Inbox in die Hand.
OUTBOX
Legt die Box aus der Hand in die Outbox.
COPYFROM 0
Kopiert die Box aus dem ausgewählten Daten-Register in die Hand.
COPYTO 0
Kopiert die Box aus der Hand in das ausgewählte Daten-Register.
ADD 0
Der Wert der Box in der Hand und der Wert der Box im ausgewählten Daten-Register werden addiert und in die Hand kopiert.
SUB 0
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.
BUMPUP 0
Addiert 1 zur Box im ausgewählten Daten-Register. Anschliessend wird die neue Box in die Hand kopiert.
BUMPDN 0
Subtrahiert 1 von der Box im ausgewählten Daten-Register. Anschliessend wird die neue Box in die Hand kopiert.
<SPRUNGZIEL>:
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.
JUMP <SPRUNGZIEL>
Springe an das angegebene Sprungziel.
JUMPN <SPRUNGZIEL>
Springe an das angegebene Sprungziel, wenn der Wert der Box in der Hand negativ ist. Sonst fahre mit der nächsten Zeile weiter.
JUMPZ <SPRUNGZIEL>
Springe an das angegebene Sprungziel, wenn der Wert der Box in der Hand 0 ist. Sonst fahre mit der nächsten Zeile weiter.
<Kommentar>
Ein Kommentar ist eine Notiz als Hilfe für dich. Er muss mit zwei Minus-Zeichen anfangen und kann beliebigen Text enthalten.
Beispiel: "-- Das ist ein Kommentar".
+ +

Über

+ Website und Algorithmus: ©2018 by George Ruinelli.
+ Grafische Darstellung (Human Resource Machine Program Viewer) ©2015 Alan De Smet.
+ Einige Levels und Ideen sind aus dem Spiel Human Ressource Machine entnommen. + + + diff --git a/hrm/human-resource-machine-viewer/GPLv3-LICENSE.md b/hrm/human-resource-machine-viewer/GPLv3-LICENSE.md new file mode 100755 index 0000000..f0188ff --- /dev/null +++ b/hrm/human-resource-machine-viewer/GPLv3-LICENSE.md @@ -0,0 +1,679 @@ +GNU GENERAL PUBLIC LICENSE +========================== + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. +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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + +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 +. diff --git a/hrm/human-resource-machine-viewer/README.md b/hrm/human-resource-machine-viewer/README.md new file mode 100755 index 0000000..b657ca0 --- /dev/null +++ b/hrm/human-resource-machine-viewer/README.md @@ -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 . + + +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. diff --git a/hrm/human-resource-machine-viewer/TODO b/hrm/human-resource-machine-viewer/TODO new file mode 100755 index 0000000..aa24793 --- /dev/null +++ b/hrm/human-resource-machine-viewer/TODO @@ -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. diff --git a/hrm/human-resource-machine-viewer/hrm-comments.md b/hrm/human-resource-machine-viewer/hrm-comments.md new file mode 100755 index 0000000..2dca3a8 --- /dev/null +++ b/hrm/human-resource-machine-viewer/hrm-comments.md @@ -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. + diff --git a/hrm/human-resource-machine-viewer/hrm.css b/hrm/human-resource-machine-viewer/hrm.css new file mode 100755 index 0000000..3dba2a5 --- /dev/null +++ b/hrm/human-resource-machine-viewer/hrm.css @@ -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 +. +*/ + +.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; +} diff --git a/hrm/human-resource-machine-viewer/hrm.js b/hrm/human-resource-machine-viewer/hrm.js new file mode 100755 index 0000000..259086c --- /dev/null +++ b/hrm/human-resource-machine-viewer/hrm.js @@ -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 +. +*/ + + +//////////////////////////////////////////////////////////////////////////////// +// 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 +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; diff --git a/hrm/human-resource-machine-viewer/label-test.asm b/hrm/human-resource-machine-viewer/label-test.asm new file mode 100755 index 0000000..7e438e2 --- /dev/null +++ b/hrm/human-resource-machine-viewer/label-test.asm @@ -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 +; + diff --git a/hrm/human-resource-machine-viewer/pako_inflate.min.js b/hrm/human-resource-machine-viewer/pako_inflate.min.js new file mode 100755 index 0000000..77f6c00 --- /dev/null +++ b/hrm/human-resource-machine-viewer/pako_inflate.min.js @@ -0,0 +1,2 @@ +/* pako 0.2.8 nodeca/pako */ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.pako=e()}}(function(){return function e(t,i,n){function a(o,s){if(!i[o]){if(!t[o]){var f="function"==typeof require&&require;if(!s&&f)return f(o,!0);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var d=i[o]={exports:{}};t[o][0].call(d.exports,function(e){var i=t[o][1][e];return a(i?i:e)},d,d.exports,e,t,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;or;r++)e[a+r]=t[i+r]},flattenChunks:function(e){var t,i,n,a,r,o;for(n=0,t=0,i=e.length;i>t;t++)n+=e[t].length;for(o=new Uint8Array(n),a=0,t=0,i=e.length;i>t;t++)r=e[t],o.set(r,a),a+=r.length;return o}},r={arraySet:function(e,t,i,n,a){for(var r=0;n>r;r++)e[a+r]=t[i+r]},flattenChunks:function(e){return[].concat.apply([],e)}};i.setTyped=function(e){e?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,a)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,r))},i.setTyped(n)},{}],2:[function(e,t,i){"use strict";function n(e,t){if(65537>t&&(e.subarray&&o||!e.subarray&&r))return String.fromCharCode.apply(null,a.shrinkBuf(e,t));for(var i="",n=0;t>n;n++)i+=String.fromCharCode(e[n]);return i}var a=e("./common"),r=!0,o=!0;try{String.fromCharCode.apply(null,[0])}catch(s){r=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(s){o=!1}for(var f=new a.Buf8(256),l=0;256>l;l++)f[l]=l>=252?6:l>=248?5:l>=240?4:l>=224?3:l>=192?2:1;f[254]=f[254]=1,i.string2buf=function(e){var t,i,n,r,o,s=e.length,f=0;for(r=0;s>r;r++)i=e.charCodeAt(r),55296===(64512&i)&&s>r+1&&(n=e.charCodeAt(r+1),56320===(64512&n)&&(i=65536+(i-55296<<10)+(n-56320),r++)),f+=128>i?1:2048>i?2:65536>i?3:4;for(t=new a.Buf8(f),o=0,r=0;f>o;r++)i=e.charCodeAt(r),55296===(64512&i)&&s>r+1&&(n=e.charCodeAt(r+1),56320===(64512&n)&&(i=65536+(i-55296<<10)+(n-56320),r++)),128>i?t[o++]=i:2048>i?(t[o++]=192|i>>>6,t[o++]=128|63&i):65536>i?(t[o++]=224|i>>>12,t[o++]=128|i>>>6&63,t[o++]=128|63&i):(t[o++]=240|i>>>18,t[o++]=128|i>>>12&63,t[o++]=128|i>>>6&63,t[o++]=128|63&i);return t},i.buf2binstring=function(e){return n(e,e.length)},i.binstring2buf=function(e){for(var t=new a.Buf8(e.length),i=0,n=t.length;n>i;i++)t[i]=e.charCodeAt(i);return t},i.buf2string=function(e,t){var i,a,r,o,s=t||e.length,l=new Array(2*s);for(a=0,i=0;s>i;)if(r=e[i++],128>r)l[a++]=r;else if(o=f[r],o>4)l[a++]=65533,i+=o-1;else{for(r&=2===o?31:3===o?15:7;o>1&&s>i;)r=r<<6|63&e[i++],o--;o>1?l[a++]=65533:65536>r?l[a++]=r:(r-=65536,l[a++]=55296|r>>10&1023,l[a++]=56320|1023&r)}return n(l,a)},i.utf8border=function(e,t){var i;for(t=t||e.length,t>e.length&&(t=e.length),i=t-1;i>=0&&128===(192&e[i]);)i--;return 0>i?t:0===i?t:i+f[e[i]]>t?i:t}},{"./common":1}],3:[function(e,t,i){"use strict";function n(e,t,i,n){for(var a=65535&e|0,r=e>>>16&65535|0,o=0;0!==i;){o=i>2e3?2e3:i,i-=o;do a=a+t[n++]|0,r=r+a|0;while(--o);a%=65521,r%=65521}return a|r<<16|0}t.exports=n},{}],4:[function(e,t,i){t.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],5:[function(e,t,i){"use strict";function n(){for(var e,t=[],i=0;256>i;i++){e=i;for(var n=0;8>n;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}function a(e,t,i,n){var a=r,o=n+i;e=-1^e;for(var s=n;o>s;s++)e=e>>>8^a[255&(e^t[s])];return-1^e}var r=n();t.exports=a},{}],6:[function(e,t,i){"use strict";function n(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}t.exports=n},{}],7:[function(e,t,i){"use strict";var n=30,a=12;t.exports=function(e,t){var i,r,o,s,f,l,d,u,h,c,b,w,m,k,_,g,v,p,x,y,S,E,B,Z,A;i=e.state,r=e.next_in,Z=e.input,o=r+(e.avail_in-5),s=e.next_out,A=e.output,f=s-(t-e.avail_out),l=s+(e.avail_out-257),d=i.dmax,u=i.wsize,h=i.whave,c=i.wnext,b=i.window,w=i.hold,m=i.bits,k=i.lencode,_=i.distcode,g=(1<m&&(w+=Z[r++]<>>24,w>>>=x,m-=x,x=p>>>16&255,0===x)A[s++]=65535&p;else{if(!(16&x)){if(0===(64&x)){p=k[(65535&p)+(w&(1<m&&(w+=Z[r++]<>>=x,m-=x),15>m&&(w+=Z[r++]<>>24,w>>>=x,m-=x,x=p>>>16&255,!(16&x)){if(0===(64&x)){p=_[(65535&p)+(w&(1<m&&(w+=Z[r++]<m&&(w+=Z[r++]<d){e.msg="invalid distance too far back",i.mode=n;break e}if(w>>>=x,m-=x,x=s-f,S>x){if(x=S-x,x>h&&i.sane){e.msg="invalid distance too far back",i.mode=n;break e}if(E=0,B=b,0===c){if(E+=u-x,y>x){y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}}else if(x>c){if(E+=u+c-x,x-=c,y>x){y-=x;do A[s++]=b[E++];while(--x);if(E=0,y>c){x=c,y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}}}else if(E+=c-x,y>x){y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}for(;y>2;)A[s++]=B[E++],A[s++]=B[E++],A[s++]=B[E++],y-=3;y&&(A[s++]=B[E++],y>1&&(A[s++]=B[E++]))}else{E=s-S;do A[s++]=A[E++],A[s++]=A[E++],A[s++]=A[E++],y-=3;while(y>2);y&&(A[s++]=A[E++],y>1&&(A[s++]=A[E++]))}break}}break}}while(o>r&&l>s);y=m>>3,r-=y,m-=y<<3,w&=(1<r?5+(o-r):5-(r-o),e.avail_out=l>s?257+(l-s):257-(s-l),i.hold=w,i.bits=m}},{}],8:[function(e,t,i){"use strict";function n(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function a(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new k.Buf16(320),this.work=new k.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function r(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=T,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new k.Buf32(be),t.distcode=t.distdyn=new k.Buf32(we),t.sane=1,t.back=-1,A):N}function o(e){var t;return e&&e.state?(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,r(e)):N}function s(e,t){var i,n;return e&&e.state?(n=e.state,0>t?(i=0,t=-t):(i=(t>>4)+1,48>t&&(t&=15)),t&&(8>t||t>15)?N:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,o(e))):N}function f(e,t){var i,n;return e?(n=new a,e.state=n,n.window=null,i=s(e,t),i!==A&&(e.state=null),i):N}function l(e){return f(e,ke)}function d(e){if(_e){var t;for(w=new k.Buf32(512),m=new k.Buf32(32),t=0;144>t;)e.lens[t++]=8;for(;256>t;)e.lens[t++]=9;for(;280>t;)e.lens[t++]=7;for(;288>t;)e.lens[t++]=8;for(p(y,e.lens,0,288,w,0,e.work,{bits:9}),t=0;32>t;)e.lens[t++]=5;p(S,e.lens,0,32,m,0,e.work,{bits:5}),_e=!1}e.lencode=w,e.lenbits=9,e.distcode=m,e.distbits=5}function u(e,t,i,n){var a,r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(k.arraySet(r.window,t,i-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),k.arraySet(r.window,t,i-n,a,r.wnext),n-=a,n?(k.arraySet(r.window,t,i-n,n,0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whavec;){if(0===f)break e;f--,h+=a[o++]<>>8&255,i.check=g(i.check,Ze,2,0),h=0,c=0,i.mode=U;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&h)<<8)+(h>>8))%31){e.msg="incorrect header check",i.mode=ue;break}if((15&h)!==F){e.msg="unknown compression method",i.mode=ue;break}if(h>>>=4,c-=4,xe=(15&h)+8,0===i.wbits)i.wbits=xe;else if(xe>i.wbits){e.msg="invalid window size",i.mode=ue;break}i.dmax=1<c;){if(0===f)break e;f--,h+=a[o++]<>8&1),512&i.flags&&(Ze[0]=255&h,Ze[1]=h>>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0,i.mode=D;case D:for(;32>c;){if(0===f)break e;f--,h+=a[o++]<>>8&255,Ze[2]=h>>>16&255,Ze[3]=h>>>24&255,i.check=g(i.check,Ze,4,0)),h=0,c=0,i.mode=L;case L:for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>8),512&i.flags&&(Ze[0]=255&h,Ze[1]=h>>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0,i.mode=H;case H:if(1024&i.flags){for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0}else i.head&&(i.head.extra=null);i.mode=j;case j:if(1024&i.flags&&(m=i.length,m>f&&(m=f),m&&(i.head&&(xe=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),k.arraySet(i.head.extra,a,o,m,xe)),512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,i.length-=m),i.length))break e;i.length=0,i.mode=M;case M:if(2048&i.flags){if(0===f)break e;m=0;do xe=a[o+m++],i.head&&xe&&i.length<65536&&(i.head.name+=String.fromCharCode(xe));while(xe&&f>m);if(512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,xe)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=K;case K:if(4096&i.flags){if(0===f)break e;m=0;do xe=a[o+m++],i.head&&xe&&i.length<65536&&(i.head.comment+=String.fromCharCode(xe));while(xe&&f>m);if(512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,xe)break e}else i.head&&(i.head.comment=null);i.mode=P;case P:if(512&i.flags){for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=G;break;case Y:for(;32>c;){if(0===f)break e;f--,h+=a[o++]<>>=7&c,c-=7&c,i.mode=fe;break}for(;3>c;){if(0===f)break e;f--,h+=a[o++]<>>=1,c-=1,3&h){case 0:i.mode=W;break;case 1:if(d(i),i.mode=te,t===Z){h>>>=2,c-=2;break e}break;case 2:i.mode=V;break;case 3:e.msg="invalid block type",i.mode=ue}h>>>=2,c-=2;break;case W:for(h>>>=7&c,c-=7&c;32>c;){if(0===f)break e;f--,h+=a[o++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=ue;break}if(i.length=65535&h,h=0,c=0,i.mode=J,t===Z)break e;case J:i.mode=Q;case Q:if(m=i.length){if(m>f&&(m=f),m>l&&(m=l),0===m)break e;k.arraySet(r,a,o,m,s),f-=m,o+=m,l-=m,s+=m,i.length-=m;break}i.mode=G;break;case V:for(;14>c;){if(0===f)break e;f--,h+=a[o++]<>>=5,c-=5,i.ndist=(31&h)+1,h>>>=5,c-=5,i.ncode=(15&h)+4,h>>>=4,c-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=ue;break}i.have=0,i.mode=$;case $:for(;i.havec;){if(0===f)break e;f--,h+=a[o++]<>>=3,c-=3}for(;i.have<19;)i.lens[Ae[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,Se={bits:i.lenbits},ye=p(x,i.lens,0,19,i.lencode,0,i.work,Se),i.lenbits=Se.bits,ye){e.msg="invalid code lengths set",i.mode=ue;break}i.have=0,i.mode=ee;case ee:for(;i.have>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<_e)h>>>=me,c-=me,i.lens[i.have++]=_e;else{if(16===_e){for(Ee=me+2;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,0===i.have){e.msg="invalid bit length repeat",i.mode=ue;break}xe=i.lens[i.have-1],m=3+(3&h),h>>>=2,c-=2}else if(17===_e){for(Ee=me+3;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,xe=0,m=3+(7&h),h>>>=3,c-=3}else{for(Ee=me+7;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,xe=0,m=11+(127&h),h>>>=7,c-=7}if(i.have+m>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=ue;break}for(;m--;)i.lens[i.have++]=xe}}if(i.mode===ue)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=ue;break}if(i.lenbits=9,Se={bits:i.lenbits},ye=p(y,i.lens,0,i.nlen,i.lencode,0,i.work,Se),i.lenbits=Se.bits,ye){e.msg="invalid literal/lengths set",i.mode=ue;break}if(i.distbits=6,i.distcode=i.distdyn,Se={bits:i.distbits},ye=p(S,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,Se),i.distbits=Se.bits,ye){e.msg="invalid distances set",i.mode=ue;break}if(i.mode=te,t===Z)break e;case te:i.mode=ie;case ie:if(f>=6&&l>=258){e.next_out=s,e.avail_out=l,e.next_in=o,e.avail_in=f,i.hold=h,i.bits=c,v(e,w),s=e.next_out,r=e.output,l=e.avail_out,o=e.next_in,a=e.input,f=e.avail_in,h=i.hold,c=i.bits,i.mode===G&&(i.back=-1);break}for(i.back=0;Be=i.lencode[h&(1<>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<>ge)],me=Be>>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=ge+me);){if(0===f)break e;f--,h+=a[o++]<>>=ge,c-=ge,i.back+=ge}if(h>>>=me,c-=me,i.back+=me,i.length=_e,0===ke){i.mode=se;break}if(32&ke){i.back=-1,i.mode=G;break}if(64&ke){e.msg="invalid literal/length code",i.mode=ue;break}i.extra=15&ke,i.mode=ne;case ne:if(i.extra){for(Ee=i.extra;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=ae;case ae:for(;Be=i.distcode[h&(1<>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<>ge)],me=Be>>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=ge+me);){if(0===f)break e;f--,h+=a[o++]<>>=ge,c-=ge,i.back+=ge}if(h>>>=me,c-=me,i.back+=me,64&ke){e.msg="invalid distance code",i.mode=ue;break}i.offset=_e,i.extra=15&ke,i.mode=re;case re:if(i.extra){for(Ee=i.extra;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=ue;break}i.mode=oe;case oe:if(0===l)break e;if(m=w-l,i.offset>m){if(m=i.offset-m,m>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=ue;break}m>i.wnext?(m-=i.wnext,be=i.wsize-m):be=i.wnext-m,m>i.length&&(m=i.length),we=i.window}else we=r,be=s-i.offset,m=i.length;m>l&&(m=l),l-=m,i.length-=m;do r[s++]=we[be++];while(--m);0===i.length&&(i.mode=ie);break;case se:if(0===l)break e;r[s++]=i.length,l--,i.mode=ie;break;case fe:if(i.wrap){for(;32>c;){if(0===f)break e;f--,h|=a[o++]<c;){if(0===f)break e;f--,h+=a[o++]<=z;z++)j[z]=0;for(R=0;b>R;R++)j[t[i+R]]++;for(C=A,O=a;O>=1&&0===j[O];O--);if(C>O&&(C=O),0===O)return w[m++]=20971520,w[m++]=20971520,_.bits=1,0;for(N=1;O>N&&0===j[N];N++);for(N>C&&(C=N),T=1,z=1;a>=z;z++)if(T<<=1,T-=j[z],0>T)return-1;if(T>0&&(e===s||1!==O))return-1;for(M[1]=0,z=1;a>z;z++)M[z+1]=M[z]+j[z];for(R=0;b>R;R++)0!==t[i+R]&&(k[M[t[i+R]]++]=R);if(e===s?(L=K=k,S=19):e===f?(L=d,H-=257,K=u,P-=257,S=256):(L=h,K=c,S=-1),D=0,R=0,z=N,y=m,I=C,F=0,p=-1,U=1<r||e===l&&U>o)return 1;for(var Y=0;;){Y++,E=z-F,k[R]S?(B=K[P+k[R]],Z=L[H+k[R]]):(B=96,Z=0),g=1<>F)+v]=E<<24|B<<16|Z|0;while(0!==v);for(g=1<>=1;if(0!==g?(D&=g-1,D+=g):D=0,R++,0===--j[z]){if(z===O)break;z=t[i+k[R]]}if(z>C&&(D&x)!==p){for(0===F&&(F=C),y+=N,I=z-F,T=1<I+F&&(T-=j[I+F],!(0>=T));)I++,T<<=1;if(U+=1<r||e===l&&U>o)return 1;p=D&x,w[p]=C<<24|I<<16|y-m|0}}return 0!==D&&(w[y+D]=z-F<<24|64<<16|0),_.bits=C,0}},{"../utils/common":1}],10:[function(e,t,i){"use strict";t.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],11:[function(e,t,i){"use strict";function n(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}t.exports=n},{}],"/lib/inflate.js":[function(e,t,i){"use strict";function n(e,t){var i=new c(t);if(i.push(e,!0),i.err)throw i.msg;return i.result}function a(e,t){return t=t||{},t.raw=!0,n(e,t)}var r=e("./zlib/inflate.js"),o=e("./utils/common"),s=e("./utils/strings"),f=e("./zlib/constants"),l=e("./zlib/messages"),d=e("./zlib/zstream"),u=e("./zlib/gzheader"),h=Object.prototype.toString,c=function(e){this.options=o.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0===(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var i=r.inflateInit2(this.strm,t.windowBits);if(i!==f.Z_OK)throw new Error(l[i]);this.header=new u,r.inflateGetHeader(this.strm,this.header)};c.prototype.push=function(e,t){var i,n,a,l,d,u=this.strm,c=this.options.chunkSize,b=!1;if(this.ended)return!1;n=t===~~t?t:t===!0?f.Z_FINISH:f.Z_NO_FLUSH,"string"==typeof e?u.input=s.binstring2buf(e):"[object ArrayBuffer]"===h.call(e)?u.input=new Uint8Array(e):u.input=e,u.next_in=0,u.avail_in=u.input.length;do{if(0===u.avail_out&&(u.output=new o.Buf8(c),u.next_out=0,u.avail_out=c),i=r.inflate(u,f.Z_NO_FLUSH),i===f.Z_BUF_ERROR&&b===!0&&(i=f.Z_OK,b=!1),i!==f.Z_STREAM_END&&i!==f.Z_OK)return this.onEnd(i),this.ended=!0,!1;u.next_out&&(0===u.avail_out||i===f.Z_STREAM_END||0===u.avail_in&&(n===f.Z_FINISH||n===f.Z_SYNC_FLUSH))&&("string"===this.options.to?(a=s.utf8border(u.output,u.next_out),l=u.next_out-a,d=s.buf2string(u.output,a),u.next_out=l,u.avail_out=c-l,l&&o.arraySet(u.output,u.output,a,l,0),this.onData(d)):this.onData(o.shrinkBuf(u.output,u.next_out))),0===u.avail_in&&0===u.avail_out&&(b=!0)}while((u.avail_in>0||0===u.avail_out)&&i!==f.Z_STREAM_END);return i===f.Z_STREAM_END&&(n=f.Z_FINISH),n===f.Z_FINISH?(i=r.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===f.Z_OK):n===f.Z_SYNC_FLUSH?(this.onEnd(f.Z_OK),u.avail_out=0,!0):!0},c.prototype.onData=function(e){this.chunks.push(e)},c.prototype.onEnd=function(e){e===f.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg},i.Inflate=c,i.inflate=n,i.inflateRaw=a,i.ungzip=n},{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate.js":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")}); diff --git a/hrm/human-resource-machine-viewer/simple.asm b/hrm/human-resource-machine-viewer/simple.asm new file mode 100755 index 0000000..c0fda0b --- /dev/null +++ b/hrm/human-resource-machine-viewer/simple.asm @@ -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; + diff --git a/hrm/images/bg_tiles.png b/hrm/images/bg_tiles.png new file mode 100755 index 0000000..b6f4598 Binary files /dev/null and b/hrm/images/bg_tiles.png differ diff --git a/hrm/images/hand.png b/hrm/images/hand.png new file mode 100755 index 0000000..b81c67d Binary files /dev/null and b/hrm/images/hand.png differ diff --git a/hrm/images/help.png b/hrm/images/help.png new file mode 100755 index 0000000..f8e80d6 Binary files /dev/null and b/hrm/images/help.png differ diff --git a/hrm/images/next.png b/hrm/images/next.png new file mode 100755 index 0000000..2e77330 Binary files /dev/null and b/hrm/images/next.png differ diff --git a/hrm/images/pause.png b/hrm/images/pause.png new file mode 100755 index 0000000..c280fec Binary files /dev/null and b/hrm/images/pause.png differ diff --git a/hrm/images/play.png b/hrm/images/play.png new file mode 100755 index 0000000..452ad10 Binary files /dev/null and b/hrm/images/play.png differ diff --git a/hrm/images/previous.png b/hrm/images/previous.png new file mode 100755 index 0000000..40c7360 Binary files /dev/null and b/hrm/images/previous.png differ diff --git a/hrm/images/reset.png b/hrm/images/reset.png new file mode 100755 index 0000000..f494632 Binary files /dev/null and b/hrm/images/reset.png differ diff --git a/hrm/images/screenshot.png b/hrm/images/screenshot.png new file mode 100755 index 0000000..7d41167 Binary files /dev/null and b/hrm/images/screenshot.png differ diff --git a/hrm/run.php b/hrm/run.php new file mode 100755 index 0000000..96e45c1 --- /dev/null +++ b/hrm/run.php @@ -0,0 +1,368 @@ + + +"); + $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
"); + $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
"); + $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
"); +// } + +?> + + <? echo("$GC_ID: $GC_NAME"); ?> - Programm ausführen (Level <? echo("$level: \"$title\""); ?>) + + + + + + + + + + +

- Programm ausführen (Level )

+ +"); +// echo("$title, $description, $example, $criteria
"); +// $parameters_valid = true; + + +// echo("Passcode: $passcode, given: " . $_GET['passcode'] . "
"); + if($passcode != $_GET['passcode']){ //passcode is wrong, level not allowed +?> +

Der Passcode für das angegebene Level ist ungültig!
+ Versuchs mal mit Level 1.

+ +

Kein Programm-Code übergeben!

+"); +?> +

Das angegebene Level existiert nicht!
+ Versuchs mal mit Level 1.

+"); + // print_r($arr_asm); + // echo(""); + array_walk($arr_asm, 'cleanup_asm_array'); + $arr_asm = array_slice(array_diff($arr_asm, array('')), 0); //Remove all empty lines from array + // echo("
");
+    //     print_r($arr_asm);
+    //     echo("
"); + + + 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,
"); +// echo("program_valid: \"$program_valid\"
"); + + $debug = false; + if($program[0][cmd] == 'comment'){ + if($program[0][comment] == '--debug'){ + echo("

DEBUG Modus

"); + $debug = true; + } + } + + + if($debug == true){ + echo("
Program Data:\nUsed Instruction: $instruction_counter\n");
+            echo("Program: ");
+            print_r($program);
+            echo("
"); + echo("
"); + } + + /*********************************************************** + * 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 "
Level Configuration: ";
+            print_r($level_configuration);
+            echo("
"); + echo("
"); + } + +// echo("Reward: $reward
"); + + +// 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 "
Testing program with many iterations...
"; + } + + 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 "
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("
"); + echo("
"); + } + + + + /*********************************************************** + * Test the program for the specific level with the shown inputs + ***********************************************************/ + if($debug == true){ + echo "
Testing the program with the shown inputs...
"; + } + +// 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 "
Level Status: $program_outcome\n";
+            echo("Inbox: ");
+            print_r($inbox);
+            echo("Expected Outbox: ");
+            print_r($expected_outbox);
+            echo("
"); + echo("
"); + } +?> + + + + + +
+

Sandbox

+
+
+ + + + + + + +
+
+
+ + + Program Steps: "); + foreach($step_boxes as $step){ echo("$step, "); }; + echo(""); + } + + ?> +
+
+
Initialisiere CPU...
+
+
+ + +
+
+

Formatierter Programm-Code

+
Laden...
+
+
+ + + + + + + + + + + + diff --git a/hrm/stylesheet.css b/hrm/stylesheet.css new file mode 100755 index 0000000..1f23f06 --- /dev/null +++ b/hrm/stylesheet.css @@ -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; +} + diff --git a/index.php b/index.php new file mode 100755 index 0000000..436f0d4 --- /dev/null +++ b/index.php @@ -0,0 +1,132 @@ + + + +"); + $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\"
"); +if(is_callable($level_description)) { // The function exists + $parameters_valid = true; + list($title, $description, $example, $criteria, $passcode) = $level_description(); +} +else{ + $parameters_valid = false; + $passcode = ""; +} +?> + + +<? echo("$GC_ID: $GC_NAME"); ?> + + + + + + + + + + + + + +
+
+

- Willkommen

+ Willkommen im Rechenzentrum des Verwaltungssitzes von Geotanien.
+ 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.

+ + 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...

+ + Um genau zu sein, wir brauchen dringenst deine Hilfe!
+ Kannst Du als Ersatz für die CPU einspringen?
+ 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!

+ + Es ist eigentlich ganz einfach: +
    +
  • Auf der linken Seite hast Du eine Inbox, welche Boxen mit Zahlen enthält,
  • +
  • Auf der rechten Seite hast Du eine Outbox, in welche die verarbeiteten Boxen abgelegt werden sollen,
  • +
  • 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 COPYFROM 0 ausführen.
  • +
  • In deiner Hand kannst du auch jeweils eine Box halten,
  • +
  • Weitere Erläuterungen findest Du in der Hilfe.
  • +
+ +

+ + 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.
+ + Die dafür benötigten Befehle sind in der Hilfe erläutert.

+ + + +
Hmm, dein Browser unterstützt leider kein lokales speichern. D.h., Du musst selber dafür sorgen, dass Du dein Programm zwischenspeicherst, befor Du es ausführst!
+ +
+ 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. + Nicht korrekt funktioniert hat es mit dem Internet Explorer und Opera! +

+ + Alles klar?
+ Dann begib dich bitte zu deiner ersten Aufgabe.

+ +
+ Oder springe direkt zum Level + Passcode: + +
+ + +
+

+ + + + + + + +
+ + + + + + diff --git a/levels.php b/levels.php new file mode 100755 index 0000000..599f799 --- /dev/null +++ b/levels.php @@ -0,0 +1,557 @@ + 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.
" . + "Schreibe ein Programm, welches das für dich macht!
" . + "Du brauchst dazu nur die Befehle INBOX, OUTBOX, " . + "JUMP sowie das dazu passende Ziel <ZIEL>:.
" . + "Du hast 4 Daten-Register zur Verfügung (nummeriert von 0 bis 3), brauchst aber eigentlich keins.
" . + "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) . "
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!
Du darfst zum nächsten Level 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.
" . + "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) . "
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!
Du darfst zum nächsten Level 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.
" . + "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!
Du darfst zum nächsten Level 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.
+ Eine Zahlen-Gruppe enthält mindestens eine Zahlen-Box und eine Terminator-Box.
" . + "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!
Du darfst zum nächsten Level 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!
+ Der Funkspruch ist so aufgebaut, dass immer mindestens eine Box verworfen werden muss.
". + "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!
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; +} + + +?>