1

I need to create an experiment that creates a foil, or a similar stimulus that has a constant change. In my case, I need to take the output from a Self-Avoiding Walk Algorithm 5x5 matrix and move two cells of this path in a way that does not "break" the walking path or create dead ends. In the image below, I would like to keep [0][0] unchanged as entering path, and then [1][0] would remain unchanged as it would break the path, [2][0] would remain unchanged to avoid making [3][0] a dead end, but then [3][0] could be moved to (2)(1) and (3)(2) could be changed to (4)(1)

Any pointers to how I could solve this problem?

Here is the JS Fiddle with generating this matrix: http://jsfiddle.net/eg86hkm7/1/

Original Matrix with proposed changes

Result - Foil with 2 block changes that keep the path continuous and without dead ends

// Adding this code just because SO makes me do it to post a JSFiddle
Lucas Rodrigues
  • 1,234
  • 2
  • 11
  • 22
  • 1
    Anytime the path makes a right angle, you can shift the corner to the inside to make a zig zag, as in [3][0]->[2][1] in your example. The end of the path can also be shifted. – toastifer Dec 27 '22 at 16:06
  • Thank you, any suggestion on how to detect that in code? – Lucas Rodrigues Dec 27 '22 at 16:31
  • What is now your exact question? the code in the link gave the path but what and when do you need your "foil". Only (sensible) comment I can make is that when in a square of 4 you have 3 red, you can make a "foil" by flipping the black to opposite. – Aldert Dec 27 '22 at 16:34
  • For each cell on the path, compare the coordinates for the next and previous cell in the path. If both the x and y are different, then the path has made a turn. – toastifer Dec 27 '22 at 16:45
  • Thank you, this might solve it for me. I'll check what to do with the last item as one of my criteria was for the path to reach the bottom – Lucas Rodrigues Dec 27 '22 at 18:56

0 Answers0