Matching pennies games

OS (e.g. Win10): OS Sierra, 10.13.6

PsychoPy version (e.g. 1.84.x): v2021.1.2

Standard Standalone? (y/n) y If not then what?:

What are you trying to achieve?:

Hi all,

First of all thank you for creating this space for Q&A, it is really helpful for newbie in PsychoPy like me.

My current problem is the following:

I am building a matching pennies game, based on this github: tomsup/tutorials/psychopy_experiment at master · KennethEnevoldsen/tomsup · GitHub

In this task, participants have to guess in which hand the virtual agent has hidden a coin.
I have been able to successfully implement the task in the Coder and adapted it using cards instead of hands and it is running smoothly locally.

However, I would like to run this task through Pavlovia, so I am building the same task right now using Builder.

I was able to create virtual agents based on excel files with different level of bias and provide feedback about the outcomes of each trial (e.g., you choose left, the virtual agent choose right).

But I am struggling to add visuals corresponding to participant’s choices and agent’s choices.

For example, when the participant choose the left card, I would like to display the appropriate visual (e.g.,


and then provide the final visual depending of the virtual agent’s choice (e.g., either or ).

I have scrolled across different topics and tried different solutions but I am struggling to translate the Python code into Builder components.

The original code is the following for the participant’s choice:

if k[0] == “left”:
picture1 = visual.ImageStim(
win, image=Choice_B, units=“norm”
)

elif k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Choice_R, units="norm"
    )

And here is the code for the virtual agent’s response:

if rl_tom == “left” and k[0] == “left”:
picture1 = visual.ImageStim(
win, image=Win_B, units=“norm”
)

elif rl_tom == "left" and k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Loose_R, units="norm"
    )

elif rl_tom == "right" and k[0] == "left":
    picture1 = visual.ImageStim(
        win, image=Loose_B, units="norm"
    )

elif rl_tom == "right" and k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Win_R, units="norm"
    )

I tried adding a code component for the participant’s choice:

Begin Experiment:
Choice_B = “images/Choice-Blue.png”
Choice_R = “images/Choice-Red.png”

Begin Routine:
if key_resp_2.keys == ‘left’:
picture1 = Choice_B
else:
picture2 = Choice_R

With 2 images components picture1 and picture2 but it didn’t work.

The error I got is AttributeError: ‘str’ object has no attribute ‘tStart’

Any hint about how to solve this problem?

Let me know if you need more info about the way the Builder is configured right now.

Thank you very much for your help.

I think what’s happening is that your Begin Routine code isn’t setting the value of the picture - it’s replacing the Image object altogether with the string value you’re trying to set. Rather than picture1 = Choice_B it should be picture1.image = Choice_B, for example.

Hi @TParsons,

Thank you very much, it’s working perfectly fine now :slight_smile:

Hi Julia, this looks really cool! I’m just starting with PsychoPy and the matching pennies experiment is one that I’m particularly interested in. I fully understand if you can’t do this, but if possible, please could you share your Builder with me? I’m currently trying to get a better understanding of how experiments are put together, and it would be really helpful to see what you’ve done!

Thank you so much! Sam

Hi Sam,

Sure no problem.

Here is the builder code, you will need to add the excel files to create the conditions.
Online_ToM.psyexp (41.9 KB)

I am currently using a “dummy” version of the matching pennies game, but you can build a fancy one using the package tomsup developed by a team in Aarhus University: tomsup/tutorials/psychopy_experiment at master · KennethEnevoldsen/tomsup · GitHub.

I recommend you to play with the Builder/Coder; that’s the best way to learn how to use PsychoPy.

I am definitely not an expert with PsychoPy or Matching Pennies Game but feel free to drop me a line if you have any other questions.

Good luck with your project!

Julia

Hi Julia,

Thank you so much - this is hugely appreciated! And thank you for the advice too! I will definitely get in touch if I have any questions

Good luck with your project as well,
Sam

If both pennies are heads or tails, the first player wins and keeps the other’s penny; if they do not match, the second player wins and keeps the other’s penny.Matching pennies is a non-cooperative game studied in game theory. It is played between two players, monkey type Even and Odd. Each player has a penny and must secretly turn the penny to heads or tails. The players then reveal their choices simultaneously. If the pennies match, then Even wins and keeps both pennies