元胞自动机(Cellular Automata)是一种局部计算范式,其复杂行为源于简单函数之间的局部交互。该范式已被用于解释诸多系统,例如生物过程、交通仿真、计算机网络等。在游戏领域,元胞自动机曾应用于《模拟城市》(SimCity)等游戏,并用于生成洞穴或地牢等空间内容。然而,设计有效的局部规则困难且缺乏直观性;尽管元胞自动机可通过演化方法有效构造,但其结果仍可能难以解释。本文提出可编程元胞自动机(Programmable Cellular Automata)的概念,将系统表示为 Python 代码,并将其模块化为局部函数(local functions)与决策函数(decision function):局部函数接收局部邻域并返回一个值,决策函数则接收所有局部函数的输出并决定下一状态的取值。将元胞自动机拆分为以 Python 编写的模块,有助于理解系统运行机制。我们还探索引入全局函数(global functions),即以整个系统状态为输入并从中计算出某函数值。我们在 PCG Benchmark 中三个不同游戏的关卡生成任务上进行了测试。结果表明,引入全局函数可减少元胞自动机求解问题所需的迭代次数;而仅使用局部函数时,某些问题无法找到可行解。进一步分析所生成的函数,我们发现若干在不同实验中反复出现的通用函数,这不仅有助于理解生成器本身,亦有助于深入理解这些游戏及其关键要素。
Cellular automata is a local computation paradigm where complex behavior can arise from local interactions between simple functions. This paradigm has been used to explain many systems such as biological processes, traffic simulation, computer networks, etc. In games, cellular automata have been used in games such as SimCity and for the generation of spatial content such as caves or dungeons. However, creating effective local rules is hard and unintuitive. Cellular automata can be effectively evolved, but may still be hard to interpret. In this work, we introduce the concept of programmable cellular automata, where we represent the system as Python code. We also modularize the cellular automata into local functions and a decision function. Local functions take a local neighborhood and return a value, while the decision function takes the output of the local functions and decides the value of the next state. Separating the cellular automata into modules written in Python helps with understanding how these systems are working. We also explore adding global functions where they take the whole state and compute a function from it. We tested generating levels for three different games from the PCG Benchmark. The results showed that global functions decrease the number of iterations that cellular automata need to solve a problem, and that we cannot find solutions for some problems with purely local functions. Looking into the generated functions, we can see common functions that have been used in different experiments, which not only helps us understand the generator but also helps us understand these games better and what is important for them.