from otree.api import Currency as c, currency_range from . import pages from ._builtin import Bot from .models import Constants import test_cases as tc import random # FOR ALPHA/BETA TESTING class PlayerBot(Bot): """"This class represents a virtual player that will input the values that each page requires and that allows to test if there are errors in a specific page or field. -Yield statements will change the value of the fields -Assert statements check if the field values have a specific value or not There are two main modes for the bots *alpha: They check if the game runs with values that belong to the boundaries of each variable. It has 4 submodes **inside: checks for errors using inside the boundaries **boundaries: checks for errors using the boundary values **outside: checks for errors using values outside the boundaries **types: checks if the values that has been inputted are the same type of the respective variables *beta: They check how the game would run in a real environment with a big amount of players. To activate it, run the game with N bots in the 'inside' mode """ def play_round(self): test_mode = 'inside' tests_for_lender = tc.lender_cases[test_mode] tests_for_borrower = tc.borrower_cases[test_mode] page_sequence = [ WelcomePage, TaskOverview, RoleAssignment, LoanAgreement, LoanFulfillment, LoanRemediation, TaskRepayment, QuizWaitPage, QuestionOne, QuestionTwo, QuestionThree, QuestionFour, QuestionFive, QuestionSix, QuizResults, QuizWaitPage, WaitForPlayer, Collateral_Offer, WaitForPlayer, Loan_Amount, WaitForPlayer, Loan_Package, WaitForPlayer, Realize_Return, WaitForPlayer, Collateral_Decision, WaitForPlayer, Seize_Collateral, WaitForPlayer, Results, ] if test_mode in tc.available_test_modes: yield (pages.pages.WelcomePage) yield (pages.pages.TaskOverview) yield (pages.RoleAssignment) yield (pages.LoanAgreement) yield (pages.LoanFulfillment) yield (pages.LoanRemediation) yield (pages.TaskRepayment) yield (pages.QuizWaitPage) yield (pages.QuestionOne) yield (pages.QuestionTwo) yield (pages.QuestionThree) yield (pages.QuestionFour) yield (pages.QuestionFive) yield (pages.QuestionSix) yield (pages.QuizResults) if self.player.role() == 'lender': yield (pages.Loan_Amount, {'loan': tests_for_lender['loan']}) assert self.group.loan == tests_for_lender['loan'] if Constants.contract_enforcement is False: if self.group.accept_loan == 'Yes': yield (pages.Collateral_Decision, {'satisfied': tests_for_lender['satisfied']}) assert self.group.satisfied == tests_for_lender['satisfied'] if self.group.satisfied == 'No': recovered_collateralralral_aux = r.randrange(0, self.group.collateral_after_feee) yield (pages.Seize_Collateral, {'recovered_collateralralrecovered_collateralateralateral_aux}) assert self.group.recovered_collateralralrrecovered_collateralateralateral_aux elif self.player.role() == 'borrower': yield (pages.Collateral_Offer, {'collateral': tests_for_borrower['collateral']}) yield (pages.Loan_Package, {'accept_loan': tests_for_borrower['accept_loan']}) assert self.group.collateral == c(tests_for_borrower['collateral']) assert self.group.accept_loan == tests_for_borrower['accept_loan'] if self.group.accept_loan == 'Yes': lender_return_aux = r.randrange(0, Constants.productivity * self.group.loan) yield (pages.Realize_Return, {'lender_return': lender_return_aux}) assert self.group.lender_return == c(lender_return_aux) else: print('There are only two roles: Borrower and Lender. You ' 'are using another one that is not allowed.') yield (pages.Results) else: print('Testing mode error: An invalid mode has been inputted.')