I am trying to create a 5x5 grid with 2 exits and put some walls in it. In other words, I want to create a maze or a labyrinth.
I was wondering if there is a way to make a border line thicker or change the colour of only one side of a patch.
I want to put only one agent inside and let him find the exit by rewarding him with some points. (Q-learning algorithm)
Does anyone have an idea?
If this is not possible can you suggest comparable code please?
Here is an example of what I want to create:
As asked, I've posted some of my work (although it seems inefficient to have done this manually). Here is what I have so far:
breed [frame frames]
to setup
ca
ask patches [ set pcolor white]
ask patch -7 8 [ set pcolor black]
ask patch -6 8 [ set pcolor black]
ask patch -5 8 [ set pcolor black]
ask patch -4 8 [ set pcolor black]
ask patch -3 8 [ set pcolor black]
ask patch -2 8 [ set pcolor black]
ask patch -1 8 [ set pcolor black]
ask patch 1 8 [ set pcolor black]
ask patch 0 8 [ set pcolor black]
ask patch 2 8 [ set pcolor black]
ask patch 3 8 [ set pcolor black]
ask patch 6 8 [ set pcolor black]
ask patch 7 8 [ set pcolor black]
ask patch 8 8 [ set pcolor black]
ask patch -7 7 [ set pcolor black]
ask patch -7 6 [ set pcolor black]
ask patch -7 5 [ set pcolor black]
ask patch -7 4 [ set pcolor black]
ask patch -7 3 [ set pcolor black]
ask patch -7 2 [ set pcolor black]
ask patch -7 1 [ set pcolor black]
ask patch -7 0 [ set pcolor black]
ask patch -7 -1 [ set pcolor black]
ask patch -7 -2 [ set pcolor black]
ask patch -7 -3 [ set pcolor black]
ask patch -7 -4 [ set pcolor black]
ask patch -7 -5 [ set pcolor black]
ask patch -7 -6 [ set pcolor black]
ask patch -7 -7 [ set pcolor black]
ask patch -7 -7 [ set pcolor black]
ask patch -6 -7 [ set pcolor black]
ask patch -5 -7 [ set pcolor black]
ask patch -4 -7 [ set pcolor black]
ask patch -3 -7 [ set pcolor black]
ask patch -2 -7 [ set pcolor black]
ask patch -1 -7 [ set pcolor black]
ask patch 1 -7 [ set pcolor black]
ask patch 0 -7 [ set pcolor black]
ask patch 2 -7 [ set pcolor black]
ask patch 3 -7 [ set pcolor black]
ask patch 4 -7 [ set pcolor black]
ask patch 5 -7 [ set pcolor black]
ask patch 8 -7 [ set pcolor black]
ask patch 8 8 [ set pcolor black]
ask patch 8 7 [ set pcolor black]
ask patch 8 6 [ set pcolor black]
ask patch 8 5 [ set pcolor black]
ask patch 8 4 [ set pcolor black]
ask patch 8 3 [ set pcolor black]
ask patch 8 2 [ set pcolor black]
ask patch 8 1 [ set pcolor black]
ask patch 8 0 [ set pcolor black]
ask patch 8 -1 [ set pcolor black]
ask patch 8 -2 [ set pcolor black]
ask patch 8 -3 [ set pcolor black]
ask patch 8 -4 [ set pcolor black]
ask patch 8 -5 [ set pcolor black]
ask patch 8 -6 [ set pcolor black]
ask patch -6 5 [ set pcolor black]
ask patch -5 5 [ set pcolor black]
ask patch -4 5 [ set pcolor black]
ask patch -4 4 [ set pcolor black]
ask patch -4 3 [ set pcolor black]
ask patch -4 2 [ set pcolor black]
ask patch -4 -1 [ set pcolor black]
ask patch -4 -2 [ set pcolor black]
ask patch -4 -3 [ set pcolor black]
ask patch -4 -4 [ set pcolor black]
ask patch -5 -4 [ set pcolor black]
ask patch -6 -4 [ set pcolor black]
ask patch -1 7 [ set pcolor black]
ask patch -1 6 [ set pcolor black]
ask patch -1 5 [ set pcolor black]
ask patch -1 4 [ set pcolor black]
ask patch -1 3 [ set pcolor black]
ask patch -1 2 [ set pcolor black]
ask patch 2 5 [ set pcolor black]
ask patch 2 4 [ set pcolor black]
ask patch 2 3 [ set pcolor black]
ask patch 2 2 [ set pcolor black]
ask patch 5 5 [ set pcolor black]
ask patch 5 4 [ set pcolor black]
ask patch 5 3 [ set pcolor black]
ask patch 5 2 [ set pcolor black]
ask patch 5 1 [ set pcolor black]
ask patch 5 0 [ set pcolor black]
ask patch 5 -1 [ set pcolor black]
ask patch 6 5 [ set pcolor black]
ask patch 7 5 [ set pcolor black]
ask patch -1 -1 [ set pcolor black]
ask patch 0 -1 [ set pcolor black]
ask patch 1 -1 [ set pcolor black]
ask patch 2 -1 [ set pcolor black]
ask patch 3 -1 [ set pcolor black]
ask patch 4 -1 [ set pcolor black]
ask patch -1 -2 [ set pcolor black]
ask patch -1 -3 [ set pcolor black]
ask patch -1 -4 [ set pcolor black]
ask patch 0 -4 [ set pcolor black]
ask patch 1 -4 [ set pcolor black]
ask patch 2 -4 [ set pcolor black]
ask patch 3 -4 [ set pcolor black]
ask patch 4 -4 [ set pcolor black]
ask patch 5 -4 [ set pcolor black]
end
Again, this is an inefficient method. If I were to continue with this method, how can I merge 4 patche开发者_StackOverflow社区s into 1 so that I can enter my agent inside and be centered?
Thank you in advance.
To highlight the edge of a patch, you'll need to use a turtle. Make a turtle shape that just consists of a line, then create a turtle with that shape and position it accordingly. You'll probably want to use a separate breed of turtles (call them "walls", say).
Once you've created the turtle, you can either keep it around if you want to do something with it later, or you can have it do "stamp die" to kill it but first have it leave an image of itself behind in the drawing.
Try looking at the code in this maze-maker netlogo model. The basic idea for the algorithm is to use a random walker that builds walls (path) as he walks. When he reaches a dead end he is teleported to a previous place where he took a turn.
Have fun! There is, of course a wikipedia entry on maze generation algorithms if you want to delve deeper.
精彩评论