English 中文(简体)
How to create maze walls in NetLogo?
原标题:

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:

alt text

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 patches 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.





相关问题
What is the iPad user agent?

From what I gather, the iPad is using iPhone OS, but with a different screen resolution from the iPhone and iPod touch. So many sites may have to change their user agent detection to adapt to the iPad....

Code to parse user agent string?

As strange as I find this, I have not been able to find a good PHP function anywhere which will do an intelligent parse of a user agent string? Googled it for about 20 minutes now. I have the string ...

How can i remove chromeframe from IE8 User Agent?

I removed Chrome Frame from my system but IE8 User Agent still has chromeframe in it. How can I remove Chrome Frame entirely? Can I somehow reset all IE8 settings or is my only choice somekind of User-...

Activate <div> based on User Agent

I need to activate a "div" based on the user agent string. For example, (and this is my actual use for this,) A user with Firefox comes to my site. I want to tell them something along the lines of "...

How to set User-Agent in python-twitter?

i m writing a small script to tweet messages from the monitoring systems. The only issue i ran into so far is that i can t set the User-Agent correctly, all tweets show up as "from API" which ain t a ...

What does default CSS s browsers depend on?

Hi (please excuse me for my ugly english ;-) ) Do you know if the default CSS of any user agent ... : depends on its release number ? depends on its layout engine ? depends on the release number of ...

热门标签