1
使用python axelrod庫,我正在通過以下(和優秀)的博客爲我自己:http://mojones.net/evolving-strategies-for-an-iterated-prisoners-dilemma-tournament.html。在嘗試實施lookerup策略時,出現以下錯誤:我如何解決蟒蛇axelrod Lookerup策略中的關鍵錯誤
KeyError: Plays(self_plays=(C, C), op_plays=(C, D), op_openings=(C, D))
如何解決此錯誤?我是否錯誤地實施了lookerup策略?我試圖通過github上的策略代碼來追蹤錯誤,但我只是沒有看到這個問題。以下代碼提供了我的問題的示例。如果我換掉另一個(例如另一個交流發電機)的lookerup策略,則axelrod遊戲會按我的預期執行。
import axelrod
import random
import itertools
def get_random_table():
strings = [''.join(x) for x in itertools.product('CD', repeat=2)]
keys = list(itertools.product(strings, strings, strings))
values = ''.join([random.choice('CD') for _ in keys])
return dict(zip(keys, values))
player_1 = axelrod.LookerUp(random_table)
#player_1 = axelrod.Alternator()
player_2 = axelrod.Alternator()
g = axelrod.Game()
iterations = 10
for turn in range(iterations):
player_1.play(player_2)
(其它標記可能包括「阿克塞爾羅德」和「prisoner's-困境」。)
您的示例代碼已損壞:未定義'random_table'。 – lxop