matrix-map
Version:
A class object for to aid in the creation of 2D grid games.
39 lines (25 loc) • 805 B
JavaScript
const getChainFromID = function(id){
let toBeDestroyed = new Set();
let alreadyChecked = new Set()
let playChain = (pos) => {
let targetID = pos;
let loopSet = new Set()
alreadyChecked.add(targetID)
toBeDestroyed.add(targetID);
let targetNeighbors = this.getEquivalentNeighbors(targetID)
for (const [key, value] of targetNeighbors) {
if(targetNeighbors.get(key) === this.map.get(targetID)){
loopSet.add(key)
}
}
loopSet.forEach((item)=>{
if(!alreadyChecked.has(item)){
playChain(item)
}
})
}
playChain(id);
// console.log('TBD', toBeDestroyed.size);
return toBeDestroyed;
}
export default getChainFromID