Compare commits

...

2 Commits

  1. 50
      script.js

@ -742,8 +742,9 @@ class SettingsStorage {
version: 1,
log: 'info',
allowTemplateAugmenting: false,
retryTemplate: 30,
attemptTemplates: 50,
retryTemplate: 120,
attemptTemplates: 20,
difficulty: 35,
svgEffects: false,
dimBlocked: true,
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) {
@ -1183,31 +1190,48 @@ class Game {
this.board.grid[n] = null;
};
const findAvailableIndexWithNeighbours = (count, except = null) => {
const findBestCandidate = (except = null) => {
let candidates = [];
for (let n of template) {
if (except && except.includes(n)) continue;
if (!this.board.grid[n]) {
// is free
const neigh = this.getNeighbours(n);
if (neigh.neighbours === count && neigh.freeSequence >= 3) {
candidates.push(n);
if (neigh.freeSequence >= 3) {
candidates.push({
n,
cw: neigh.centerWeight
});
}
}
}
candidates.sort((a, b) => a.cw - b.cw);
if (candidates.length) {
return this.arrayChoose(candidates)
} else {
return false;
// return candidates[0].n;
let top = [];
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) => {
for (let i = 6; i >= 0; i--) {
const n = findAvailableIndexWithNeighbours(i, except);
if (n !== false) return n;
}
const n = findBestCandidate(except);
if (n !== false) return n;
// this corrupts the template, but makes the likelihood of quickly finding a valid solution much higher.
if (template.length !== BOARD_SIZE && this.cfg.allowTemplateAugmenting) {

Loading…
Cancel
Save