-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolverWorker.js
More file actions
23 lines (21 loc) · 948 Bytes
/
solverWorker.js
File metadata and controls
23 lines (21 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
importScripts('board.js', 'cages.js', 'constants.js', 'error.js', 'legalityChecker.js', 'pawnCaptures.js',
'piece.js', 'pseudoLegalityChecker.js', 'solver.js', 'undo.js');
let undoStack = new UndoStack();
onmessage = function (e) {
const solveParameters = e.data[0];
board = e.data[1];
currentRetract = e.data[2];
positionData = new PositionData();
positionData.initializeDataFromBoard(false); // solver assumes position is legal
positionData.ep = e.data[3];
getPawnCaptureCache().set(e.data[4]);
knownCages = e.data[5];
getPawnCaptureConfig().set(e.data[6]);
undoStack.reset();
const startTime = Date.now();
const result = solve(solveParameters);
const stopTime = Date.now();
const timeInSeconds = (stopTime - startTime) / 1000;
const maybeTruncated = result.length == solveParameters.maxSolutions;
postMessage([result, getPawnCaptureCache(), maybeTruncated, timeInSeconds]);
}