2

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

我想知道是否有办法使边界线变粗或仅更改补丁一侧的颜色。

我想只放一个特工进去,通过奖励他一些积分让他找到出口。(Q-学习算法)

有人有想法吗?

如果这是不可能的,你能建议类似的代码吗?

这是我要创建的示例:

替代文字

如被问及,我已经发布了一些我的工作(尽管手动完成这项工作似乎效率低下)。这是我到目前为止所拥有的:

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 个,以便我可以进入我的代理并居中?

先感谢您。

4

2 回答 2

2

要突出显示补丁的边缘,您需要使用海龟。制作一个只由一条线组成的海龟形状,然后创建一个具有该形状的海龟并相应地定位它。您可能想要使用不同品种的海龟(例如称它们为“墙”)。

一旦你创建了海龟,你可以保留它,如果你以后想对它做点什么,或者你可以让它“戳死”来杀死它,但首先让它在绘图中留下自己的图像.

于 2010-04-01T15:13:27.307 回答
1

尝试查看这个迷宫制造者 netlogo 模型中的代码。该算法的基本思想是使用一个随机步行者,在他行走时建造墙壁(路径)。当他到达死胡同时,他会被传送到之前转弯的地方。

玩得开心!如果您想深入研究,当然有一个关于迷宫生成算法的维基百科条目。

于 2010-03-10T20:35:08.680 回答