import numpy as np
class masu:
def win(self):
mm=self.mode
if mm=="先手":
self.mode="後手"
if mm=="後手":
self.mode="先手"
if self.hand[0]=="後手":
self.mode="後手勝利"
if self.hand[3]=="先手":
self.mode="先手勝利"
def change(self):
c=[]
for i in range(10):
c.append(0)
for i in range(6):
sx=self.pos_ch[i]
c[sx]=c[sx]+1
ch=0
for i in range(6):
h=0
p3=self.pos_ch[i]
if c[p3]>1:
h=100
if self.hand_ch[i]==self.mode:
h=0
if h>50:
self.pos_ch[i]=0
self.hand_ch[i]=self.mode
def select(self):
koma_sel=[]
for u in range(6):
h=0
if self.hand[u]==self.mode:
h=h+1
if self.pos[u]>0:
h=h+1
if h==2:
koma_sel.append(u)
return koma_sel
def makedir(self,h1,k1):
dir=[]
if k1=="王":
dir.append([1,1])
dir.append([1,-1])
dir.append([-1,1])
dir.append([-1,-1])
dir.append([1,0])
dir.append([0,1])
dir.append([-1,0])
dir.append([0,-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])
h=0
if k1=="金":
h=h+1
if h1=="先手":
h=h+1
if h==2:
dir.append([0,1])
dir.append([0,-1])
dir.append([1,0])
dir.append([-1,0])
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])
dir.append([0,-1])
dir.append([1,0])
dir.append([-1,0])
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])
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])
dir.append([1,-1])
dir.append([-1,-1])
dir.append([-1,1])
dir.append([1,1])
return dir
def point(self,d):
m=-1
for i in range(10):
if self.ban[i]==d:
m=i
return m
def check(self,pon):
c=[]
for i in range(10):
c.append(0)
for i in range(6):
if self.hand[i]==self.mode:
sx=pon[i]
c[sx]=c[sx]+1
ch=0
for i in range(1,10):
if c[i]>1:
ch=100
return ch
def makedata(self):
koma_sel=self.select()
sig=[]
for u in koma_sel:
dir=self.makedir(self.hand[u],self.koma[u])
n=self.pos[u]
for d in dir:
x1=self.ban[n][0]+d[0]
y1=self.ban[n][1]+d[1]
b1=[x1,y1]
nx=self.point(b1)
if nx>0:
su=[]
for p1 in self.pos:
su.append(p1)
su[u]=nx
sig.append(su)
bus=[]
for sp in sig:
if self.check(sp)<50:
bus.append(sp)
sum_hand=[]
sum_pos=[]
for car in bus:
self.pos_ch=[]
self.hand_ch=[]
for i in range(6):
self.pos_ch.append(car[i])
self.hand_ch.append(self.hand[i])
self.change()
sum_hand.append(self.hand_ch)
sum_pos.append(self.pos_ch)
num=len(sum_pos)
n1=np.random.choice(range(num))
for i in range(6):
self.hand[i]=sum_hand[n1][i]
self.pos[i]=sum_pos[n1][i]
self.win()
最終更新:2018年01月15日 08:46