oTree Forum >

Ultimatum Strategy Method - More Demos

#1 by JuergenMR

Hi Chris, 

I am looking for an Ultimatum Game with Strategy Method; when I play this https://www.otreehub.com/projects/otree-more-demos/ I have only one choice per player (either Proposer or Responder); when I look at the code and take @staticmethod in P1 and P2 out. The fields for the slower player are already prefilled. Am I doing anything wrong? 

I would like to play the game where each player first chooses what she would give as a proposer, then what she would give as a receiver (without seeing what the other player chose). Do you understand what I am looking for? Did I just get it wrong?

Thanks for your reponse

#2 by Chris_oTree

Move those fields from the Group level to the Player level, since every player has to answer them.

#3 by JuergenMR

thanks for the quick reply! this works, but now I do not get the payoff right :( do you have a quick solutions for this? they are calculated at group level

#4 by JuergenMR

Hi Chris, I am still struggling with this issue :( I can easily switch to the strategy method if I remove @staticmethod (see below) from page 1 and page 2.

However, the choices will pe prefilled for the player who fills in the form second. If I move the choices to player level. I do not get the payoffs right at all :( is there a quick fix for this? 

Anyone else who can help me? I assume it is rather simple but I'm just not getting it :(

Page 1
 #   @staticmethod
 #   def is_displayed(player: Player):
 #       return player.id_in_group == 1
 Page 2
  #  @staticmethod
  #  def is_displayed(player: Player):
  #      return player.id_in_group == 2

#5 by aseyq

Hi JuergenMR, 

It would be helpful if you could also post the set_payoff function. I found it in the file though. (I should note that don't forget to remove "is_displayed" conditions because both players should see both pages. 

So, first, you need a random device to determine who is the proposer and who is the responder. Then you need to rewrite your set payoff functions. Also, it is helpful to create another field to keep track of who is the proposer and who is the responder. Then you need to change group attributes to player attributes in the function.

I am writing off the top of my head, so it might not work right away but you get the idea.

import random

def set_payoffs(group: Group):
    players = group.get_players()
    random.shuffle(players) ## this will determine who is proposer and who is responder.
                            ## first player is gonna be proposer
                            ## this should work but double check whether it messes something up 
                            ## since list modifications are tricky in python
                            ## but in any case one random player object will be proposer and the other responder
    proposer, responder = players
    ## record the roles
    proposer.is_proposer = True
    responder.is_proposer = False
    amount_offered = proposer.amount_offered
    responder.offer_accepted = getattr(responder, 'response_{}'.format(int(amount_offered)))
    if responder.offer_accepted:
        proposer.payoff = C.ENDOWMENT - amount_offered
        responder.payoff = amount_offered
        proposer.payoff = 0
        responder.payoff = 0

#6 by JuergenMR

Wow! thank you! That is great! It is not 100% working yet, but I do get the idea! Thank you very much for your support! I will post the code as soon as I have it running!

Write a reply

Set forum username