Commit ddf1fee2 authored by Florent Becker's avatar Florent Becker

Check the feasability of OnTAS simulation

parent 60132add
...@@ -987,6 +987,23 @@ export class Simulator { ...@@ -987,6 +987,23 @@ export class Simulator {
Logger.log(Logger.INFO, `saved current assembly as SVG file ${fileName}`); Logger.log(Logger.INFO, `saved current assembly as SVG file ${fileName}`);
} }
currentAssemblyContainsTwoTwoSquare() {
let two_by_two_found = false;
let atlas = this.tileBlockAtlas;
console.log(atlas);
for (const tile of atlas.getAllTiles()) {
const x = tile.coords.x;
const y = tile.coords.y;
if (atlas.getTileAtLocation(new Vector2D(x+1, y))&&
atlas.getTileAtLocation(new Vector2D(x+1, y+1)) &&
atlas.getTileAtLocation(new Vector2D(x, y+1))) {
two_by_two_found = true;
break;
}
}
return two_by_two_found;
}
} }
// TOUCH EVENTS // TOUCH EVENTS
......
...@@ -260,6 +260,12 @@ async function onOnTASSimButton() { ...@@ -260,6 +260,12 @@ async function onOnTASSimButton() {
let tdpContents, tdsContents; let tdpContents, tdsContents;
let n_tiles = simulator.tileset.tileTypes.length;
if (n_tiles > 3000) {
alert('The current system has ' + n_tiles + ' tile types.\nBecause of limitations of the web simulator, the OnTAS simulation can only be run on tileset with at most 3000 tile types, sorry.');
return;
}
if (blobs === null) { if (blobs === null) {
alert('No system to convert to the OnTAS. Please open a system before doing that'); alert('No system to convert to the OnTAS. Please open a system before doing that');
return; return;
...@@ -267,35 +273,35 @@ async function onOnTASSimButton() { ...@@ -267,35 +273,35 @@ async function onOnTASSimButton() {
tdpContents = await blobs[0].text(); tdpContents = await blobs[0].text();
tdsContents = await blobs[1].text(); tdsContents = await blobs[1].text();
} }
let myWorker = new Worker(new URL("src/ontasWorker.js", window.location.href).href, { type: "module"});
console.log("let's go"); let current_assembly_size = tdpContents.split('\n').length - 2;
if (current_assembly_size > 3000) {
alert('The current assembly has ' + current_assembly_size + ' tiles.\nBecause of limitations of the web simulator, the OnTAS simulation can only be run on assemblies with at most 3000 tiles, sorry.')
}
if (!simulator.currentAssemblyContainsTwoTwoSquare()) {
alert('The current assembly does not contain a 2×2 square, so it cannot be used as the simulated seed in the simulation. Try stepping a few times until it does.\nOnly Theorem 8 (the 5×5 simulation) is implemented, sorry!');
return;
}
let myWorker = new Worker(new URL("src/ontasWorker.js", window.location.href).href, { type: "module"});
myWorker.ready = false; myWorker.ready = false;
myWorker.onmessageerror = (event) => { myWorker.onmessageerror = (event) => {
console.log(error) console.log(error)
}; };
myWorker.onerror = (error) => { myWorker.onerror = (error) => {
console.log(error);
console.error('Error occurred in worker:', error.message); console.error('Error occurred in worker:', error.message);
}; };
myWorker.onmessage = (event) => { myWorker.onmessage = (event) => {
console.log(myWorker.ready)
if (myWorker.ready) { if (myWorker.ready) {
let newTds = new TextDecoder().decode(event.data) let newTds = new TextDecoder().decode(event.data)
console.log(newTds);
LoadAsOnTAS("onTAS_for_" + filename, newTds); LoadAsOnTAS("onTAS_for_" + filename, newTds);
} else { } else {
console.log("worker ready");
console.log(event.data);
myWorker.ready = true; myWorker.ready = true;
let msg = { tds: tdsContents, tdp: tdpContents }; let msg = { tds: tdsContents, tdp: tdpContents };
console.log("lancement calcul");
console.log(msg);
myWorker.postMessage(msg); myWorker.postMessage(msg);
console.log("calcul lancé")
} }
//
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment