我正在为我将在我的硕士论文中运行的实验编写代码。我基本上完成了,但我被困在最后一个方面,我找不到解决方法。我有一个公益游戏,有 16 名参与者,分成 8 个两人组。我有 4 次治疗并且我平衡了比赛,每轮治疗由 4 名玩家玩(他们是 12 人)。我目前缺少的部分是我希望每个玩家每轮都打 3 次。这种随机化在下面的代码中执行,理论上可行,但实际上我从未设法完成它。在 20 分钟内,我设法在第 10 轮结束时完成,但无法让程序找到满足上述第 11 轮和第 12 轮两个条件的组合。我知道这有点棘手,如果你更容易理解喜欢它,但是。.. 你有什么建议吗?非常感谢!
class Subsession(BaseSubsession):
def before_session_starts(self):
info_condition = ['Bel', 'Bel', 'Act', 'Act', 'Ctrl', 'Ctrl', 'No', 'No']
i = 0
condition = True
while condition:
i+= 1
print('I am in the loop: {} th time. Round{}.'.format(i, self.round_number))
self.group_randomly()
for gr_index, g in enumerate(self.get_groups()):
g.info = info_condition[gr_index]
for p in g.get_players():
p.info_player = g.info
condition = any(not p.can_go_on(p.info_player) for p in self.get_players())
if condition == False:
break
p.count_treat()
print('I am out of the loop. Round{}'.format(self.round_number))
class Player(BasePlayer):
runs = models.CharField()
def count_treat(self):
ctrl_count = 0
no_count = 0
bel_count = 0
act_count = 0
for p in self.in_all_rounds():
if p.info_player == "Ctrl":
ctrl_count += 1
elif p.info_player == "No":
no_count += 1
elif p.info_player == "Bel":
bel_count += 1
elif p.info_player == "Act":
act_count += 1
p.runs = dict()
p.runs['Ctrl'] = ctrl_count
p.runs['Bel'] = bel_count
p.runs['No'] = no_count
p.runs['Act'] = act_count
def can_go_on(self, activity):
self.count_treat()
print(self.id_in_subsession, self.runs[activity] < 4, activity, self.runs[activity])
return self.runs[activity] < 4