功能最强大的行为研究和实验平台。

The most powerful platform for behavioral research and experiments.

oTree 是什么

oTree 是一个用于网络交互任务的开源平台,适用于以下方面:

  • 心理学实验
  • 多人游戏
  • 拍卖市场
  • 策略游戏
  • 动态问卷或调查
  • 评估和测试

oTree 已被应用于超过 1500 篇学术出版物中。

为什么使用 oTree?

多功能性
oTree 是少数既用户友好又多功能的框架之一。你可以用它构建从井字游戏到实时拍卖市场的任何东西。

简便
oTree 仅限于最基本的编程概念:if语句、循环、简单函数、列表和字典。

适合学习
oTree 是学习编程的有趣方式。同时,它也是经济学或心理学等科目课程中的绝佳实践补充。

演示教程

正如 Python 是一种高级语言,oTree 也是一个高级框架。你不需要了解 HTTP、SQL 等所有细枝末节。立刻开始,快速构建有趣的东西吧!

清晰的代码

class C(BaseConstants):
    PLAYERS_PER_GROUP = 2
    NUM_ROUNDS = 10

玩家将自动被分成两人一组,并且游戏将重复进行 10 轮。

class Player(BasePlayer):
  contribution = models.CurrencyField(min=0, max=100)
  opt_out = models.BooleanField()

在这里,我们定义了数据库表的列。

class Contribute(Page):
  timeout_seconds = 60
  form_model = 'player'
  form_fields = ['contribution']

  @staticmethod
  def is_displayed(player):
    return player.id_in_group == 1

这个页面的时间限制为 60 秒,并且只对第一位玩家显示。

class WaitForOthers(WaitPage):
  @staticmethod
  def after_all_players_arrive(group):
    p1, p2 = group.get_players()
    p1.payoff = p1.contribution
    p2.payoff = 100 - p1.contribution

多人游戏非常简单。只需在游戏中添加一个等待页面(WaitPage),它将自动同步玩家,在此时刻你可以进行计算。

class Results(Page):
  form_model = 'player'
  form_fields = ['opt_out']

  @staticmethod
  def app_after_this_page(player, upcoming_apps):
    if player.opt_out:
      return 'questionnaire'

这个页面为用户提供了一个选择,可以完成当前部分,或者跳转到您的其他应用之一(例如问卷)。

page_sequence = [Contribute, WaitForOthers, Results]

将页面串联起来

app_sequence = ['trust_game', 'questionnaire']

将应用串联起来

动态模板

使用动态标签、HTML 和 CSS 设计您的用户界面。

Please answer the following questions.
{{ formfields }}

You may chat with other users here:
{{ chat }}

内置组件,如聊天框和自动表单布局。

{{ if player.payoff > 0 }}
  Congrats, you made {{ player.payoff }}{{ else }}
  You did not make any money.
{{ endif }}

条件逻辑

高级用户功能

yield Survey, dict(name='Bob', age=20)
yield Auction, dict(bid=random.randint(100, 200))
yield Results

使用机器人测试您的应用程序,它们可以并行运行,以在多人游戏中相互对抗。您可以编程不同的机器人策略,并运行多智能体模拟。

class Auction(Page):
  @staticmethod
  def live_method(player, bid):
    group = player.group
    if bid > group.highest_bid:
      group.highest_bid = bid
      return {
        0: dict(msg='New high bid!', bid=bid)
      }
    else:
      my_id = player.id_in_group
      return {
        my_id: dict(msg='Your bid was too low.')
      }

实时页面允许玩家在同一页面上实时互动。使用玩家的ID向特定玩家发送消息,或使用特殊的ID 0向整个组广播。

开始吧

$ pip install otree
$ otree startproject myproject
$ cd myproject
$ otree devserver

Categories:

Tags:

3 Responses

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注