Compare commits

...

2 Commits

  1. 50
      script.js

@ -742,8 +742,9 @@ class SettingsStorage {
version: 1, version: 1,
log: 'info', log: 'info',
allowTemplateAugmenting: false, allowTemplateAugmenting: false,
retryTemplate: 30, retryTemplate: 120,
attemptTemplates: 50, attemptTemplates: 20,
difficulty: 35,
svgEffects: false, svgEffects: false,
dimBlocked: true, dimBlocked: true,
logSolution: false, logSolution: false,
@ -1140,7 +1141,13 @@ class Game {
} }
} }
return {neighbours: nOccupied, freeSequence: maxFreeSequence}; let { rx, ry } = this.board.gridXyToCoord(x, y);
return {
neighbours: nOccupied,
freeSequence: maxFreeSequence,
centerWeight: Math.round(Math.sqrt(Math.pow(rx, 2) + Math.pow(ry, 2))),
};
} }
placeOrbs(template) { placeOrbs(template) {
@ -1183,31 +1190,48 @@ class Game {
this.board.grid[n] = null; this.board.grid[n] = null;
}; };
const findAvailableIndexWithNeighbours = (count, except = null) => { const findBestCandidate = (except = null) => {
let candidates = []; let candidates = [];
for (let n of template) { for (let n of template) {
if (except && except.includes(n)) continue; if (except && except.includes(n)) continue;
if (!this.board.grid[n]) { if (!this.board.grid[n]) {
// is free
const neigh = this.getNeighbours(n); const neigh = this.getNeighbours(n);
if (neigh.neighbours === count && neigh.freeSequence >= 3) { if (neigh.freeSequence >= 3) {
candidates.push(n); candidates.push({
n,
cw: neigh.centerWeight
});
} }
} }
} }
candidates.sort((a, b) => a.cw - b.cw);
if (candidates.length) { if (candidates.length) {
return this.arrayChoose(candidates) // return candidates[0].n;
} else { let top = [];
return false; let topw = candidates[0].cw;
for(let cand of candidates) {
if (cand.cw <= topw + this.cfg.difficulty) { // TODO this could vary by template
top.push(cand);
}
}
//the neighbor count is not used for anything anymore, oops
// console.log('Got a choice of '+top.length+' tiles');
return this.arrayChoose(top).n;
} }
return false;
}; };
const findAvailableIndex = (except = null) => { const findAvailableIndex = (except = null) => {
for (let i = 6; i >= 0; i--) { const n = findBestCandidate(except);
const n = findAvailableIndexWithNeighbours(i, except); if (n !== false) return n;
if (n !== false) return n;
}
// this corrupts the template, but makes the likelihood of quickly finding a valid solution much higher. // this corrupts the template, but makes the likelihood of quickly finding a valid solution much higher.
if (template.length !== BOARD_SIZE && this.cfg.allowTemplateAugmenting) { if (template.length !== BOARD_SIZE && this.cfg.allowTemplateAugmenting) {

Loading…
Cancel
Save