Kaggle - ConnectX(2) - 4枚そろえるボードゲーム

Connect Xコンペに関する2回目の記事です。

Connect X

今回はエージェントが受け取る情報を確認したいと思います。

環境ルール(Environment Rules)

サンプルソースを見ますと下記のようなコメントが記述されていました。

[サンプルソース]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def agent(observation, configuration):
# Number of Columns on the Board.(ボードのカラム数)
columns = configuration.columns
# Number of Rows on the Board.(ボードの行数)
rows = configuration.rows
# Number of Checkers "in a row" needed to win.(勝つために並べるコインの数)
inarow = configuration.inarow
# The current serialized Board (rows x columns).(現在のボードの状態。1次元として)
board = observation.board
# Which player the agent is playing as (1 or 2).(どちらのプレイヤーか)
mark = observation.mark

# Return which column to drop a checker (action).(どのカラムに落とすかを返す)
return 0

確認のために、前回作成したソースにエージェントが受け取る情報を表示する処理を追加し実行してみます。

[ソース]

1
2
3
4
5
6
7
8
9
10
11
def my_agent(observation, configuration):
print('observation', observation)
print('configuration', configuration)
print('------------')
from random import choice
return choice([c for c in range(configuration.columns) if observation.board[c] == 0])

env.reset()
# Play as the first agent against default "random" agent.
env.run([my_agent, "random"])
env.render(mode="ipython", width=500, height=450)

[結果]
(一部表示)

サンプルソースの説明に合致した情報が格納されていることが分かります。

そのほかの情報(stepやtimeoutなど)もありますが、必要に応じて参照すればいいと思います。

ポイントとしては、observation.boardでしょうか。

6行7列の配列を1次元配列で表しています。この方が機械学習のデータとして扱いやすいですからね。