如何在NetLogo中创建迷宫墙?

时间:2010-03-10 18:17:50

标签: user-agent agent maze greedy netlogo

我正在尝试创建一个带有2个出口的5x5网格,并在其中放置一些墙。换句话说,我想创造一个迷宫或迷宫。

我想知道是否有办法让边框线变粗或改变贴片一侧的颜色。

我想只在里面放一个特工,让他通过奖励他一些积分来找到退出。 (Q学习算法)

有没有人有想法?

如果无法做到这一点,您能建议可比的代码吗?

以下是我想要创建的示例:

alt text http://i44.tinypic.com/2hgu1ow.png

据我所知,我已经发布了一些我的工作(尽管手动完成这项工作似乎效率低下)。以下是我到目前为止的情况:

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

同样,这是一种效率低下的方法。如果我继续使用这种方法,我怎样才能将4个补丁合并为1,这样我就可以在里面输入我的代理并居中?

提前谢谢。

2 个答案:

答案 0 :(得分:2)

要突出显示补丁的边缘,您需要使用乌龟。制作一个只包含一条线的乌龟形状,然后创建一个具有该形状的乌龟并相应地定位它。你可能想要使用一种单独的海龟(比如说它们叫“墙”)。

一旦你创造了乌龟,你可以保留它,如果你想稍后用它做什么,或者你可以让它做“踩死”来杀死它但是首先让它留下自己的形象在图纸中。

答案 1 :(得分:1)

尝试查看this maze-maker netlogo model.中的代码。算法的基本思想是使用随机漫步者在他走路时建立墙(路径)。当他走到死路时,他被传送到他转过身的前一个地方。

玩得开心!如果你想深入研究,当然有wikipedia entry on maze generation algorithms