本文整理汇总了Python中individual.Individual.play_game方法的典型用法代码示例。如果您正苦于以下问题:Python Individual.play_game方法的具体用法?Python Individual.play_game怎么用?Python Individual.play_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类individual.Individual
的用法示例。
在下文中一共展示了Individual.play_game方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_json_record
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import play_game [as 别名]
def make_json_record(case_name=CASE_NAME, seed=0, lineage=0, age=0):
input_filepath = os.path.join(RESULT_DIR, case_name)
output_file = os.path.join(
ensure_exists(os.path.join(ANALYSIS_DIR, case_name, "seed-{}".format(seed))), "game.json"
)
params = load("params", input_filepath, seed)
TASKS = [(task[0], int(task[1][::-1], 2)) for task in params["TASKS"]]
hit_multipliers, patterns = zip(*TASKS)
lineages = load("lineages", input_filepath, seed)
def i2s(i):
return tuple((i >> n) & 1 for n in range(params["NUM_NODES"]))
ind = Individual(lineages[lineage][age].genome)
transitions = ind.play_game(hit_multipliers, patterns)
states = [
ps[: params["NUM_SENSORS"]] + cs[params["NUM_SENSORS"] :]
for ps, cs in zip(map(i2s, transitions[0]), map(i2s, transitions[1]))
]
trial_length = params["WORLD_HEIGHT"]
block_sizes = []
for pattern in patterns:
block_sizes += [sum(i2s(pattern))] * int(params["NUM_TRIALS"] / len(patterns))
json_dict = {
"generation": params["NGEN"] - age,
"connectivityMatrix": ind.cm.T.tolist(),
"nodeTypes": {"sensors": [0, 1], "hidden": [2, 3, 4, 5], "motors": [6, 7]},
"blockSize": block_sizes,
"Trial": [
{"trialNum": i, "lifeTable": states[(i * trial_length) : ((i + 1) * trial_length)]}
for i in range(params["NUM_TRIALS"])
],
}
with open(output_file, "w") as f:
json.dump(json_dict, f)
print("Saved game representation to `{}`.".format(output_file))
return json_dict