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'] = 5 if self.round_number ==2: self.participant.vars['roundnumber'] = 6 if self.round_number ==3: self.participant.vars['roundnumber'] = 7 if self.round_number ==4: self.participant.vars['roundnumber'] = 8 if self.round_number == 1: #8 return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins= 1 #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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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 = 60 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 = round((self.player.endowment - self.player.deduction_all_seconds), 2) if self.player.puzzle_solved == 0: 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.player.total_payoff < 0: self.player.total_payoff = 0 else: self.player.total_payoff = self.player.total_payoff if self.timeout_happened: self.player.time_spent = self.timeout_seconds self.player.total_payoff = 0 def vars_for_template(self) -> dict: if self.round_number == 1: return dict( roundnumber=self.participant.vars['roundnumber'], min_num_of_moves=8, endowment=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins= 1 #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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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=6, per_move_ins=0, # self.participant.vars['move'][self.round_number - 1], per_10sec_ins=1 # 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': 1, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 100, 'endowment': 6, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [1, 6, 2], [4, 5, 3], [7, 8, None], ] } 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': 1, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 100, 'endowment': 6, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [None, 5, 2], [1, 8, 3], [4, 7, 6], ] } 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': 1, # self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 100, 'endowment': 6, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [1, 5, 2], [4, 3, 6], [None, 7, 8], ] } 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': 1,#self.participant.vars['sec'][self.round_number - 1], 'per_10sec_cents': 100, 'endowment': 6, 'min_num_of_moves': 8, 'player_id': self.player.id, 'the_player': self.player.id == 1, 'board': [ [4, 1, 3], [7, None, 5], [8, 2, 6], ] } 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( player_in_all_rounds=self.player.in_all_rounds(), bonus=self.participant.vars['bonus'], 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_with = self.player.in_all_rounds() self.participant.vars['solved_with'] = [p.puzzle_solved for p in player_with] self.participant.vars['time_with'] = [p.time_spent for p in player_with] self.participant.vars['moves_with'] = [p.num_of_moves for p in player_with] self.participant.vars['endow_with'] = [p.endowment for p in player_with] self.participant.vars['payoff_with'] = [p.final_payoff1 for p in player_with] self.participant.vars['bonus_with'] = [p.bonus for p in player_with] page_sequence = [instructions1, Game1, Results, ]