bef runner bug fixes
This commit is contained in:
parent
4f7795c70b
commit
17a81b9fea
@ -623,6 +623,8 @@ html, body {
|
|||||||
padding: 5px 9.5px;
|
padding: 5px 9.5px;
|
||||||
line-height: 12pt;
|
line-height: 12pt;
|
||||||
font-size: 10pt; }
|
font-size: 10pt; }
|
||||||
|
.bce_code .bce_code_data {
|
||||||
|
white-space: pre; }
|
||||||
.bce_code .bce_code_editarea {
|
.bce_code .bce_code_editarea {
|
||||||
display: block;
|
display: block;
|
||||||
resize: none;
|
resize: none;
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bce_code_data { white-space: pre; }
|
||||||
|
|
||||||
.bce_code_editarea {
|
.bce_code_editarea {
|
||||||
display: block;
|
display: block;
|
||||||
resize: none;
|
resize: none;
|
||||||
|
@ -33,7 +33,7 @@ function BefObject(domBase) {
|
|||||||
|
|
||||||
this.state = BefState.INITIAL;
|
this.state = BefState.INITIAL;
|
||||||
this.initial = atob(this.pnlCode.getAttribute('data-b93rnr_code'));
|
this.initial = atob(this.pnlCode.getAttribute('data-b93rnr_code'));
|
||||||
this.simspeed = BefSpeed.get(domBase.hasAttribute('data-b93rnr_initialspeed') ? domBase.getAttribute('data-b93rnr_initialspeed') : '4');
|
this.simspeed = BefSpeed.get(domBase.hasAttribute('data-b93rnr_initialspeed') ? domBase.getAttribute('data-b93rnr_initialspeed') : BefSpeed.SUPERFAST.val);
|
||||||
this.code = [];
|
this.code = [];
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
@ -172,7 +172,7 @@ BefObject.prototype.step = function() {
|
|||||||
|
|
||||||
let t0 = performance.now();
|
let t0 = performance.now();
|
||||||
let stepc = 0;
|
let stepc = 0;
|
||||||
while(this.state=== BefState.RUNNING && (stepc===0 || (performance.now() - t0 < 16)) && stepc < 128) // 16ms == 60FPS
|
while(this.state=== BefState.RUNNING && (stepc===0 || (performance.now() - t0 < 16)) && stepc < 1024) // 16ms == 60FPS
|
||||||
{
|
{
|
||||||
this.stepSingle();
|
this.stepSingle();
|
||||||
stepc++;
|
stepc++;
|
||||||
@ -364,13 +364,16 @@ BefObject.prototype.getDisplayHTML = function() {
|
|||||||
for (let x=0; x < this.width; x++) {
|
for (let x=0; x < this.width; x++) {
|
||||||
let cc = this.code[y][x];
|
let cc = this.code[y][x];
|
||||||
let chr = String.fromCharCode(cc);
|
let chr = String.fromCharCode(cc);
|
||||||
|
|
||||||
if (chr === '&') chr = '&';
|
if (chr === '&') chr = '&';
|
||||||
if (chr === '<') chr = '<';
|
else if (chr === '<') chr = '<';
|
||||||
if (chr === '>') chr = '>';
|
else if (chr === '>') chr = '>';
|
||||||
if (chr === ' ') chr = ' ';
|
else if (cc === 32 ) chr = ' ';
|
||||||
if (cc===0) chr = '<span style="color:#888">0</span>';
|
else if (cc<10 && cc>=0 ) chr = '<span style="background:#BBB;color:#888">'+cc+'</span>';
|
||||||
else if (cc>127 || cc<32) chr = '<span style="background:black;color:#888;">?</span>';
|
else if (cc<32 && cc>=10) chr = '<span style="background:#BBB;color:#888">'+String.fromCharCode(65+cc)+'</span>';
|
||||||
if (x === this.position[0] && y === this.position[1]) chr = '<span style="background: dodgerblue">' + chr + '</span>';
|
else if (cc>127 || cc<0 ) chr = '<span style="background:#BBB;color:#888;">X</span>';
|
||||||
|
|
||||||
|
if (x === this.position[0] && y === this.position[1]) chr = '<span style="background:dodgerblue">' + chr + '</span>';
|
||||||
str += chr;
|
str += chr;
|
||||||
}
|
}
|
||||||
str += '<br/>';
|
str += '<br/>';
|
||||||
@ -400,18 +403,19 @@ BefObject.prototype.updateDisplay = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BefObject.prototype.parseBef = function(str) {
|
BefObject.prototype.parseBef = function(str) {
|
||||||
const lines = str.replace('\r\n', '\n').split('\n').map(function(str){return str.replace(/\s+$/, '')});
|
const lines = str.replace('\r', '').split('\n');
|
||||||
let max = 0;
|
let max = 0;
|
||||||
for (let line of lines) max = Math.max(max, line.length);
|
for (let line of lines) max = Math.max(max, line.length);
|
||||||
|
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
for (let line of lines)
|
for (let _line of lines)
|
||||||
{
|
{
|
||||||
|
let line = _line.replace('\r', '').replace('\n', '');
|
||||||
let row = [];
|
let row = [];
|
||||||
for(let i=0; i < max; i++)
|
for(let i=0; i < max; i++)
|
||||||
{
|
{
|
||||||
row.push((i < line.length ? (line[i]) : ' ').charCodeAt(0));
|
row.push((i < line.length ? (line[i].charCodeAt(0)) : 32));
|
||||||
}
|
}
|
||||||
result.push(row)
|
result.push(row)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ $editable = $PARAM_BEFUNGE93RUNNER['editable'];
|
|||||||
|
|
||||||
function fmtBef($str) {
|
function fmtBef($str) {
|
||||||
$str = htmlspecialchars($str);
|
$str = htmlspecialchars($str);
|
||||||
$str = str_replace("\r\n", "\n", $str);
|
$str = str_replace("\r", "", $str);
|
||||||
$str = join("\n", array_map(function($p){return rtrim($p);}, explode("\n", $str)));
|
$str = join("\n", array_map(function($p){return rtrim($p);}, explode("\n", $str)));
|
||||||
$str = str_replace(' ', ' ', $str);
|
$str = str_replace(' ', ' ', $str);
|
||||||
$str = nl2br($str);
|
$str = nl2br($str);
|
||||||
|
@ -53,7 +53,7 @@ $max = ceil($max / 20) * 20;
|
|||||||
'code' => file_get_contents($problem['file_code']),
|
'code' => file_get_contents($problem['file_code']),
|
||||||
'url' => $problem['url_raw'],
|
'url' => $problem['url_raw'],
|
||||||
'interactive' => !$problem['abbreviated'],
|
'interactive' => !$problem['abbreviated'],
|
||||||
'speed' => null,
|
'speed' => $problem['steps'] < 500000 ? 2 : 3,
|
||||||
'editable' => false,
|
'editable' => false,
|
||||||
];
|
];
|
||||||
echo require (__DIR__ . '/../fragments/befunge93_runner.php');
|
echo require (__DIR__ . '/../fragments/befunge93_runner.php');
|
||||||
@ -73,7 +73,7 @@ $max = ceil($max / 20) * 20;
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>Execution time</b> (<a href="/programs/view/BefunGen">BefunExec</a>):</td>
|
<td><b>Execution time</b> (<a href="/programs/view/BefunGen">BefunExec</a>):</td>
|
||||||
<td><?php echo $problem['time'] . ' ms <i>(=' . (($problem['time']===0) ? '?' : number_format(($problem['steps']/$problem['time'])/1000, 2, '.', '')) . ' MHz)</i>'; ?></td>
|
<td><?php echo formatMilliseconds($problem['time']) . ' <i>(' . (($problem['time']===0) ? '?' : number_format(($problem['steps']/$problem['time'])/1000, 2, '.', '')) . ' MHz)</i>'; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>Program size:</b></td>
|
<td><b>Program size:</b></td>
|
||||||
|
@ -1 +1,2 @@
|
|||||||
The idea here was to first move the numbers into a *real* 20x20 grid where every field represents a single number, the rest was not that hard.
|
The idea here was to first move the numbers into a *real* 20x20 grid where every field represents a single number,
|
||||||
|
the rest was just brute-forcing all possible products and outputting the biggest.
|
Loading…
Reference in New Issue
Block a user