def select(m1):
kon=[]
for u in range(6):
h=0
if hand[u]==m1:
h=h+1
if pos[u]>0:
h=h+1
if h==2:
kon.append(u)
return kon
def makedir(h1,k1):
dir=[]
if k1=="王":
dir.append([1,0])
dir.append([-1,0])
dir.append([0,1])
dir.append([0,-1])
dir.append([1,1])
dir.append([1,-1])
dir.append([-1,1])
dir.append([-1,-1])
h=0
if k1=="歩":
h=h+1
if h1=="先手":
h=h+1
if h==2:
dir.append([0,1])
h=0
if k1=="歩":
h=h+1
if h1=="後手":
h=h+1
if h==2:
dir.append([0,-1])
return dir
def pol(mode):
k=select(mode)
sig=[]
for k1 in k:
dir=makedir(hand[k1],koma[k1])
for d in dir:
p1=pos[k1]
x1=ban[p1][0]+d[0]
y1=ban[p1][1]+d[1]
b1=[x1,y1]
px=-1
if b1 in ban:
px=ban.index(b1)
pon=[0,0,0,0,0,0]
for u in range(6):
pon[u]=pos[u]
pon[k1]=px
if px>0:
sig.append(pon)
return sig
def check(mode,px):
c=[]
for i in range(6):
if hand[i]==mode:
c.append(px[i])
cou=[0,0,0,0,0,0,0,0,0,0]
for c1 in c:
cou[c1]=cou[c1]+1
ch=0
for i in range(1,7):
if cou[i]>1:
ch=100
return ch
def change(mode,px,hx):
c=[]
for i in range(6):
if hx[0][i]==mode:
c.append(px[i])
cou=[0,0,0,0,0,0,0,0,0,0]
for c1 in c:
cou[c1]=cou[c1]+1
mm="先手"
if mode=="先手":
mm="後手"
for i in range(6):
p1=px[i]
h=0
if hx[i]==mm:
h=h+1
if cou[p1]>1:
h=h+1
if h==2:
hx[i]==mode
px[i]=0
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]]
sig=pol(mode)
posx=[]
for s in sig:
ch=check(mode,s)
if ch<50:
posx.append(s)
print(posx)
handx=[]
handx.append(hand)
change(mode,posx[0],handx[0])
最終更新:2018年01月06日 17:01