メソッドget_others_in_group() (https://otree.readthedocs.io/en/latest/multiplayer/groups.html)は、自分以外のグループメンバーを取得します。
それを使って、結果のフィードバック画面に他プレイヤーの選択と利得が表示される公共財ゲームを作りました。
これを作ります

Models.py
今回のゲームでは、協力 (貢献する) と非協力 (貢献しない) の二択、4人で行う設定にしました。
こちらのページ (https://github.com/akrgt/otree_2019KG/tree/master/2_SD) を参考にさせていただきました。
from otree.api import (
models,
widgets,
BaseConstants,
BaseSubsession,
BaseGroup,
BasePlayer,
Currency as c,
currency_range,
)
author = 'Mizuno'
doc = """
公共財ゲーム
"""
class Constants(BaseConstants):
name_in_url = 'pgg'
players_per_group = 4
num_rounds = 20
endowment = c(20)
multiplier = 1.6
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
total_contribution = models.CurrencyField()
individual_share = models.CurrencyField()
def compute(self):
contributions = [p.contribution for p in self.get_players()]
self.total_contribution = sum(contributions)
self.individual_share = self.total_contribution * Constants.multiplier / Constants.players_per_group
for p in self.get_players():
p.payoff = Constants.endowment - p.contribution + self.individual_share
class Player(BasePlayer):
contribution = models.CurrencyField(
choices=[
[c(Constants.endowment), '貢献する'],
[c(0), '貢献しない']
],
label="下のいずれかを選択し、クリックしてください。",
widget=widgets.RadioSelect
)
Pages.py
class Page2(Page) のところで、他のプレイヤーをそれぞれp1、p2、p3としています。例えばプレイヤー自身のIDが2のときはp1=ID1のプレイヤー、p2=ID3のプレイヤー、p2=ID4のメンバーとなります。
from otree.api import Currency as c, currency_range
from ._builtin import Page, WaitPage
from .models import Constants
class Page1(Page):
form_model = 'player'
form_fields = ['contribution']
class Wait(WaitPage):
def after_all_players_arrive(self):
self.group.compute()
class Page2(Page):
def vars_for_template(self):
p1,p2,p3 = self.player.get_others_in_group()
return dict(
p1 = p1,
p2 = p2,
p3 = p3
)
page_sequence = [
Page1,
Wait,
Page2
]
Page1.html
{% extends "global/Page.html" %}
{% load otree static %}
{% block title %}
{% endblock %}
{% block content %}
<center>
<p>
このラウンドで、{{ Constants.endowment }}をお渡しします。 <br>
この{{ Constants.endowment }}を使って、グループに貢献しますか?<br>
<br>
</p>
{% formfield player.contribution %}
{% next_button %}
</center>
{% endblock %}
Page2.html
{% extends "global/Page.html" %}
{% load otree static %}
{% block title %}
<center>結果</center>
{% endblock %}
{% block content %}
<center>
<p>
あなたがこのラウンドで獲得したトークンは<br><br>
<strong> {{ player.payoff }}</strong><br><br><br><br>
<table border='1'>
<tr><th>プレイヤー</th><th>選択</th><th>手元</th><th>分配額</th><th>合計</th>
</tr>
<tr>
<td>あなた</td>
<td>{% if player.contribution == Constants.endowment %}
貢献する
{% else %}
貢献しない
{% endif %}
<td>{% if player.contribution == Constants.endowment %}
0トークン
{% else %}
20トークン
{% endif %}
<td>{{group.individual_share}}
</td>
<td>{{player.payoff}}
</td>
</tr>
<tr>
<td>A</td>
<td>{% if p1.contribution == Constants.endowment %}
貢献する
{% else %}
貢献しない
{% endif %}
<td>{% if p1.contribution == Constants.endowment %}
0トークン
{% else %}
20トークン
{% endif %}
<td>{{group.individual_share}}
</td>
<td>{{p1.payoff}}
</td>
</tr>
<tr>
<td>B</td>
<td>{% if p2.contribution == Constants.endowment %}
貢献する
{% else %}
貢献しない
{% endif %}
<td>{% if p2.contribution == Constants.endowment %}
0トークン
{% else %}
20トークン
{% endif %}
<td>{{group.individual_share}}
</td>
<td>{{p2.payoff}}
</td>
</tr>
<tr>
<td>C</td>
<td>{% if p3.contribution == Constants.endowment %}
貢献する
{% else %}
貢献しない
{% endif %}
<td>{% if p3.contribution == Constants.endowment %}
0トークン
{% else %}
20トークン
{% endif %}
<td>{{group.individual_share}}
</td>
<td>{{p3.payoff}}
</td>
</tr>
</table>
<br>
</p>
{% next_button %}
</center>
{% endblock %}