Created
June 26, 2018 14:58
-
-
Save timini/b9519d93e0c637288127618b711a7478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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