-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.js
More file actions
21 lines (20 loc) · 1.1 KB
/
Copy pathworker.js
File metadata and controls
21 lines (20 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
self.onmessage = ({ data }) => {
const { id, board, player, forbidden, difficulty, variety, move, options } = data;
try {
if (data.type === 'move') {
const choice = self.GomokuEngine.chooseMove(board, player, forbidden, difficulty, { variety });
self.postMessage({ type: 'move', id, move: choice });
} else if (data.type === 'analyze') {
const result = self.GomokuEngine.estimateMove(board, move, player, forbidden, difficulty,
(update) => self.postMessage({ type: 'analysis', id, move, result: update, complete: false }), options);
self.postMessage({ type: 'analysis', id, move, result, complete: true });
} else if (data.type === 'heatmap') {
const result = self.GomokuEngine.estimateTopMoves(board, player, forbidden, difficulty,
(update) => self.postMessage({ type: 'heatmap', id, result: update, complete: false }), options);
self.postMessage({ type: 'heatmap', id, result, complete: true });
}
} catch (error) {
self.postMessage({ type: 'error', id, message: error && error.message ? error.message : '计算失败' });
}
};