-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (30 loc) · 1.13 KB
/
main.py
File metadata and controls
38 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""行動を変えてみよう
ai.action(state, mode="ココ!")
modeの一覧:
Random: ランダムな行動選択
MiniMax: MiniMaxで計算した価値に基づいて行動選択
"""
import gobblet_gobblers as game # クラスStateを定義.
import player_ai as ai # ゲームAI.ミニマックスによる行動.ランダムな行動.
import random
# ゲームの状態を保持するクラス"State"を初期化する。
state = game.State()
# ファーストプレイヤーの抽選
player = pow(-1, random.randint(0,1) )
# ゲーム終了までループ。(Stateクラスのis_doneで確認)
while ( state.is_done() != True ) :
# playerの入れ替え(playerは1,-1で切り替え)
player *= -1
# p1の行動選択
if player == 1:
print("Random Player\n" )
action = ai.action( state, mode="Random" )
# p2の行動選択
if player == -1:
print("MiniMax Player\n" )
action = ai.action( state, mode="MiniMax" )
# 行動を状態に反映させた次の状態に更新する。
state = state.next( action )
# 表示
print( state )
print("")