Conditions file - trials not by row (Iowa Gambling Task)

OS (Win10):
PsychoPy version (1.84.2):
Standard Standalone? y:
What are you trying to achieve?:

Apologies for the rather vague title but I cannot describe it otherwise.

I am trying to computerise the Iowa Gambling Task.If you imagine that you are a participant and you have 4 decks of cards (e.g. Decks A-D) in front of you, if you choose the top card from Deck A, the top cards from Decks B, C, D are not removed. Psychopy, however, removes the whole row in a conditions file (at least in the way I set it up).

I was wondering if there is a way to move between rows and columns based on what deck was chosen last. For instance, in my attached conditions file, if someone chooses Deck A the first 10 times (i.e. first 10 rows in the conditions file) and then Deck B on the 11th, this 11th trial should take the values from row 1, columns C and D which are for Deck B. And if they choose Deck A for the 12th trial then they should return to 11th row columns A & B for Deck A. Like in the image below:

I do not know if this makes sense at all.

I attach the .psyexp file and the conditions file. If you landed o this page looking for the IGT feel free to use it (only two decks at the moment but easy to expand).

I have only basic knowledge of Python but any help will be much appreciated.

CONDITIONS.xlsx (8.7 KB)
IGT.psyexp (30.8 KB)

How many trials total are there? How does the program know the experiment is finished? When all cards have been exhausted?

Currently the exp will end once the trials in the conditions file has been exhausted i.e. 40 trials. However the ultimate purpose is to have 160 conditions (i.e. rows) in the conditions file but end once the participant reaches 100 trials. This is as per original paper.

So this sounded like more fun than my real work, and I went a little overboard. Sorry if I ended up robbing you of the chance to struggle and learn more on your own …

The design that occurred to me was to have the stacks of cards represented as separate lists of dictionaries, and have a loop (call it “mytrials”) with no conditions file that runs 100 times. If they click on column A, then you .pop(0) the first dictionary out of the list for A, set your variables for stimuli with it, and call mytrials.addData() for each column you want to save to output files.

To do this you would modify the conditions file slightly, so that there are only three columns: DECK_NAME, EARNINGS, and LOSSES. Come to think of it (I didn’t do this here), you should also probably add a column with a unique number for each line, (and save it with .addData()) so you can always know when which card was shown.

I don’t know if you want the decks randomized, but all you would have to do would be import random, and call random.shuffle() on them.

Here’s the code I used to create the separate lists for each card stack:

allCards = data.importConditions("CONDITIONS.xlsx")
A_cards = filter(lambda x: x["DECK_NAME"] == "A", allCards)
B_cards = filter(lambda x: x["DECK_NAME"] == "B", allCards)

# the total number of trials. 
#You would set to 100 when ready
totalReps = 50

I have here what I believe is a working example of this. I did make some fairly heavy modifications to your code to accommodate this design.

For one I moved the code that is called whenever an image is clicked to a separate function, because it’s more difficult to maintain when you have near-identical code repeated several times.

I also changed a bit how the image files are loaded, since a deck could run out of cards, and you would want your participants to know this. So when a stack is empty, the image is changed (here I used a big red X).

Let me know what you think. Hopefully this is what you were looking for. If there’s anything you don’t quite get (since you’re new to python), or if I didn’t get, feel free to ask:

IGT.psyexp (33.6 KB)

CONDITIONS.xlsx (6.4 KB)


Hi daniel.riggs1,

That’s really great and it seems to be working the couple of times I ran it.

Not at all. Also, if I posted in this forum it means I reached my limit on what I can do with this exp.[quote=“daniel.riggs1, post:4, topic:1543”]
I don’t know if you want the decks randomized

Nope, the whole point in this task is to present the trials in a sequential manner.
Your response will actually “force me” to open and read that Python book that I bought some time ago :wink:

Once again, many thanks for the solution and your time. It is much appreciated. I hope others will find it useful too.

Hi, Yiannis
Can you share the code for the Iowa gambling task(IGT)?

1 Like

Can I get this code via a zip file by any chance? :slight_smile: