Skip to content

Commit

Permalink
Merge pull request #57 from stanmart/player-names
Browse files Browse the repository at this point in the history
Use more suggestive player names
  • Loading branch information
stanmart authored Apr 25, 2024
2 parents f680809 + 9e4bb3a commit bfd885e
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 78 deletions.
3 changes: 2 additions & 1 deletion _static/accept.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let numPlayers = 3;
let player_names = js_vars.player_names;

let pastOffersTable = document.getElementById('past-offers-table');

Expand All @@ -12,7 +13,7 @@ function populatePastOffers(pastOffers) {

let from = row.insertCell();
from.className = "offer-proposer-col";
from.innerHTML = `P${offer.player}`;
from.innerHTML = player_names[`P${offer.player}`];

for (let i = 0; i < numPlayers; i++) {
let cell = row.insertCell();
Expand Down
4 changes: 3 additions & 1 deletion _static/coalitions_demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
let numPlayers = 3;

let player_names = js_vars.player_names;

let totalShareable = document.getElementById('total-shareable');
let totalShared = document.getElementById('total-shared');

Expand Down Expand Up @@ -101,7 +103,7 @@ function updatePastOffers(newPastOffers) {

let from = row.insertCell();
from.className = "offer-proposer-col";
from.innerHTML = `P${offer.player}`;
from.innerHTML = player_names[`P${offer.player}`];

for (let i = 0; i < numPlayers; i++) {
let cell = row.insertCell();
Expand Down
2 changes: 1 addition & 1 deletion _static/live_bargaining.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ table.shaded-rows tbody tr:nth-child(odd) {
}

.otree-chat__nickname {
width: 120px;
width: 70px;
}

#payoff-table {
Expand Down
11 changes: 8 additions & 3 deletions _static/live_bargaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let pastOffers = []
let prod_fct = js_vars.prod_fct;
let prod_fct_labels = js_vars.prod_fct_labels;
let lastPlayerIsDummy = prod_fct.length == numPlayers - 1;
let player_names = js_vars.player_names;

let popupFull = document.getElementById('popup-full');
let popupTitle = document.getElementById('popup-title');
Expand Down Expand Up @@ -67,8 +68,12 @@ for (let i = 0; i < numPlayers; i++) {
}

function sendOffer() {
if (totalSharedValue > 0 && !isMemberCheckboxes[0].checked) {
openPopup('Invalid proposal: the budget is zero when Player 1 is not included in the group', 'error');
if (!lastPlayerIsDummy && totalSharedValue > 0 && !isMemberCheckboxes[0].checked) {
openPopup(`Invalid proposal: the budget is zero when Player ${player_names['P1']} is not included in the group`, 'error');
return;
}
if (lastPlayerIsDummy && totalSharedValue > 0 && !(isMemberCheckboxes[0].checked && isMemberCheckboxes[1].checked)) {
openPopup(`Invalid proposal: the budget is zero when Players ${player_names['P1']} and ${player_names['P2']} are not included in the group`, 'error');
return;
}
if (totalSharedValue > totalShareableValue) {
Expand Down Expand Up @@ -184,7 +189,7 @@ function updatePastOffers(newPastOffers) {

let from = row.insertCell();
from.className = "offer-proposer-col";
from.innerHTML = `P${offer.player}`;
from.innerHTML = player_names[`P${offer.player}`];

for (let i = 0; i < numPlayers; i++) {
let cell = row.insertCell();
Expand Down
11 changes: 8 additions & 3 deletions _static/proposal_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let pastOffers = []
let prod_fct = js_vars.prod_fct;
let prod_fct_labels = js_vars.prod_fct_labels;
let lastPlayerIsDummy = prod_fct.length == numPlayers - 1;
let player_names = js_vars.player_names;

let popupFull = document.getElementById('popup-full');
let popupTitle = document.getElementById('popup-title');
Expand Down Expand Up @@ -90,8 +91,12 @@ function sendOffer() {
'allocations': allocations,
};

if (totalSharedValue > 0 && !members[0]) {
openPopup('Invalid proposal: the budget is zero when Player 1 is not included in the group', 'error');
if (!lastPlayerIsDummy && totalSharedValue > 0 && !isMemberCheckboxes[0].checked) {
openPopup(`Invalid proposal: the budget is zero when Player ${player_names['P1']} is not included in the group`, 'error');
return;
}
if (lastPlayerIsDummy && totalSharedValue > 0 && !(isMemberCheckboxes[0].checked && isMemberCheckboxes[1].checked)) {
openPopup(`Invalid proposal: the budget is zero when Players ${player_names['P1']} and ${player_names['P2']} are not included in the group`, 'error');
return;
}
if (totalSharedValue > totalShareableValue) {
Expand Down Expand Up @@ -151,7 +156,7 @@ function updatePastOffers(newPastOffers) {

let from = row.insertCell();
from.className = "offer-proposer-col";
from.innerHTML = `P${offer.player}`;
from.innerHTML = player_names[`P${offer.player}`];

for (let i = 0; i < numPlayers; i++) {
let cell = row.insertCell();
Expand Down
20 changes: 10 additions & 10 deletions introduction/Coalitions.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h4> Group formation </h4>
All other players get 0.
<span style="color: #b70505; font-weight: bold;"> If there is no such agreement, all three players get 0. </span>
</p>
<p> Note that because Player 1 has to be included for a group to receive a budget, there will be one group at most.</p>
<p> Note that because Player {{P1}} has to be included for a group to receive a budget, there will be one group at most.</p>

<hr>

Expand Down Expand Up @@ -67,9 +67,9 @@ <h3>All proposals</h3>
<tr>
<th class="offer-id-col">ID</th>
<th class="offer-proposer-col">From</th>
<th class="offer-player-col player-1">P1</th>
<th class="offer-player-col player-2">P2</th>
<th class="offer-player-col player-3">P3</th>
<th class="offer-player-col player-1">{{P1}}</th>
<th class="offer-player-col player-2">{{P2}}</th>
<th class="offer-player-col player-3">{{P3}}</th>
</tr>
</thead>
<tbody id="past-offers-table"></tbody>
Expand All @@ -84,9 +84,9 @@ <h3>Choose a proposal </h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
</tr>
<tr style="height: 3em;">
<th class="offer-left-col">Accepted proposal <span class="red-highlight">ID</span></th>
Expand Down Expand Up @@ -149,9 +149,9 @@ <h3>Currently accepted proposal</h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
</tr>
<tr style="height: 3em;">
<th class="offer-left-col">Accept proposal <span class="red-highlight">ID</span></th>
Expand Down
20 changes: 10 additions & 10 deletions introduction/Proposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
<h4> Group budgets </h4>

<p>
You and the two other players will each be randomly assigned a player number ("Player 1/2/3").
<b> The player numbers will be reshuffled each round. </b>
You and the two other players will each be randomly assigned a player role ({{P1}}, {{P2}}, {{P3}}).
<b> The player roles will be reshuffled each round. </b>
</p>
<p>
<b>
A group needs to include Player 1 to receive any budget.
A group needs to include Player {{P1}} to receive any budget.
The more members a group has, the bigger the budget.
For the exact size of the budget in CHF, you will see a table and a corresponding graph like the one below ("Group budgets").
</p></b>

<p> </p>
<p> For example, if Player 1 and one other player form a group together, they have a budget of 50 CHF. If all players form a group together, they have a budget of 100 CHF. (The exact numbers might be different in the game.) </p>
<p> For example, if Player {{P1}} and one other player form a group together, they have a budget of 50 CHF. If all players form a group together, they have a budget of 100 CHF. (The exact numbers might be different in the game.) </p>



Expand Down Expand Up @@ -113,9 +113,9 @@ <h3>Past proposals</h4>
<tr>
<th class="offer-id-col">ID</th>
<th class="offer-proposer-col">From</th>
<th class="offer-player-col player-1">P1</th>
<th class="offer-player-col player-2">P2</th>
<th class="offer-player-col player-3">P3</th>
<th class="offer-player-col player-1">{{P1}}</th>
<th class="offer-player-col player-2">{{P2}}</th>
<th class="offer-player-col player-3">{{P3}}</th>
</tr>
</thead>
<tbody id="past-offers-table"></tbody>
Expand All @@ -132,9 +132,9 @@ <h3> Make a proposal </h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
<th style="text-align: right;">Total</th>
</tr>
<tr style="height: 3em;">
Expand Down
10 changes: 10 additions & 0 deletions introduction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,26 @@ def js_vars(player: Player):
prod_fct=list(player.session.config["prod_fct"].values()),
prod_fct_labels=list(player.session.config["prod_fct"].keys()),
my_id=1,
player_names=player.session.config["player_names"],
)

@staticmethod
def vars_for_template(player: Player):
return player.session.config["player_names"]


class Coalitions(Page):
@staticmethod
def js_vars(player: Player):
return dict(
my_id=1,
player_names=player.session.config["player_names"],
)

@staticmethod
def vars_for_template(player: Player):
return player.session.config["player_names"]


class Payment(Page):
pass
Expand Down
26 changes: 13 additions & 13 deletions live_bargaining/Bargain.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<ul>
<li>
Any subset of players can form a group.
A group needs to include Player 1 to receive any budget.
A group needs to include Player {{P1}} to receive any budget.
The more members a group has, the bigger the budget.
You see the budget sizes for this particular round on the right.
</li>

{{ if last_player_is_dummy }}
<li style="display: none;" class="dummy-instruction">The group's budget does not depend on Player 3's inclusion. They can still be included in any group.</li>
<li style="display: none;" class="dummy-instruction">The group's budget does not depend on Player {{P3}}'s inclusion. They can still be included in any group.</li>
{{ endif }}

<li>
Expand All @@ -38,7 +38,7 @@

</ul>

<b> This is <span class="red-highlight">round {{ actual_round_number }}</span>. You are <span style="color: #056fb7; font-weight: bold;">Player {{ player.id_in_group }}</span>.
<b> This is <span class="red-highlight">round {{ actual_round_number }}</span>. You are <span style="color: #056fb7; font-weight: bold;">Player {{ player_name }}</span>.


{{ if subsession.round_number == 1 }}
Expand Down Expand Up @@ -74,7 +74,7 @@

<div class="section vertical-fill highlight-section" style="width: 200px;">
<h3 class="highlight-section-title">Chat</h3>
{{ chat nickname=player.role }}
{{ chat nickname=player_name }}
</div>

<div class="section vertical-fill">
Expand All @@ -85,9 +85,9 @@ <h3>Past proposals</h4>
<tr>
<th class="offer-id-col">ID</th>
<th class="offer-proposer-col">From</th>
<th class="offer-player-col player-1">P1</th>
<th class="offer-player-col player-2">P2</th>
<th class="offer-player-col player-3">P3</th>
<th class="offer-player-col player-1">{{P1}}</th>
<th class="offer-player-col player-2">{{P2}}</th>
<th class="offer-player-col player-3">{{P3}}</th>
</tr>
</thead>
<tbody id="past-offers-table"></tbody>
Expand All @@ -104,9 +104,9 @@ <h3> Make a proposal</h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
<th style="text-align: right;">Total</th>
</tr>
<tr style="height: 3em;">
Expand Down Expand Up @@ -142,9 +142,9 @@ <h3>Currently accepted proposal</h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
</tr>
<tr style="height: 3em;">
<th class="offer-left-col">Accepted proposal <span class="red-highlight">ID</span></th>
Expand Down
12 changes: 6 additions & 6 deletions live_bargaining/BargainingResults.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ <h3>Accepted proposals</h2>
<tbody>
<tr>
<th></th>
<th class="offer-player-col player-1">Player 1</th>
<th class="offer-player-col player-2">Player 2</th>
<th class="offer-player-col player-3">Player 3</th>
<th class="offer-player-col player-1">Player {{P1}}</th>
<th class="offer-player-col player-2">Player {{P2}}</th>
<th class="offer-player-col player-3">Player {{P3}}</th>
</tr>
<tr style="height: 3em;">
<th class="offer-left-col">Accepted proposal ID</th>
Expand All @@ -45,9 +45,9 @@ <h3>All proposals</h4>
<tr>
<th class="offer-id-col">ID</th>
<th class="offer-proposer-col">From</th>
<th class="offer-player-col player-1">P1</th>
<th class="offer-player-col player-2">P2</th>
<th class="offer-player-col player-3">P3</th>
<th class="offer-player-col player-1">{{P1}}</th>
<th class="offer-player-col player-2">{{P2}}</th>
<th class="offer-player-col player-3">{{P3}}</th>
</tr>
</thead>
<tbody id="past-offers-table"></tbody>
Expand Down
2 changes: 1 addition & 1 deletion live_bargaining/Info.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p> <span style="color: #b70505; font-weight: bold;"> In this round, unlike in previous rounds, adding Player 5 has no impact on the budget. </span> </p>
{{ endif }}

<p> In this round you are <span style="color: #056fb7; font-weight: bold;">Player {{ player.id_in_group }}</span>. </p>
<p> In this round you are <span style="color: #056fb7; font-weight: bold;">Player {{ player_name }}</span>. </p>
Remember, payoffs are determined as follows:

<div style="width: 350px; align-content: center;">
Expand Down
Loading

0 comments on commit bfd885e

Please sign in to comment.