diff --git a/gridGame/src/features/gridGame/gridGameSlice.js b/gridGame/src/features/gridGame/gridGameSlice.js index 6d43053a319e804ebbaaf7427319929ae2673d42..b3467cbe8f9e943bd9c17cbee6d1efc1af0d2d30 100644 --- a/gridGame/src/features/gridGame/gridGameSlice.js +++ b/gridGame/src/features/gridGame/gridGameSlice.js @@ -89,9 +89,26 @@ class Vertex { const incidences = []; for (const direction of DIRECTIONS) { - const child = this.getChild(direction); - incidences.push({ vertex: child, - action: direction }); + const child = new Vertex(this.toString()); + + 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;