from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import itertools from collections import defaultdict import numpy as np from django import forms from django.forms import widgets as django_widgets import math author = 'Jindi Huang' doc = """ Game Complexity """ class Constants(BaseConstants): name_in_url = 'game_stage2' players_per_group = None round_per_game = 6 game_num = 4 num_rounds = game_num*round_per_game signal_interval = 0.5 signal_max = 15 signal_num = int(signal_max/signal_interval) budget = 20 min_time = 30 scaler = 2.8 list1 = np.arange(1 * 20, - 1, -1) list2 = [] list2.append(0) for x in range(20): list2.append((x+1)*5) # fpa_pool = [0.0, 0.0, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.25, 1.5, 2.0, 2.0, 2.0, 2.0, 2.25, 2.25, 3.0, 3.0, 3.0, 3.0, 3.25, 3.5, 3.5, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.75, 6.0, 6.0, 6.0, 6.25, 6.25, 6.5, 7.0, 7.0, 7.0, 7.0, 7.5, 7.75, 7.75, 8.0, 8.0, 8.0, 8.0, 8.75, 9.0, 9.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.25, 10.5, 10.5, 11.0, 11.0, 11.0, 11.0, 11.25, 11.25, 12.0, 12.0, 12.0, 12.0, 12.5, 13.0, 13.0, 13.0, 13.25, 13.5, 13.5, 14.0, 14.0, 14.0, 14.0, 15.0, 15.5, 16.0, 20.0] fpa_pool = [0.0, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.0, 3.0, 3.5, 3.5, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.5, 6.0, 6.0, 6.0, 6.0, 6.0, 6.5, 7.0, 7.0, 7.0, 7.0, 7.5, 7.5, 8.0, 8.0, 8.0, 8.0, 8.0, 8.5, 9.0, 9.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.5, 10.5, 10.5, 11.0, 11.0, 11.0, 11.0, 11.0, 11.5, 12.0, 12.0, 12.0, 12.0, 12.5, 13.0, 13.0, 13.0, 13.0, 13.5, 13.5, 14.0, 14.0, 14.0, 14.0, 15.0, 15.5, 16.0, 20.0] # spa_pool = [0.0, 0.0, 0.25, 0.75, 1.0, 1.0, 1.0, 1.0, 1.25, 1.25, 2.0, 2.0, 2.5, 3.0, 3.0, 3.25, 3.5, 3.5, 3.75, 3.75, 4.0, 4.25, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 5.0, 5.25, 5.5, 6.0, 6.0, 6.25, 7.0, 7.0, 7.0, 7.0, 7.5, 7.75, 8.0, 8.5, 8.75, 9.0, 9.0, 9.0, 9.25, 9.5, 9.5, 9.5, 9.75, 9.75, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.25, 10.25, 10.5, 11.0, 11.0, 11.25, 11.5, 12.0, 12.0, 12.0, 12.25, 12.25, 12.5, 12.75, 12.75, 13.0, 13.0, 13.0, 13.0, 13.25, 14.0, 14.0, 14.5, 15.0, 15.0, 15.0, 15.0, 15.25, 15.5, 15.5, 16.0, 16.0, 16.0, 16.0, 16.5, 17.0, 17.0, 20.0, 20.0, 20.0, 20.0, 20.0] spa_pool = [0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.5, 3.5, 3.5, 3.5, 3.5, 4.0, 4.0, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 5.0, 5.5, 5.5, 6.0, 6.0, 6.0, 7.0, 7.0, 7.0, 7.0, 7.5, 8.0, 8.0, 8.5, 8.5, 9.0, 9.0, 9.0, 9.5, 9.5, 9.5, 9.5, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.5, 11.0, 11.0, 11.5, 11.5, 12.0, 12.0, 12.0, 12.5, 12.0, 12.5, 12.5, 12.5, 13.0, 13.0, 13.0, 13.0, 13.0, 14.0, 14.0, 14.5, 15.0, 15.0, 15.0, 15.0, 15.0, 15.5, 15.5, 16.0, 16.0, 16.0, 16.0, 16.5, 17.0, 17.0, 20.0, 20.0, 20.0, 20.0, 20.0] # aa = {0.0: 0, 0.25: 0, 0.5: 0, 0.75: 0, 1.0: 0, 1.25: 0.149050986452622, 1.5: 0.0, 1.75: 0.07035117712830502, 2.0: 0.0, 2.25: 0.023827982407022996, 2.5: 0.020439976895425982, 2.75: 0.0, 3.0: 0.0, 3.25: 0.018121578648904013, 3.5: 0.031522834195717, 3.75: 0.014056462694790994, 4.0: 0.013197503103205999, 4.25: 0.012479108326312993, 4.5: 0.0, 4.75: 0.0, 5.0: 0.011868324261900987, 5.25: 0.032705345055193014, 5.5: 0.01012225274880002, 5.75: 0.01931897089078799, 6.0: 0.027088218137275022, 6.25: 0.017048117489148973, 6.5: 0.03995318396652603, 6.75: 0.015142553528091018, 7.0: 0.014764604024907979, 7.25: 0.014440817961294927, 7.5: 0.034983561718687106, 7.75: 0.020417066060274935, 8.0: 0.013444030459728973, 8.25: 0.026627139667889987, 8.5: 0.019861700798778026, 8.75: 0.006620330875315994, 9.0: 0.013264316276384025, 9.25: 0.006652404734014961, 9.5: 0.006671789280294993, 9.75: 0.0, 10.0: 0.020179672075109067, 10.25: 0.027495658365684017, 10.5: 0.007022612667561989, 10.75: 0.014280385707842957, 11.0: 0.014662205118249005, 11.25: 0.022940536407601964, 11.5: 0.02453950635749602, 11.75: 0.017650416075933983, 12.0: 0.00935724255859205, 12.25: 0.009811575271176043, 12.5: 0.010375150141271994, 12.75: 0.0, 13.0: 0.023154162066787998, 13.25: 0.0, 13.5: 0.0, 13.75: 0.04882012088101495, 14.0: 0.045668418518076015, 14.25: 0.0, 14.5: 0.0, 14.75: 0.0, 15.0: 0.0, 15.25: 0.0, 15.5: 0.0, 15.75: 0.0, 16.0: 0.0, 16.25: 0.0, 16.5: 0.0, 16.75: 0.0, 17.0: 0.0, 17.25: 0.0, 17.5: 0.0, 17.75: 0.0, 18.0: 0.0, 18.25: 0.0, 18.5: 0.0, 18.75: 0.0, 19.0: 0.0, 19.25: 0.0, 19.5: 0.0, 19.75: 0.0, 20.0: 0.0} aa = {0.0: 0, 0.5: 0.0, 1.0: 0.074525493226311, 1.5: 0.1097010817904635, 2.0: 0.04708957976766401, 2.5: 0.03235396809893748, 3.0: 0.009060789324451979, 3.5: 0.04761185486756453, 4.0: 0.02646528861375802, 4.5: 0.006239554163156469, 5.0: 0.02822099678949752, 5.5: 0.036134410721790466, 6.0: 0.0452717623272435, 6.5: 0.056048519475146, 7.0: 0.029556289769601007, 7.5: 0.05241250372947204, 8.0: 0.03696613332381149, 8.5: 0.03648543607038102, 9.0: 0.01990068408104939, 9.5: 0.009997991647302529, 10.0: 0.033927501257951076, 10.5: 0.027910634704325532, 11.0: 0.033272666175971466, 11.5: 0.044834982599263995, 12.0: 0.023088238232147007, 12.5: 0.015280937776860015, 13.0: 0.023154162066787998, 13.5: 0.02441006044050742, 14.0: 0.07007847895858355, 14.5: 0.0, 15.0: 0.0, 15.5: 0.0, 16.0: 0.0, 16.5: 0.0, 17.0: 0.0, 17.5: 0.0, 18.0: 0.0, 18.5: 0.0, 19.0: 0.0, 19.5: 0.0, 20.0: 0.0} # da = {0.0: 0.0, 0.25: 0.0, 0.5: 0.0, 0.75: 0.0, 1.0: 0.0, 1.25: 0.0, 1.5: 0.3593041119630842, 1.75: 0.0, 2.0: 0.0, 2.25: 0.0, 2.5: 0.0, 2.75: 0.0, 3.0: 0.0, 3.25: 0.0, 3.5: 0.0, 3.75: 0.06798289443314987, 4.0: 0.08084574175838066, 4.25: 0.05420857703573434, 4.5: 0.04193375428100454, 4.75: 0.0, 5.0: 0.034668024774918815, 5.25: 0.0, 5.5: 0.0, 5.75: 0.0, 6.0: 0.0, 6.25: 0.0, 6.5: 0.0, 6.75: 0.015407275358444883, 7.0: 0.014389925371704693, 7.25: 0.0, 7.5: 0.0, 7.75: 0.013516734654266838, 8.0: 0.02484974155585873, 8.25: 0.0, 8.5: 0.03297602330573768, 8.75: 0.0, 9.0: 0.046771176476795406, 9.25: 0.01657443797557112, 9.5: 0.007916506844856896, 9.75: 0.007691333023211344, 10.0: 0.03553775397974812, 10.25: 0.019361119712212327, 10.5: 0.006176604288712917, 10.75: 0.006049233888184569, 11.0: 0.011739789330270423, 11.25: 0.005701243597996397, 11.5: 0.0, 11.75: 0.0, 12.0: 0.03717491104993975, 12.25: 0.0, 12.5: 0.004964694343391307, 12.75: 0.004887716294052713, 13.0: 0.009555264106959283, 13.25: 0.0, 13.5: 0.0, 13.75: 0.004672569066050625, 14.0: 0.0, 14.25: 0.0, 14.5: 0.01362488416331853, 14.75: 0.0, 15.0: 0.00441763845261367, 15.25: 0.0, 15.5: 0.0, 15.75: 0.0, 16.0: 0.0, 16.25: 0.0, 16.5: 0.0, 16.75: 0.004358863815263181, 17.0: 0.004301882026837123, 17.25: 0.0, 17.5: 0.0, 17.75: 0.004246608617723302, 18.0: 0.0, 18.25: 0.0, 18.5: 0.0, 18.75: 0.0, 19.0: 0.0, 19.25: 0.0, 19.5: 0.0, 19.75: 0.004192964454005743, 20.0: 0.0} da = {0.0: 0, 0.5: 0.0, 1.0: 0.0, 1.5: 0.3593041119630842, 2.0: 0.0, 2.5: 0.0, 3.0: 0.0, 3.5: 0.03399144721657493, 4.0: 0.14194147749282277, 4.5: 0.06903804279887171, 5.0: 0.034668024774918815, 5.5: 0.0, 6.0: 0.0, 6.5: 0.0077036376792224415, 7.0: 0.022093563050927134, 7.5: 0.006758367327133419, 8.0: 0.03160810888299215, 8.5: 0.03297602330573768, 9.0: 0.05505839546458102, 9.5: 0.020049392344248074, 10.0: 0.04906398034745996, 10.5: 0.018881781088911365, 11.0: 0.017615028073360905, 11.5: 0.0028506217989981986, 12.0: 0.03717491104993975, 12.5: 0.007408552490417608, 13.0: 0.011999122253985695, 13.5: 0.002336284533025257, 14.0: 0.002336284533025368, 14.5: 0.01362488416331853, 15.0: 0.00441763845261367, 15.5: 0.0, 16.0: 0.0, 16.5: 0.0021794319076315904, 17.0: 0.006481313934468713, 17.5: 0.002123304308861651, 18.0: 0.002123304308861651, 18.5: 0.0, 19.0: 0.0, 19.5: 0.0020964822270028716, 20.0: 0.0020964822270028716} aa_pool = list(aa.keys()) da_pool = list(da.keys()) aa_weights = list(aa.values()) da_weights = list(da.values()) # fpa_optimal = {0.0: 0, 0.25: 0, 0.5: 0.25, 0.75: 0.5, 1.0: 0.75, 1.25: 0.75, 1.5: 1.25, 1.75: 1.25, 2.0: 1.25, 2.25: 1.25, 2.5: 1.25, 2.75: 1.25, 3.0: 2.25, 3.25: 2.25, 3.5: 2.5, 3.75: 2.5, 4.0: 2.5, 4.25: 2.5, 4.5: 2.5, 4.75: 3.25, 5.0: 3.25, 5.25: 3.75, 5.5: 3.75, 5.75: 3.75, 6.0: 4.25, 6.25: 4.25, 6.5: 4.25, 6.75: 4.25, 7.0: 5.25, 7.25: 5.25, 7.5: 5.25, 7.75: 5.25, 8.0: 5.25, 8.25: 5.25, 8.5: 5.25, 8.75: 5.25, 9.0: 6.5, 9.25: 6.5, 9.5: 7.25, 9.75: 7.25, 10.0: 7.25, 10.25: 7.25, 10.5: 8.25, 10.75: 8.25, 11.0: 8.25, 11.25: 8.25, 11.5: 8.25, 11.75: 8.25, 12.0: 8.25, 12.25: 8.25, 12.5: 8.25, 12.75: 8.25, 13.0: 10.25, 13.25: 10.25, 13.5: 10.25, 13.75: 10.25, 14.0: 10.25, 14.25: 10.25, 14.5: 11.25, 14.75: 11.5, 15.0: 11.5} fpa_optimal = {0.0: 0, 0.5: 0, 1.0: 0.5, 1.5: 1.0, 2.0: 1.5, 2.5: 1.5, 3.0: 1.5, 3.5: 2.5, 4.0: 2.5, 4.5: 2.5, 5.0: 3.5, 5.5: 3.5, 6.0: 3.5, 6.5: 4.5, 7.0: 4.5, 7.5: 5.5, 8.0: 5.5, 8.5: 5.5, 9.0: 5.5, 9.5: 7.5, 10.0: 7.5, 10.5: 7.5, 11.0: 8.5, 11.5: 8.5, 12.0: 8.5, 12.5: 8.5, 13.0: 8.5, 13.5: 10.5, 14.0: 10.5, 14.5: 11.5, 15.0: 11.5} # da_optimal = {0.0: 0, 0.25: 0, 0.5: 0, 0.75: 0, 1.0: 0, 1.25: 0, 1.5: 0, 1.75: 0, 2.0: 1.75, 2.25: 1.75, 2.5: 1.75, 2.75: 1.75, 3.0: 1.75, 3.25: 1.75, 3.5: 1.75, 3.75: 1.75, 4.0: 1.75, 4.25: 1.75, 4.5: 1.75, 4.75: 1.75, 5.0: 1.75, 5.25: 1.75, 5.5: 4.5, 5.75: 4.5, 6.0: 4.75, 6.25: 4.75, 6.5: 4.75, 6.75: 4.75, 7.0: 4.75, 7.25: 4.75, 7.5: 4.75, 7.75: 4.75, 8.0: 5.25, 8.25: 5.25, 8.5: 5.25, 8.75: 5.25, 9.0: 5.25, 9.25: 5.25, 9.5: 5.25, 9.75: 5.25, 10.0: 5.25, 10.25: 5.25, 10.5: 5.25, 10.75: 5.25, 11.0: 5.25, 11.25: 5.25, 11.5: 5.25, 11.75: 5.25, 12.0: 5.25, 12.25: 5.25, 12.5: 5.25, 12.75: 5.25, 13.0: 5.25, 13.25: 5.25, 13.5: 5.25, 13.75: 5.25, 14.0: 10.25, 14.25: 10.5, 14.5: 10.5, 14.75: 10.5, 15.0: 10.5} da_optimal = {0.0: 0, 0.5: 0, 1.0: 0, 1.5: 0, 2.0: 0, 2.5: 2.0, 3.0: 2.0, 3.5: 2.0, 4.0: 2.0, 4.5: 2.0, 5.0: 2.0, 5.5: 2.0, 6.0: 4.5, 6.5: 5.0, 7.0: 5.0, 7.5: 5.0, 8.0: 5.0, 8.5: 5.5, 9.0: 5.5, 9.5: 5.5, 10.0: 5.5, 10.5: 5.5, 11.0: 5.5, 11.5: 5.5, 12.0: 5.5, 12.5: 5.5, 13.0: 5.5, 13.5: 5.5, 14.0: 9.5, 14.5: 10.5, 15.0: 10.5} revenue_fpa_genius = {0.0: 0, 0.5: 0, 1.0: 1.3913237053732923e-05, 1.5: 0.0006858710562414265, 2.0: 0.003005259203606311, 2.5: 0.006010518407212622, 3.0: 0.009015777610818933, 3.5: 0.014247154743022513, 4.0: 0.021370732114533768, 4.5: 0.028494309486045026, 5.0: 0.04173971116119877, 5.5: 0.05565294821493169, 6.0: 0.06956618526866462, 6.5: 0.08837482054500725, 7.0: 0.11046852568125906, 7.5: 0.14206136458967802, 8.0: 0.17757670573709752, 8.5: 0.21309204688451705, 9.0: 0.24860738803193655, 9.5: 0.28982406454093024, 10.0: 0.3622800806761628, 10.5: 0.43473609681139536, 11.0: 0.5291642060849283, 11.5: 0.634997047301914, 12.0: 0.7408298885188996, 12.5: 0.8466627297358853, 13.0: 0.952495570952871, 13.5: 1.106600130475245, 14.0: 1.2910334855544525, 14.5: 1.5243929963856506, 15.0: 1.778458495783259} revenue_fpa_ignorant = {0.0: -6.547143074504644, 0.5: -6.330437205690106, 1.0: -6.113731336875567, 1.5: -5.897025468061028, 2.0: -5.68031959924649, 2.5: -5.463613730431951, 3.0: -5.246907861617411, 3.5: -5.030201992802873, 4.0: -4.813496123988334, 4.5: -4.596790255173796, 5.0: -4.380084386359257, 5.5: -4.163378517544718, 6.0: -3.9466726487301793, 6.5: -3.7299667799156406, 7.0: -3.513260911101102, 7.5: -3.296555042286563, 8.0: -3.0798491734720246, 8.5: -2.8631433046574855, 9.0: -2.6464374358429468, 9.5: -2.4297315670284085, 10.0: -2.21302569821387, 10.5: -1.996319829399331, 11.0: -1.7796139605847925, 11.5: -1.5629080917702538, 12.0: -1.3462022229557151, 12.5: -1.1294963541411767, 13.0: -0.9127904853266378, 13.5: -0.6960846165120991, 14.0: -0.4793787476975604, 14.5: -0.26267287888302177, 15.0: -0.04596701006848318} revenue_da_genius = {0.0: 0, 0.5: 0, 1.0: 0, 1.5: 0, 2.0: 0, 2.5: 0.023192980697614503, 3.0: 0.046385961395229006, 3.5: 0.06957894209284352, 4.0: 0.09277192279045801, 4.5: 0.11596490348807251, 5.0: 0.13915788418568703, 5.5: 0.16235086488330153, 6.0: 0.2300010039858122, 6.5: 0.33097509196468733, 7.0: 0.44130012261958307, 7.5: 0.5516251532744788, 8.0: 0.6619501839293747, 8.5: 0.7825422900366434, 9.0: 0.9129660050427507, 9.5: 1.043389720048858, 10.0: 1.1738134350549652, 10.5: 1.3042371500610725, 11.0: 1.4346608650671797, 11.5: 1.5650845800732869, 12.0: 1.6955082950793943, 12.5: 1.8259320100855014, 13.0: 1.9563557250916088, 13.5: 2.086779440097716, 14.0: 2.2622744171780806, 14.5: 2.58217129755383, 15.0: 2.9049427097480587} revenue_da_ignorant = {0.0: -7.512609463755232, 0.5: -7.245525569075567, 1.0: -6.978441674395904, 1.5: -6.711357779716237, 2.0: -6.444273885036572, 2.5: -6.177189990356906, 3.0: -5.910106095677241, 3.5: -5.643022200997576, 4.0: -5.375938306317911, 4.5: -5.108854411638246, 5.0: -4.84177051695858, 5.5: -4.574686622278914, 6.0: -4.3076027275992494, 6.5: -4.0405188329195845, 7.0: -3.7734349382399195, 7.5: -3.506351043560254, 8.0: -3.23926714888059, 8.5: -2.972183254200924, 9.0: -2.7050993595212582, 9.5: -2.4380154648415933, 10.0: -2.1709315701619283, 10.5: -1.903847675482263, 11.0: -1.6367637808025979, 11.5: -1.3696798861229327, 12.0: -1.1025959914432673, 12.5: -0.835512096763602, 13.0: -0.5684282020839367, 13.5: -0.3013443074042713, 14.0: -0.034260412724606205, 14.5: 0.23282348195505875, 15.0: 0.4999073766347244} revenue_spa_genius = {0.0: 0, 0.5: 4e-06, 1.0: 3.599999999999995e-05, 1.5: 0.0002920000000000034, 2.0: 0.0007919999999999964, 2.5: 0.0016560000000000019, 3.0: 0.0027545000000001123, 3.5: 0.00444199999999987, 4.0: 0.007357999999999501, 4.5: 0.011988500000000051, 5.0: 0.019801000000004024, 5.5: 0.03199550000000835, 6.0: 0.04689100000001719, 6.5: 0.0648595000000319, 7.0: 0.0845115000000353, 7.5: 0.11194750000005428, 8.0: 0.14394749999998577, 8.5: 0.17840799999986198, 9.0: 0.21816149999986045, 9.5: 0.27007299999979173, 10.0: 0.3403769999996785, 10.5: 0.4379329999993417, 11.0: 0.5514234999993545, 11.5: 0.682495499998199, 12.0: 0.8198079999981227, 12.5: 0.977023999998047, 13.0: 1.171532499999214, 13.5: 1.408808499997032, 14.0: 1.6460844999921211, 14.5: 1.9020844999997477, 15.0: 2.1678049999916214} revenue_spa_ignorant = {0.0: -3.4505731829264805, 0.5: -3.2995922926856043, 1.0: -3.1486114024391845, 1.5: -2.997630512199467, 2.0: -2.8466496219514656, 2.5: -2.695668731712617, 3.0: -2.5446878414622445, 3.5: -2.3937069512255826, 4.0: -2.242726060972203, 4.5: -2.091745170731233, 5.0: -1.94076428048302, 5.5: -1.7897833902457747, 6.0: -1.6388025000000062, 6.5: -1.4878216097547219, 7.0: -1.3368407195092056, 7.5: -1.1858598292669602, 8.0: -1.0348789390231197, 8.5: -0.8838980487820158, 9.0: -0.7329171585359366, 9.5: -0.5819362682931593, 10.0: -0.43095537804821216, 10.5: -0.2799744878049524, 11.0: -0.12899359756049414, 11.5: 0.021987292682701096, 12.0: 0.17296818292658062, 12.5: 0.32394907317052535, 13.0: 0.47492996341478666, 13.5: 0.6259108536580018, 14.0: 0.7768917439005001, 14.5: 0.9278726341461299, 15.0: 1.0788535243879551} revenue_aa_genius = {0.0: 0, 0.5: 0, 1.0: 0, 1.5: 0.00020695912580412067, 2.0: 0.003333231686073502, 2.5: 0.009521767339060816, 3.0: 0.018687195740121218, 3.5: 0.028830351615459156, 4.0: 0.04526705705322381, 4.5: 0.06612336999248339, 5.0: 0.08812575861688295, 5.5: 0.11583745717312482, 6.0: 0.15219853573094508, 6.5: 0.20172045694111299, 7.0: 0.27150789741506437, 7.5: 0.35391720019527817, 8.0: 0.4622913614931918, 8.5: 0.5919298336690231, 9.0: 0.745118759874755, 9.5: 0.9122784919684522, 10.0: 1.08676680078877, 10.5: 1.287715797321462, 11.0: 1.512338162619219, 11.5: 1.7675260372507267, 12.0: 2.0681191382999096, 12.5: 2.3940624266951946, 13.0: 2.737544006272439, 13.5: 3.1087815224783606, 14.0: 3.5108582163929665, 14.5: 4.010858216393002, 15.0: 4.510858216392958} revenue_aa_ignorant = {0.0: -4.40496034368737, 0.5: -4.172988192068018, 1.0: -3.9410160404486883, 1.5: -3.709043888829351, 2.0: -3.4770717372099784, 2.5: -3.245099585590687, 3.0: -3.0131274339713245, 3.5: -2.781155282351995, 4.0: -2.5491831307326445, 4.5: -2.317210979113306, 5.0: -2.085238827493979, 5.5: -1.8532666758746175, 6.0: -1.6212945242552868, 6.5: -1.389322372635936, 7.0: -1.1573502210166053, 7.5: -0.925378069397257, 8.0: -0.6934059177779238, 8.5: -0.4614337661585748, 9.0: -0.22946161453924255, 9.5: 0.002510537080100763, 10.0: 0.2344826886994393, 10.5: 0.4664548403187788, 11.0: 0.6984269919381242, 11.5: 0.9303991435574558, 12.0: 1.162371295176803, 12.5: 1.3943434467961398, 13.0: 1.6263155984154816, 13.5: 1.8582877500348116, 14.0: 2.090259901654163, 14.5: 2.3222320532735257, 15.0: 2.554204204892843} class Group(BaseGroup): pass class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: category = itertools.cycle([i for i in range(1, 25)]) for player in self.get_players(): player.participant.vars['category'] = next(category) player.participant.vars['instruction_round'] = [1, Constants.round_per_game + 1, 2 * Constants.round_per_game + 1, 3 * Constants.round_per_game + 1] player.participant.vars['payround'] = random.choice([i for i in range(1, Constants.num_rounds+1) if i not in player.participant.vars['instruction_round']]) player.participant.vars['game_payment'] = 0 player.participant.vars['total_payment'] = self.session.config['participation_fee'] player.participant.vars['correct_num'] = 4*Constants.game_num player.participant.vars['correct_payment'] = 0 player.participant.vars['payin15'] = random.choice([i for i in range(1, 16)]) for player in self.get_players(): player.signal = c(Constants.signal_interval * random.randint(0, Constants.signal_num)) player.set_current_play() player.set_opponent() class Player(BasePlayer): bid = models.CurrencyField(label=False, blank=True) signal = models.CurrencyField() current_play = models.StringField() current_game = models.IntegerField() current_round = models.IntegerField() round_payoff = models.CurrencyField() confidence = models.FloatField() winner = models.IntegerField() no_winner = models.IntegerField() total_payment = models.CurrencyField() game_payment = models.CurrencyField() ignorant_payment = models.CurrencyField(initial=0) genius_payment = models.CurrencyField(initial=0) computer_payment = models.CurrencyField() self_payment = models.CurrencyField() genius_prob = models.IntegerField() computer = models.BooleanField() pay_or_not = models.IntegerField() pay_confidence = models.IntegerField() wrong_bid = models.IntegerField() opponent1 = models.CurrencyField() opponent2 = models.CurrencyField() opponent3 = models.CurrencyField() bid1 = models.CurrencyField() bid2 = models.CurrencyField() bid3 = models.CurrencyField() bid4 = models.CurrencyField() def set_current_play(self): if self.round_number <= Constants.num_rounds / Constants.game_num: self.current_game = 1 if self.participant.vars['category'] <= 6: self.current_play = 'fp' elif self.participant.vars['category'] <= 12: self.current_play = 'sp' elif self.participant.vars['category'] <= 18: self.current_play = 'aa' else: self.current_play = 'da' elif self.round_number <= 2*Constants.num_rounds / Constants.game_num: self.current_game = 2 if self.participant.vars['category'] in [7, 8, 13, 14, 19, 20]: self.current_play = 'fp' elif self.participant.vars['category'] in [1, 2, 15, 16, 21, 22]: self.current_play = 'sp' elif self.participant.vars['category'] in [3, 4, 9, 10, 23, 24]: self.current_play = 'aa' else: self.current_play = 'da' elif self.round_number <= 3*Constants.num_rounds / Constants.game_num: self.current_game = 3 if self.participant.vars['category'] in [9, 11, 15, 17, 21, 23]: self.current_play = 'fp' elif self.participant.vars['category'] in [3, 5, 13, 18, 19, 24]: self.current_play = 'sp' elif self.participant.vars['category'] in [1, 6, 7, 12, 20, 22]: self.current_play = 'aa' else: self.current_play = 'da' else: self.current_game = 4 if self.participant.vars['category'] in [10, 12, 16, 18, 22, 24]: self.current_play = 'fp' elif self.participant.vars['category'] in [4, 6, 14, 17, 20, 23]: self.current_play = 'sp' elif self.participant.vars['category'] in [2, 5, 8, 11, 19, 21]: self.current_play = 'aa' else: self.current_play = 'da' self.current_round = self.round_number - (self.current_game-1) * Constants.round_per_game - 1 def set_opponent(self): if self.current_play == "fp": opponent = random.choices(Constants.fpa_pool, weights=None, k=3) elif self.current_play == "sp": opponent = random.choices(Constants.spa_pool, weights=None, k=3) elif self.current_play == "aa": opponent = random.choices(Constants.aa_pool, weights=Constants.aa_weights, k=3) else: opponent = random.choices(Constants.da_pool, weights=Constants.da_weights, k=3) opponent.sort(reverse=True) self.opponent1 = opponent[0] self.opponent2 = opponent[1] self.opponent3 = opponent[2] def set_payoff(self): if self.round_number in self.participant.vars['instruction_round']: self.confidence = 0 self.genius_prob = random.randint(0, 100) self.computer = self.genius_prob >= self.confidence self.pay_or_not = random.randint(0, 100) self.pay_confidence = random.randint(0, 1) possible = [i*0.5 for i in range(0, 41)] if self.current_play == "sp": self.genius_payment = Constants.revenue_spa_genius[self.signal] self.ignorant_payment = Constants.revenue_spa_ignorant[self.signal] elif self.current_play == "fp": self.genius_payment = Constants.revenue_fpa_genius[self.signal] self.ignorant_payment = Constants.revenue_fpa_ignorant[self.signal] elif self.current_play == "aa": self.genius_payment = Constants.revenue_aa_genius[self.signal] self.ignorant_payment = Constants.revenue_aa_ignorant[self.signal] else: self.genius_payment = Constants.revenue_da_genius[self.signal] self.ignorant_payment = Constants.revenue_da_ignorant[self.signal] if self.bid is None or (self.bid not in possible and (self.current_play == "sp" or self.current_play == "fp")): self.game_payment = 0 self.winner = 0 self.round_payoff = -self.session.config['baseline_bonus'] if self.bid is not None: self.wrong_bid = 1 else: if self.bid > self.opponent1: self.winner = 1 else: self.winner = 0 self.round_payoff = 0 if self.bid == self.opponent1: self.no_winner = 1 bids = [self.bid, self.opponent1, self.opponent2, self.opponent3] bids.sort(reverse=True) self.bid1 = bids[0] self.bid2 = bids[1] self.bid3 = bids[2] self.bid4 = bids[3] if (self.current_play == "aa" or self.current_play == "sp") and self.winner == 1: self.round_payoff = self.signal - self.opponent1 elif (self.current_play == "da" or self.current_play == "fp") and self.winner == 1: self.round_payoff = self.signal - self.bid if self.pay_confidence == 1: if self.computer: self.computer_payment = Constants.scaler*(self.genius_prob*(self.session.config['baseline_bonus']+self.genius_payment) + (100-self.genius_prob)*(self.session.config['baseline_bonus']+self.ignorant_payment))/100 if self.pay_or_not <= self.computer_payment: self.game_payment = self.session.config['baseline_bonus'] else: self.game_payment = 0 else: self.self_payment = Constants.scaler*(self.round_payoff+self.session.config['baseline_bonus']) if self.pay_or_not <= self.self_payment: self.game_payment = self.session.config['baseline_bonus'] else: self.game_payment = 0 else: self.game_payment = self.round_payoff + self.session.config['baseline_bonus'] if self.round_number == self.participant.vars["payround"] and self.participant.vars['payin15'] == 1: self.participant.vars['game_payment'] = c(self.game_payment) self.total_payment = self.game_payment + self.session.config['participation_fee'] self.participant.vars['total_payment'] = c(self.total_payment) # def bid_error_message(self, value): # possible = [999] # i = 0 # while i <= 20: # possible.append(i) # i = i + 0.5 # if value is not None: # if value not in possible: # return "All bids must be between $0 and $20 and in 50 cent increments." qn_win = models.IntegerField( choices=[ [1, 'Alice'], [2, 'Bob'], [3, 'Clair'], [4, 'David'], ], widget=widgets.RadioSelect, blank=False, label="" ) qn_pay = models.IntegerField( choices=[ [1, '$20'], [2, '$21'], [3, '$22'], [4, '$23'], ], widget=widgets.RadioSelect, blank=False, label="" ) qn_lose = models.IntegerField( choices=[ [0, '$0'], [1, '$20'], [2, '$21'], [3, '$22'], ], widget=widgets.RadioSelect, blank=False, label="" ) qn_time = models.IntegerField( widget=widgets.RadioSelect, blank=False, label="" ) def qn_time_choices(player): if player.current_play == "da": choices = [ [1, 'I cannot save much time by clicking “Buy the Key” artificially early because I can only proceed to the next round after 30 seconds have passed from the start of the auction.'], [0, 'I can save a lot of time if I click “Buy the Key” artificially early.'], ] elif player.current_play == "aa": choices = [ [1, 'I cannot save much time by clicking “Stop Bidding” artificially early because I can only proceed to the next round after 30 seconds have passed from the start of the auction.'], [0, 'I can save a lot of time if I click “Stop Bidding” artificially early.'], ] else: choices = [ [1, 'I can only submit my bids at least 30 seconds after the start of the auction.'], [0, 'I can submit my bids immediately after the start of the auction.'], ] return choices qn_lose_got_wrong = models.BooleanField(initial=False) qn_win_got_wrong = models.BooleanField(initial=False) qn_pay_got_wrong = models.BooleanField(initial=False) qn_time_got_wrong = models.BooleanField(initial=False) failed_comprehension_auction = models.BooleanField(initial=False)