analyzer playback

This commit is contained in:
方而静 2024-01-20 21:10:12 +08:00
parent d10dbc57b9
commit 85e3b0e934
Signed by: szTom
GPG Key ID: 072D999D60C6473C
4 changed files with 475 additions and 36 deletions

View File

@ -1,7 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Visual Pushbox 2024</title>
<link rel="stylesheet" href="normalize.css" />
</head>
<body>
@ -14,27 +17,32 @@
</div>
<div id="control-panel">
<div class="ctrl-title">Analyzer</div>
<table class="full-width info-table"><tbody>
<tr><td>Analyze Status:</td><td id="analyze-status" class="text-right">Not Analyzed</td></tr>
<table class="full-width info-table"><tbody><tr>
<td><table class="info-table full-width" id="analyze-info-table"><tbody>
<tr><td>Status:</td><td id="analyze-status" class="text-right">Not Analyzed</td></tr>
<tr><td>Total Steps:</td><td id="analyze-steps" class="text-right">N/A</td></tr>
</tbody></table>
<div class="btn-group full-width top-margin">
<button id="analyze" class="btn float-left full-width">Analyze</button>
</div>
</tbody></table></td>
<td><button id="analyze" class="">Analyze</button></td>
</tr></tbody></table>
<div class="ctrl-title top-margin">Playback</div>
<div id="progress-indicator">
<div id="progress-value" class="float-left">415 / 1618</div>
<div id="progress-left" class="float-right">-1203</div>
</div>
<div id="progress-bar" class="full-width top-margin">
<table class="full-width info-table"><tbody>
<tr>
<td id="progress-value"><span id="current-progress">0</span>/<span id="full-progress">0</span></td>
<td id="progress-remain" class="text-right">-0</td>
</tr>
</tbody></table>
<div id="progress-bar" class="full-width">
<div id="progress-bar-fg" class="full-height"></div>
</div>
<div class="ctrl-title top-margin">Import / Export</div>
<textarea autocomplete="off" spellcheck="false" id="maze_charmap"></textarea>
<div id="charmap_controls" class="btn-group full-width top-margin">
<button id="charmap_import" class="btn float-left">Import</button>
<button id="charmap_export" class="btn float-right">Export</button>
<div id="progress-controls" class="full-width">
<a href="javascript:void(0)" class="abtn" id="progressctl-prev">Prev</a>
<a href="javascript:void(0)" class="abtn" id="progressctl-next">Next</a>
<a href="javascript:void(0)" class="abtn" id="progressctl-auto">Play</a>
<a href="javascript:void(0)" class="abtn" id="progressctl-reset">Reset</a>
</div>
<div class="ctrl-title top-margin">Edit</div>
<textarea autocomplete="off" spellcheck="false" id="maze-charmap"></textarea>
<button id="charmap_import" class="btn full-width top-margin">Import</button>
</div>
</main>
</body>
@ -43,13 +51,26 @@
<style>
#analyze-info-table {
width: 215px;
}
#analyze {
height: 38px;
width: 75px;
float: right;
}
html {
background-color: #f6f6c6;
}
#progress-bar {
background-color: lightgrey;
height: 10px;
}
#progress-bar-fg {
width: 30%;
background-color: orange;
}
@ -95,6 +116,7 @@ textarea {
resize: none;
outline: none;
border-radius: 0px;
border: none;
}
.ctrl-title {
@ -124,23 +146,21 @@ textarea {
}
.float-left {
display: inline-block;
float: left;
}
.float-right {
display: inline-block;
float: right;
}
#maze_charmap {
width: calc(100% - 2px);
height: 298px;
#maze-charmap {
width: calc(100%);
height: 300px;
display: block;
margin: 0;
padding: 0;
overflow: hidden;
font-size: 13.33px;
font-size: 13px;
font-family: monospace;
}
@ -149,7 +169,6 @@ textarea {
height: 80vh;
border: 1px solid black;
padding: 0;
display: inline-block;
float: left;
position: relative;
}
@ -174,7 +193,7 @@ textarea {
.maze-mv {
z-index: 10;
transition: top 0.2s, left 0.2s;
/* transition: top 0.2s, left 0.2s; */
}
.sqr-wall {

View File

@ -67,20 +67,64 @@ class BoardUI {
}
};
function fillTemplate(id, val) {
document.getElementById(id).innerHTML = val.toString();
}
function updateProgressBar(p) {
document.getElementById('progress-bar-fg').style.width = `${p}%`;
}
document.addEventListener('DOMContentLoaded', () => {
const charmap_input = document.getElementById('maze_charmap');
const charmap_input = document.getElementById('maze-charmap');
const analyze_button = document.getElementById('analyze');
const analyze_status_element = document.getElementById('analyze-status');
let board = new BoardUI();
let maze = null, analyze_res = null;
let maze = null, analyze_res = null, current_progress = 0;
let autoplay_timer = null;
let current_worker = null;
function stopAutplay() {
if (autoplay_timer != null) {
clearInterval(autoplay_timer);
autoplay_timer = null;
fillTemplate('progressctl-auto', 'Play');
}
}
function resetAnalyze() {
document.getElementById('analyze-status').innerHTML = 'Not Analyzed';
document.getElementById('analyze-steps').innerHTML = 'N/A';
stopAutplay();
analyze_status_element.innerHTML = 'Not Analyzed';
fillTemplate('analyze-steps', 'N/A');
fillTemplate('current-progress', '0');
fillTemplate('full-progress', '0');
fillTemplate('progress-remain', '-0');
updateProgressBar(0);
current_progress = 0;
analyze_res = null;
}
function moveProgress(d) {
if (analyze_res == null || analyze_res.step == -1) {
return;
}
current_progress += d;
if (current_progress < 0) {
current_progress = 0;
}
if (current_progress > analyze_res) {
current_progress = analyze_res.step;
}
let st = analyze_res.path[current_progress];
board.updateState(st);
fillTemplate('current-progress', current_progress.toString());
fillTemplate('progress-remain', `-${analyze_res.step - current_progress}`);
updateProgressBar(current_progress * 100 / analyze_res.step);
}
function importMaze(charmap_val) {
let charmp = charmap_val.split('\n').map(x => x.trimEnd());
maze = Maze.fromCharMap(charmp);
@ -102,6 +146,34 @@ document.addEventListener('DOMContentLoaded', () => {
importMaze(charmap_input.value);
});
document.getElementById('progressctl-next').addEventListener('click', function() {
moveProgress(1);
});
document.getElementById('progressctl-prev').addEventListener('click', function() {
moveProgress(-1);
});
document.getElementById('progressctl-auto').addEventListener('click', function() {
if (autoplay_timer == null) {
autoplay_timer = setInterval(() => {
if (current_progress == analyze_res.step) {
stopAutplay();
return;
}
moveProgress(1);
}, 500);
fillTemplate('progressctl-auto', 'Pause');
} else {
stopAutplay();
}
});
document.getElementById('progressctl-reset').addEventListener('click', function() {
stopAutplay();
moveProgress(-current_progress);
});
analyze_button.addEventListener('click', function() {
resetAnalyze();
if (current_worker != null) {
@ -121,15 +193,16 @@ document.addEventListener('DOMContentLoaded', () => {
current_worker.onmessage = (msg_r) => {
let msg = msg_r.data;
if (msg.what === 'started') {
analyze_status_element.innerHTML = 'Running';
analyze_status_element.innerHTML = 'Analyzing';
} else if (msg.what == 'done') {
analyze_res = msg.value;
console.log(analyze_res);
analyze_status_element.innerHTML = 'Done';
document.getElementById('analyze-steps').innerHTML = analyze_res.step.toString();
current_worker.terminate();
current_worker = null;
analyze_button.innerHTML = 'Analyze';
analyze_status_element.innerHTML = 'Analyze Done';
fillTemplate('full-progress', analyze_res.step);
fillTemplate('analyze-steps', analyze_res.step);
fillTemplate('progress-remain', `-${analyze_res.step}`);
}
};
current_worker.postMessage(maze);

349
analyzer/normalize.css vendored Normal file
View File

@ -0,0 +1,349 @@
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}

View File

@ -167,7 +167,6 @@ export class AnalyzeContext {
while (q.size()) {
let x = q.front();
q.pop();
console.log(x.toString());
let dis = this.dis[x.asHash()];
if (x.box.equals(this.maze.target) && this.step == -1) {
@ -184,7 +183,6 @@ export class AnalyzeContext {
let yh = y.asHash();
if (y.isValidInMaze(this.maze) && this.dis[yh] == -1) {
console.log(y.toString());
this.dis[yh] = dis + 1;
this.source[yh] = x.clone();
q.push(y);