from otree.api import Currency as c, currency_range from ._builtin import Page from .models import Constants import datetime, json, time import random import math class instructions1(Page): def vars_for_template(self): if self.round_number ==1: self.participant.vars['roundnumber'] = 1 if self.round_number ==2: self.participant.vars['roundnumber'] = 2 if self.round_number ==3: self.participant.vars['roundnumber'] = 3 if self.round_number ==4: self.participant.vars['roundnumber'] = 4 if self.round_number == 1: #8 return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins= 0 #self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 2: #8 return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 3: #8 return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 4: #8 return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) def before_next_page(self): self.participant.vars['sssss'] = time.time() class Game1(Page): form_model = 'player' form_fields = ['puzzle_solved', 'total_payoff', 'time_spent', 'num_of_moves', 'min_num_of_moves', 'board_history', 'deduction_per_second', 'deduction_all_seconds', 'deduction_per_move', 'deduction_all_moves', 'time_between_moves', 'endowment', 'deduction_per_move_cents', 'deduction_per_second_cents'] timeout_seconds = 300 timer_text = 'Time Left to Next Deduction:' def before_next_page(self): self.player.deduction_all_seconds = self.player.time_spent // 10 * self.player.deduction_per_second if self.player.num_of_moves <= 14 and self.player.puzzle_solved == 1: self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) self.player.total_payoff = 4 if self.player.puzzle_solved == 0: self.player.num_of_moves = 14 self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) self.player.total_payoff = 0 if self.player.num_of_moves > 14 and self.player.puzzle_solved == 1: self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) self.player.total_payoff = 0 if self.timeout_happened: self.player.total_payoff = 0 self.player.time_spent = self.timeout_seconds if self.player.total_payoff < 0: self.player.total_payoff = 0 else: self.player.total_payoff = self.player.total_payoff def vars_for_template(self) -> dict: if self.round_number == 1: return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins= 0 #self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 2: return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 3: return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) if self.round_number == 4: return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=4, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=0 # self.participant.vars['sec'][self.round_number - 1], ) def js_vars(self): if self.round_number == 1: # 8 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'per_move': 0, # self.participant.vars['move'][self.round_number - 1], 'per_move_cents': 0, 'per_10sec': 0, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 0, 'endowment': 4, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [5, 2, None], [1, 4, 3], [7, 8, 6], ] } if self.round_number == 2: # 8 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'per_move': 0, # self.participant.vars['move'][self.round_number - 1], 'per_move_cents': 0, 'per_10sec': 0, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 0, 'endowment': 4, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [None, 3, 6], [1, 4, 2], [7, 5, 8], ] } if self.round_number == 3: # 8 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'per_move': 0, # self.participant.vars['move'][self.round_number - 1], 'per_move_cents': 0, 'per_10sec': 0, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 0, 'endowment': 4, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [2, 4, 3], [1, 5, 6], [7, 8, None], ] } if self.round_number == 4: # 8 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'per_move': 0, # self.participant.vars['move'][self.round_number - 1], 'per_move_cents': 0, 'per_10sec': 0, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 0, 'endowment': 4, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [4, 1, 3], [7, None, 6], [5, 2, 8], ] } class Results(Page): form_model = 'player' form_fields = ['final_payoff1', 'bonus'] def vars_for_template(self): if self.player.num_of_moves == 8 and self.player.puzzle_solved ==1: self.player.bonus = 1 self.player.final_payoff1 = self.player.total_payoff + 1 self.participant.vars['final_payoff1'] = self.player.final_payoff1 self.participant.vars['bonus'] = self.player.bonus else: self.player.bonus = 0 self.player.final_payoff1 = self.player.total_payoff self.participant.vars['final_payoff1'] = self.player.final_payoff1 self.participant.vars['bonus'] = self.player.bonus if self.round_number == 1: #8 return dict( roundnumber=self.participant.vars['roundnumber'], final_payoff1=self.participant.vars['final_payoff1'], bonus=self.participant.vars['bonus'], ) if self.round_number == 2: #8 return dict( roundnumber=self.participant.vars['roundnumber'], final_payoff1=self.participant.vars['final_payoff1'], bonus=self.participant.vars['bonus'], ) if self.round_number == 3: #8 return dict( roundnumber=self.participant.vars['roundnumber'], final_payoff1=self.participant.vars['final_payoff1'], bonus=self.participant.vars['bonus'], ) if self.round_number == 4: # 8 return dict( bonus=self.participant.vars['bonus'], player_in_all_rounds=self.player.in_all_rounds(), roundnumber=self.participant.vars['roundnumber'], final_payoff1 = self.participant.vars['final_payoff1'], ) def js_vars(self): return { 'final_payoff1': self.participant.vars['final_payoff1'], 'bonus': self.participant.vars['bonus'], } def before_next_page(self): player_wo = self.player.in_all_rounds() self.participant.vars["solved_wo"] = [p.puzzle_solved for p in player_wo] self.participant.vars['time_wo'] = [p.time_spent for p in player_wo] self.participant.vars['moves_wo'] = [p.num_of_moves for p in player_wo] self.participant.vars['endow_wo'] = [p.endowment for p in player_wo] self.participant.vars['payoff_wo'] = [p.final_payoff1 for p in player_wo] self.participant.vars['bonus_wo'] = [p.bonus for p in player_wo] page_sequence = [instructions1, Game1, Results, ]