Skip to content

Instantly share code, notes, and snippets.

@timini
Created June 26, 2018 14:58
Show Gist options
  • Save timini/b9519d93e0c637288127618b711a7478 to your computer and use it in GitHub Desktop.
Save timini/b9519d93e0c637288127618b711a7478 to your computer and use it in GitHub Desktop.
const nodes = [];
const adjMatrix = {};
function breakPieces (shape){
shape = shape.split('\n');
let height = shape.length;
let width = shape[0].length;
// create a list with the co-ordinates of each '+'
for (let i=0; i < height; i++) {
for (let j=0; j < width; j++) {
if (shape[i][j] === '+') {
nodes.push({ x: i, y: j });
}
}
}
// create a blank adjancy matrix (all elements set to 0)
for (let i=0; i < height; i++) {
let row = {};
for (let j=0; j < width; j++) {
row[j] = 0;
}
adjMatrix[i] = row;
}
console.log(adjMatrix);
for (let i=0; i < nodes.length; i++) {
const { x, y } = nodes[i];
// check for nodes to the north
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment