Skip to content
Snippets Groups Projects
Commit 1ef2c882 authored by jguzman12's avatar jguzman12
Browse files

had to rewrite the incidences function because none of the test passed but...

had to rewrite the incidences function because none of the test passed but finally got it to be able to use what is needed and pass all the tests
parent 1db336d6
No related branches found
No related tags found
No related merge requests found
...@@ -89,9 +89,26 @@ class Vertex { ...@@ -89,9 +89,26 @@ class Vertex {
const incidences = []; const incidences = [];
for (const direction of DIRECTIONS) { for (const direction of DIRECTIONS) {
const child = this.getChild(direction); const child = new Vertex(this.toString());
incidences.push({ vertex: child,
action: direction }); let moved = false;
let somethingMoved = true;
while (somethingMoved) {
somethingMoved = false;
for (const [row, column] of this.getLocationsOf(PAWN)) {
const newLocation = shift([row, column], direction);
if (child.get(newLocation) === FLOOR) {
child.set([row, column], FLOOR);
child.set(newLocation, PAWN);
moved = true;
somethingMoved = true;
}
}
}
if (moved) {
incidences.push({ action: direction,
child });
}
} }
return incidences; return incidences;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment