import policy
import numpy as np
def check(mode,pos_ex,hand_ex):
cou=[0,0,0,0,0,0,0,0,0,0]
for i in range(6):
p1=pos_ex[i]
if hand_ex[i]==mode:
cou[p1]=cou[p1]+1
ch=0
for i in range(9):
if cou[i]>1:
ch=100
return ch
def change(mode):
cou=[0,0,0,0,0,0,0,0,0,0]
for i in range(6):
p1=pos_ex[i]
if hand_ex[i]==mode:
cou[p1]=cou[p1]+1
mm="先手"
if mode=="先手":
mm="後手"
for i in range(6):
p1=pos_ex[i]
h1=hand_ex[i]
h=0
if h1==mm:
h=h+1
if cou[p1]>0:
h=h+1
if h==2:
pos_ex[i]=0
hand_ex[i]=mode
mode="先手"
koma=["王","歩","歩","王","歩","歩"]
hand=["先手","先手","先手","後手","後手","後手"]
pos=[2,1,3,8,7,9]
ban=[[0,0],[1,1],[2,1],[3,1],[1,2],[2,2],[3,2],[1,3],[2,3],[3,3]]
delta=0
trs=0
while delta<50:
sub=policy.policy()
sub.koma=koma
sub.hand=hand
sub.pos=pos
sub.ban=ban
sig=sub.makedata(mode)
hand_pol=[]
pos_pol=[]
for ss in sig:
pos_ex=ss
hand_ex=hand
ch=check(mode,pos_ex,hand_ex)
change(mode)
if ch<50:
pos_pol.append(pos_ex)
hand_pol.append(hand_ex)
q=[]
n=0
for u in pos_pol:
q.append(n)
n=n+1
nx=np.random.choice(q)
mm=mode
if mm=="後手":
mode="先手"
if mm=="先手":
mode="後手"
hand=hand_pol[nx]
pos=pos_pol[nx]
print(pos)
print(hand)
if hand[0]=="後手":
delta=100
if hand[3]=="先手":
delta=100
trs=trs+1
if trs>10:
delta=100
最終更新:2018年01月06日 19:38