2回実行され、値がなくエラーが発生する

実現したいこと

ポケモンバトルをモンテカルロで実行したい。

前提

ポケモンのバトル環境をpythonで作成しています。

発生している問題・エラーメッセージ

エラーメッセージ 味方すばやさ 65 --------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[13], line 60 58 # VSランダム 59 next_actions = (mcts_action, random_action) ---> 60 evaluate_algorithm_of('VS_Random {:.3f}', next_actions) 62 # VSアルファベータ法 63 #next_actions = (mcts_action, alpha_beta_action) 64 #evaluate_algorithm_of('VS_AlphaBeta {:.3f}', next_actions) Cell In[13], line 46, in evaluate_algorithm_of(label, next_actions) 43 for i in range(EP_GAME_COUNT): 44 # 1ゲームの実行 45 if i % 2 == 0: ---> 46 total_point += play(next_actions) 47 else: 48 total_point += 1 - play(list(reversed(next_actions))) Cell In[13], line 29, in play(next_actions) 27 else: 28 next_action = next_actions[1] ---> 29 action = next_action(state) 31 # 次の状態の取得 32 state = state.next(action) Cell In[5], line 77, in mcts_action(state) 75 # 現在の局面のノードの作成 76 root_node = Node(state) ---> 77 root_node.expand() 79 # 100回のシミュレーションを実行 80 for _ in range(100): Cell In[5], line 56, in mcts_action.<locals>.Node.expand(self, tekiaction) 54 self.child_nodes = [] 55 for action in legal_actions: ---> 56 self.child_nodes.append(Node(self.state.next(action))) Cell In[12], line 174, in State.next(self, action) 171 ukeruHP=self.HP_count(action+1) 173 kougekiHP=self.mikata1HP if self.i%2 == 1 else self.teki1HP --> 174 return State(ukeruHP,kougekiHP) Cell In[12], line 24, in State.__init__(self, mikatapokemon, tekipokemon) 21 #print("敵",teki) 23 mikatasubayasa1=mikata["すばやさ"].values ---> 24 mikatasubayasa1=mikatasubayasa1[0] #ここがおかしい 25 print("味方すばやさ",mikatasubayasa1) 26 mikatakougeki1=mikata["こうげき"].values IndexError: index 0 is out of bounds for axis 0 with size 0

該当のソースコード

ソースコード 補足に書きました

試したこと

エラー内容を確認しました。2回実行されていて2回目は味方素早さに値が代入されないことがわかりました。

補足情報(FW/ツールのバージョンなど)

jupyternotebook
python 3.10.9
macbook air 2018

参考

AlphaZero 深層学習・強化学習・探索 人工知能プログラミング実践入門

コメントを投稿

0 コメント