A random map generation algorithm for the game "Civilization"

I am participating in the individual competition of the Nuggets Community Game Creativity Contest. For details, please see: Game Creativity Contest

This paper mainly introduces an algorithm for generating balanced and fair game maps for strategic multiplayer games such as Civilization and Catan by means of procedural modeling (PCG).

Introduction to Symmetry Game

Symmetrical confrontation game means that the resources, interaction methods, restricted rules, and final goals of the players participating in the game are the same or similar, and it is a fair and symmetrical zero-sum game. Such as "Heroes", "Civilization", "Catan" and other games.

We built a multiplayer turn-based strategy game with reference to the 4X elements of civilization [1], as shown in the following figure: The map began to be covered by the "fog of war". Players must send explorers into this fog to reveal lands to expand, resources to develop, and opponents to eliminate.

map balance indicator

We refer to two references [2][3] to formulate a two-point metric for evaluating the balance of symmetrical versus game maps.

1. Strategic Feature

Strategic features refer to the strategic resources that players can utilize in the game. The balance of strategic features refers to the fact that each player obtains substantially the same resources (including types and quantities) within a certain period of time.

The following two figures show the situation where the strategic characteristics of the two players are unbalanced. The blue player can get more mineral resources at the beginning, while the yellow player has almost no mineral resources near the spawn point, which will lead to the development of the yellow player at the beginning of the game. Limited.

2. Player placeholder

The distribution of the player's initial spawn position will also affect the balance of the game.

The two graphs below show a situation where the player's initial placeholder distribution density is different and the gameplay is unbalanced. The initial distribution of players in the left picture is dense, which will lead to players in this area crushing each other in the early game and limited development; while the yellow players in the right picture lack competition in the early game and can better develop their own construction.

In addition to the impact of the above two points on the balance of the game, the random map of the strategic game map should also take into account: the aesthetics of the map, the customization of parameters according to the player's preferences, and the efficiency of map generation.

Map generation process

1. Customize map parameters according to player preferences

Before creating a new game, we will let players customize the map parameters according to their preferences, including the size of the map, the total number of players, the type of the map (Panga, continents, islands), water body proportion, vegetation proportion, rock proportion and resources ratio, etc.

2. 生成地图的轮廓:柏林噪声

柏林噪声(Perlin noise)指由Ken Perlin发明的自然噪声生成算法[4]。在游戏开发领域,柏林噪声可以用于生成波形,起伏不平的材质或者纹理。如下图所示:

与椒盐噪声相比,柏林噪声有较好的连续性分布,可以更好的模拟自然界中的地形分布与地表装饰物分布。利用柏林噪声生成自然地图可以参考:www.bilibili.com/video/BV1sJ…

Unity官方自带生成柏林函数的函数。我们引用了柏林噪声js库来进行地形的实现。我们利用柏林噪声的采样尺度来决定地图的类型是连续的大陆型地图还是离散的大洲型地图;将随机取到的连续噪声均衡化作为地图的高度图,根据用户设置的水体占比来制定海平面高度,最终生成的地形结果如下图所示: 

3. 玩家出生点的选择:米切尔最佳候选算法

为了保证每位玩家两两之间的初始分布不会过近,我们在生成游戏地形后,在陆地上对玩家初始占位符进行均匀采样。为了兼顾效果与效率,我们最终选用米切尔最佳候选 算法(best candidate)。

米切尔最佳候选算法是一种渐进、增量式的均匀采样方法。它每一轮采样都是从多个随机采样点中,保留与之前轮的所有采样点中最小距离最大的点作为本轮的采样结果。如下图所示:黑色点是之前轮已经确定的采样点,灰色点是本轮随机采样的候选点,每个候选点都选出与之前轮采样点中距离最近的距离,再从中选出最小距离最大的红色点作为本轮采样的结果。

利用这种采样方式采样出玩家的初始占位符,可以避免任意两个玩家之间的距离过近导致游戏平衡性被破坏,如下图所示:

4. 战略资源的分布

采样出玩家的分布之后,我们将地图单元格分为两种类型:每个玩家占位符附近距离N以内的单元格为玩家区域(Player Zones),不隶属于任何玩家区域的单元格被称为隔离区或自然区(Natural Zones)。

为了让每名玩家在游戏初始时具有公平的战略特征,我们对每位玩家的玩家区域内定额分配植被、岩石与矿产资源。根据用户设定的植被、岩石与资源占比分别计算出每位玩家区应当分配到的植被、岩石与资源数量,然后在每个玩家区域内不重不漏地采样出相等数量的植被、岩石与资源单元格。

对于自然区,我们按照玩家设置的参数,采用米切尔候选算法均匀采样每一种资源。这样可以保证每位玩家在游戏初始时能够得到数量一致的战略特征。如下图所示:

5. 边界情况处理

用以上方式生成的地图在某些情况下会产生不好的结果,例如当水体比例过低时生成海岛地形,会导致水体不够划分不出海岛地形;当水体比例过高时,会由于陆地单元格分布不均导致出生在不同规模大小的岛屿上的玩家能够得到的战略资源再度失衡。对于这些边界情况,我们利用种子生长与泛洪填充等启发式生成方法生成地图,优先保证地图类型能够满足用户的需求,并尽可能保证水体与各种战略特征的资源逼近用户的设定。以下是我们在水体占比过低与水体占比过高时生成的地图,可以看出在这两种情况下依然能够保证所生成地图的平衡性:

生成地图质量的定量评估

为了判断我们的生成随机地图算法是否具有良好的平衡性指标,我们设计了一套地图自动扩张算法:每个玩家以出生点占位符为种子,轮流扩张一个单元格,直到地图中所有的单元格都被有且只有一个玩家占领;然后我们统计每个玩家占领到的资源数量、距离最近的敌人距离,以及每个玩家与多少数量的玩家领土相邻。如下图所示: 

实验组是我们的算法生成的地图,对照组是根据水体与各种资源的比例随机采样地形、随机采样玩家分布得到的地图。如下方左侧是实验组生成的地图,右侧是对照组生成的地图:

实验组 对照组

实验组与对照组各生成100次地图,统计每个玩家与其他势力最小距离的均值与方差、扩张完成后各资源占有量的均值与方差以及每位玩家潜在冲突势力的均值与方差,统计的结果如下所示:

通过定量的统计结果可以看出,我们的方法生成的地图,玩家之间有更大的平均极小距离,这说明每位玩家的出生点占位符设置更加平衡;各种资源的分布方差均比对照组小,说明我们的战略特征分配与朴素的随机生成的地图相比更加均衡。

综上所述,我们的地图生成结果能够保证对称性多人对抗战略游戏的平衡性。

线上体验地址:huanggaole.itch.io/cition

参考文献

[1] Ford, Dom. "eXplore, eXpand, eXploit, eXterminate”: Affective writing of postcolonial history and education in Civilization V." Game Studies 16.2 (2016)

[2] Jakub Kowalski,Radoslaw Miernik,Piotr Pytlik,Maciej Pawlikowski(2018). Strategic Features and Terrain Generation for Balanced Heroes of Might and Magic III Maps. 2018 IEEE Conference on Computational Intelligence and Games

[3] Pereira,Prada, Rui. (2009). Self-adapting dynamically generated maps for turn-based strategic multiplayer browser games. Proceedings of the International Conference on Advances in Computer Entertainment Technology, ACE 2009, Athens, Greece, October 29-31, 2009

[4]Ken Perlin. An image synthesizer. SIGGRAPH Comput. Graph. 1985, 19: 287––296.

Guess you like

Origin juejin.im/post/7085186517588525092