| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -1140,7 +1140,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 +1189,49 @@ 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, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					              neighs: neigh.neighbours, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            }); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          } | 
					 | 
					 | 
					 | 
					          } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      } | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      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 + 18) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            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) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |