我有以下循环:
for tile_id, tile in corner_tiles.items():
for neighbour in tile["neighbours"]:
if not (neighbour in enemy_tiles) and tile["player"] == None:
return tile_id
其中:
tile
是
{'counters': <number of counters on tile or None>,
'player': <player id of the player who holds the tile or None>,
'neighbours': <list of ids of neighbouring tile>
}
和corner_tiles
和enemy_tiles
是{<tile_id> : <tile>, ... }
形式的词典。你知道吗
你知道吗
不管neighbour
是否在enemy_tiles
中,循环总是返回tile_id
,但如果tile["player"]
不是None
,则不会返回。我想弄清楚这一点已经有一段时间了,但似乎无法发现哪里出了问题。你知道吗
编辑:
我也尝试过:
for tile_id, tile in corner_tiles.items():
if tile["player"] is None:
for neighbour in tile["neighbours"]:
if neighbour not in enemy_tiles:
return tile_id
它们的作用是一样的。你知道吗
在经历了巨大的压力之后,我发现了错误背后的简单原因,我正在为错过它而自责。。。你知道吗
我的循环应该做的是确保所有
neighbours
都不在enemy_tiles
中。当然,它几乎每次都被评估为true,因为检查的第一个neighbour
不在enemy_tiles
中的概率要高得多,因此该语句为true,并且在只检查一个neighbour
之后返回tile_id
。你知道吗相关问题 更多 >
编程相关推荐