from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class FirstWaitPage(WaitPage): wait_for_all_groups = True template_name = 'Coordination_Structure_6/MyWaitPage.html' def is_displayed(self): return self.round_number == 1 body_text = "請等待其他受試者完成小測驗。" class StrategyMethodInitial(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['Message1', 'Message2', 'Message3'] def before_next_page(self): if self.player.State_ball == 1: self.player.Message = self.player.Message1 elif self.player.State_ball == 2: self.player.Message = self.player.Message2 else: self.player.Message = self.player.Message3 class StrategyMethod(Page): def is_displayed(self): return self.round_number != 1 form_model = 'player' form_fields = ['Message1', 'Message2', 'Message3'] def js_vars(self): return dict( Message1=self.player.Message1, Message2=self.player.Message2, Message3=self.player.Message3, ) def before_next_page(self): if self.player.State_ball == 1: self.player.Message = self.player.Message1 elif self.player.State_ball == 2: self.player.Message = self.player.Message2 else: self.player.Message = self.player.Message3 class SendMessage(Page): form_model = 'player' form_fields = ['Message'] def vars_for_template(self): return dict( image_path_ball='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.State_ball) ) def js_vars(self): return dict( Message=self.player.Message, ) class MessagesWaitPage(WaitPage): body_text = "請等待其他組員發送訊息。" template_name = 'Coordination_Structure_6/MyWaitPage.html' class ReceiveMessage(Page): # timeout_seconds = 30 form_model = 'player' form_fields = ['Action_ball_1', 'Action_ball_2'] class Results(Page): # timeout_seconds = 30 def vars_for_template(self): if self.player.Action_ball_1 == self.player.First_state: first_action_match = 2 else: first_action_match = 0 if self.player.Action_ball_2 == self.player.Second_state: second_action_match = 2 else: second_action_match = 0 if self.player.State_ball == self.player.First_action: first_state_match = 2 else: first_state_match = 0 if self.player.State_ball == self.player.Second_action: second_state_match = 2 else: second_state_match = 0 return dict( image_path_ball_M_S='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.State_ball), image_path_text_M_A1='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.Action_ball_1), image_path_text_M_A2='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.Action_ball_2), image_path_ball_S1='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.First_state), image_path_ball_S2='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.Second_state), image_path_ball_A1='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.First_action), image_path_ball_A2='exercise_rounds/Pic/Symbol_{}.jpg'.format(self.player.Second_action), first_action_match=first_action_match, second_action_match=second_action_match, first_state_match=first_state_match, second_state_match=second_state_match ) page_sequence = [FirstWaitPage, StrategyMethodInitial, StrategyMethod, SendMessage, ReceiveMessage, Results]