from otree.api import * from . import pages # class PlayerBot(Bot): # def play_round(self): # if self.group.round_number==1: # yield pages.Introduction # yield pages.Exploit, dict(exploitation=2) # 20210809 # __init__からPageクラスを読み込もうとするとうまくいかない # → __init__.pyの内容をpages.pyにコピペし、pages.pyからPageクラスを読み込むようにしたらうまくいった # 現在、途中でテストがとまるので、検証法を調べる # 20210810 # GameOver ページがとばされたため、botが混乱しているように見える → 修正 # Introduction ページは1ラウンド目だけ確認するよう修正 # → 完了 # 手順:devserver 立ち上げ後にlocalhost:8000 にアクセスし、デモモードでプレイヤー人数分のURLをたたくとデモ開始 # この方法だと、ゲーム終了時の状態を見ることができるものの、複数のケースを一度にためすことができない # PowerShell からbotを走らせることも可能 # tests.py をセット, settings.py の Session_Configにてbot有効化まではブラウザ経由と同じ # その後、PowerShell にて "pip3 install requests" を実行後 # "otree test Resource_Reproduction_2021" を実行(Session_Configのname値を使用) # ケースをいくつか作って順番に走らせるのを試してみる↓ # うまくいった! # class PlayerBot(Bot): # # cases = ['zero', 'one', 'two', 'three', 'four'] # # def play_round(self): # if self.group.round_number == 1: # yield pages.Introduction # # if self.case == 'zero': # yield pages.Exploit, dict(exploitation=0) # elif self.case == 'one': # yield pages.Exploit, dict(exploitation=1) # elif self.case == 'two': # yield pages.Exploit, dict(exploitation=2) # elif self.case == 'three': # yield pages.Exploit, dict(exploitation=3) # else: # yield pages.Exploit, dict(exploitation=4) # Expect() の使い方をためしてみる # 下のコードで、dict(exploitation=self.exp_value)の値を変えるとエラーがでることを確認 class PlayerBot(Bot): exp_value = 1 def play_round(self): if self.group.round_number==1: yield pages.Introduction yield pages.Exploit, dict(exploitation=self.exp_value) expect(self.player.resource, self.group.round_number*self.exp_value) #### コマンドラインからブラウザを立ち上げるボットテストの手順 # pip install requests # pip install ws4py # ののちに、Chromeを閉じた状態で # ひっつめのPSで otree devserver を実行し、別のPSで以下のコマンドを実行 # otree browser_bots Resource_Reproduction_2021 # を実行すると、自動的にブラウザが立ち上がってBotが動き始める # settings.py SESSION_CONFIGS の mock_exogenous_data=True はなくても大丈夫な模様 # devserver のほうのPSで大量のエラーが出ているが、ゲーム自体は無事終わった模様 # リアルタイムで観察すると、ゲーム進行中はエラーがでないため、ゲーム終了時に問題が起きていると推察