我被分配了一个计算任务,用伪代码和算法创建随机生成的游戏关卡。地图必须使用#来打印,并且具有少于3个邻居的空间和单元格会消亡。但我们被告知在没有任何一方的情况下解决问题,可以肯定的说,我不知道我在做什么。任何帮助都将不胜感激。。。在
以下是全部代码:
# -*- coding: utf-8 -*-
import random
def create_random_map(height, width):
map = []
for y in range(height):
for x in range(width):
map.append( bool(random.randint(0,1)) )
return map
def apply_cellular_automaton(map, height, width, born, survive):
return map
def draw_map(map, height, width):
pass
height = 45
width = 79
map = create_random_map(height, width)
for i in range(5):
map = apply_cellular_automaton(map, height, width, [6, 7, 8], [3, 4, 5, 6, 7, 8])
for i in range(3):
map = apply_cellular_automaton(map, height, width, [5, 6, 7, 8], [5, 6, 7, 8])
draw_map(map, height, width)
给我的伪代码
^{pr2}$我已经给出了一个公式例子
^{3}$
您可以先为map找到一个可行的结构。 地图必须是二维结构。这样做的一种方法是使map成为一个列表列表,即一个行列表,其中每个rows元素都是该行的列。请参见Rosetta代码站点上的Create a two-dimensional array at runtime。在
接下来填充一个数组,并尝试将draw_-map伪代码转换为正确的Python,围绕2D数组的实现。在
相关问题 更多 >
编程相关推荐