I've coded a game in oTree for research purposes and the code below does exactly what I intend. The problem is that some games have over 100 rounds so you can see how the code could get ridiculously long. For people who are going to use this code in the future, it is practically unreadable in its current form. Any ideas on how I could condense this into a simpler if statement?
If you are unfamiliar with oTree, the "participant" signifier is essentially a way to pass data across rounds. The "player" reflects the participant specific to a round number. So each round I need to save their current round return (player.r#) and call the returns of all past rounds (participant.r#-1).
if subsession.round_number == 1:
participant = player.participant
participant.r1 = round(100 * asset, 3) + 100
player.r1 = participant.r1
elif subsession.round_number == 2:
participant = player.participant
participant.r2 = round(participant.r1 * asset, 3) + participant.r1
player.r1 = participant.r1
player.r2 = participant.r2
elif subsession.round_number == 3:
participant = player.participant
participant.r3 = round(participant.r2 * asset, 3) + participant.r2
player.r1 = participant.r1
player.r2 = participant.r2
player.r3 = participant.r3
elif subsession.round_number == 4:
participant = player.participant
participant.r4 = round(participant.r3 * asset, 3) + participant.r3
player.r1 = participant.r1
player.r2 = participant.r2
player.r3 = participant.r3
player.r4 = participant.r4
elif subsession.round_number == 5:
participant = player.participant
participant.r5 = round(participant.r4 * asset, 3) + participant.r4
player.r1 = participant.r1
player.r2 = participant.r2
player.r3 = participant.r3
player.r4 = participant.r4
player.r5 = participant.r5