You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document defines how to define a Model-View-Controller game using the Ajiaco-Social Experiment Framework. This document only aims the
syntax to be used to define the game and not the internal implementation
details.
Also some definition will be referenced to the oTree
documentation to be used as inspiration.
Game definition
The game is defined as an instance of the class ajiaco.Game. This instance
contains all the configuration utilities to run the game and a series of
constants defined by the user. For example if we wan to define the Matching Pennies Game from the oTree Tutorial
Example:
# we import the ajiaco module as ajcimportajiacoasajc# we define the game and store it into the# game variablegame=ajc.Game(
"mpennies", display="Matching Pennies",
groups_size=2, rounds=4, demo_participants=2,
stakes=100)
The Game class only has one required parameter called name. Name is
the unique string that identify the game inside the project. This value will
be prefixed in every database table (in our case the internal name of the
player model will be mpennies_player) and will be used to create the
urls to navigate the experiment.
From the oTree point of view this value replaces the SESSIONS_CONFIG name key and the Constants.name_in_url value.
Optional parameters
display the name to be displayed in the Ajiaco Admin and demo
interface. By default is the same values as name.
oTree SESSIONS_CONFIGdisplay_name key
group_size The number of player of the groups (default None). If
The value is None all the players are in only one group, and also
the programmer can manipulate the players manually to make arbitrary number
of groups whit arbitrary sizes.
Equivalent to oTree Constants.players_per_group
rounds The number of times to repeat this game (default 1)
Equivalent to oTree Constants.num_rounds
demo_participants How many participants are needed to create a
game for the demo page. By default is the number needed to fill a group.
Constants
The Game class also accept any another parameter and store it as constant
inside the game instance. For example the stakes=100.
Accessing the parameters and constants
The game configuration is reand only and you can access any value as regular
attribute of any Python object. Example
game.namegame.displaygame.stakesgame.name="foo"# this will failgame.nonexistent_constant="foo"# this also will fail
Models
Ajiaco offers 4 model to store your data
Game.participants_storage Data about the participant of the game
Game.sessions_storage Data about all the sessions of the game.
Game.rounds_storage Data about the rounds of all the sessions of
the game.
Game.groups_storage Data about all groups inside every round of
every session.
Game.players_storage Data about the player of every group.
Defining custom data for the models.
To add attributes to the any of the models you need to call method add_fields just after the instantiation of the Game class. After this
Ajiaco will prevent any attempt of the modification from inside any "hook"
or "page". The syntax of this method is:
For example if we want to continue with the oTree tutorial 3, and add the
suggested attributes is_winner, and tails inside the players; and paying_round inside the session, the code will be:
The hooks are functions to be executed in some special cases. In this
development stage only one hooks are designed the round creation hook
Session round creation hook
Equivalent to oTree Subsession.creating_session method.
Allows you to initialize the round, by setting initial values on fields on
players, groups, participants, or the rounds. For example to replicate
the same of the oTree tutorial 3:
@game.whendefcreating_round(session_round):
ifsession_round.is_first:
# ask if this round is the first# in this case a random round is selected and stored# inside the session paying_round attributepaying_round=random.randint(1, game.rounds)
session_round.session.paying_round=paying_roundelifsession_round.number==game.half_way:
# if the round number is the first of the second half# invert all the rolesmatrix=session_round.get_group_matrix()
forrowinmatrix:
row.reverse()
session_round.set_group_matrix(matrix)
elifsession_round.number>game.half_way:
# if the current round is higher than the first# of the second half, this simply copy the order of the# previous roundssession_round.group_like_round(game.half_way)
Pages
The final part of the game is design what the participant will see in their
screen. And this is defined (as before) as functions.
Forms
To create the tutorial requested choice page, Ajiaco suggest the next code:
@game.page.showdefchoice(page):
page.player.tails=page.ask(
"Choice tails or heads",
choices={"Tails": True, "Heads": False}
).check(
page.player.number==1andpage.player.tails==True,
"player number 1 can only choice 'tails'")
The line @game.page.show register the function choice as a page
inside the game.
The function registered as pages only receives one parameter called page.
The page parameter is utility that allow the user to send and
and retrieve data from the page HTML code (normally this is all hidden)
and also can access the current player, group, round and session that
are asking for the page.
The entire code of the function is only 1 line that create a form
(page.ask) that ask the user to select from a combo box between Heads and Tails. Also add to this form a validator that check (only
for show the functionality) that check if the player number 1 select tails.
The wait pages are decorated with the code @game.page.wait_for(...). The decorator always ask for the players
to wait. This can be the players of an entire group ("group"), or the
players of an entire round ("round")
Chen, D. L., Schonger, M., & Wickens, C. (2016). oTree—An open-source platform for laboratory, online, and field experiments. Journal of Behavioral and Experimental Finance, 9, 88-97.
The text was updated successfully, but these errors were encountered:
AEP 0001: The ajiaco game definition overview.
Rationale
This document defines how to define a Model-View-Controller game using the
Ajiaco-Social Experiment Framework. This document only aims the
syntax to be used to define the game and not the internal implementation
details.
Also some definition will be referenced to the oTree
documentation to be used as inspiration.
Game definition
The game is defined as an instance of the class
ajiaco.Game
. This instancecontains all the configuration utilities to run the game and a series of
constants defined by the user. For example if we wan to define the
Matching Pennies Game from the oTree Tutorial
Example:
The
Game
class only has one required parameter calledname
. Name isthe unique string that identify the game inside the project. This value will
be prefixed in every database table (in our case the internal name of the
player model will be mpennies_player) and will be used to create the
urls to navigate the experiment.
Optional parameters
display
the name to be displayed in the Ajiaco Admin and demointerface. By default is the same values as
name
.group_size
The number of player of the groups (defaultNone
). IfThe value is
None
all the players are in only one group, and alsothe programmer can manipulate the players manually to make arbitrary number
of groups whit arbitrary sizes.
rounds
The number of times to repeat this game (default1
)demo_participants
How many participants are needed to create agame for the demo page. By default is the number needed to fill a group.
Constants
The Game class also accept any another parameter and store it as constant
inside the game instance. For example the
stakes=100
.Accessing the parameters and constants
The game configuration is reand only and you can access any value as regular
attribute of any Python object. Example
Models
Ajiaco offers 4 model to store your data
Game.participants_storage
Data about the participant of the gameGame.sessions_storage
Data about all the sessions of the game.Game.rounds_storage
Data about the rounds of all the sessions ofthe game.
Game.groups_storage
Data about all groups inside every round ofevery session.
Game.players_storage
Data about the player of every group.Defining custom data for the models.
To add attributes to the any of the models you need to call method
add_fields
just after the instantiation of the Game class. After thisAjiaco will prevent any attempt of the modification from inside any "hook"
or "page". The syntax of this method is:
Where field type can be the Python classes:
int
: integersfloat
: floating point numbers.string
: textbool
:True
orFalse
.list
: a sorted sequencedict
: a map.ajiaco.binary
: binary data.ajiaco.money
: currency values.For example if we want to continue with the oTree tutorial 3, and add the
suggested attributes
is_winner
, andtails
inside the players; andpaying_round
inside the session, the code will be:Hooks
The hooks are functions to be executed in some special cases. In this
development stage only one hooks are designed the round creation hook
Session round creation hook
Allows you to initialize the round, by setting initial values on fields on
players, groups, participants, or the rounds. For example to replicate
the same of the oTree tutorial 3:
Pages
The final part of the game is design what the participant will see in their
screen. And this is defined (as before) as functions.
Forms
To create the tutorial requested choice page, Ajiaco suggest the next code:
@game.page.show
register the functionchoice
as a pageinside the game.
page
.page
parameter is utility that allow the user to send andand retrieve data from the page HTML code (normally this is all hidden)
and also can access the current player, group, round and session that
are asking for the page.
(
page.ask
) that ask the user to select from a combo box betweenHeads and Tails. Also add to this form a validator that check (only
for show the functionality) that check if the player number 1 select tails.
Wait Pages
@game.page.wait_for(...)
. The decorator always ask for the playersto wait. This can be the players of an entire group (
"group"
), or theplayers of an entire round (
"round"
)Simple information pages with skip
In this case the page will be skipped whit
page.skip()
(equivalent tooTree
Page.is_displayed()
) if the current round is not the last one.Otherwise the page render the list of previous selections.
Future functionalities
Timer
The timer can be implemented as an optional parameter of the decorator
page.show. For example
Helpers
Maybe we can implement helpers to create tables without using the template
language something like
Accessing common attributes of the page
Functionalities like
page.set_title
can be easily implemented to thepage.
References
The text was updated successfully, but these errors were encountered: