アットウィキロゴ

しぃいい

import numpy as np
 
class step:
 
    def change(self,mode,ps,hs):
 
        c=[]   
        for i in range(10):
            c.append(0)
 
        for i in range(6):
            sx=ps[i]
            c[sx]=c[sx]+1
 
        ch=0
        for i in range(6):
            h=0
            p3=ps[i]
            if c[p3]>1:
               h=100
            if hs[i]==mode:
               h=0
            if h>50:
               ps[i]=0
               hs[i]=mode   
 
    def check(self,mode,po):
 
        c=[]   
        for i in range(10):
            c.append(0)
 
        for i in range(6):
            if self.hand[i]==mode:
               sx=po[i]
               c[sx]=c[sx]+1
 
        ch=0
        for i in range(1,10):
            if c[i]>1:
               ch=100
 
        return ch                 
 
 
 
 
    def point(self,d):
 
        m=-1  
        for i in range(10):
           if self.ban[i]==d:
              m=i
 
        return m       
 
 
 
    def select(self,mode):
 
        koma_select=[]
 
        for u in range(6):
           h=0
           if self.hand[u]==mode:
              h=h+1
           if self.pos[u]>0:
              h=h+1
           if h==2:       
              koma_select.append(u)
 
        return koma_select         
 
    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])
 
        return dir
 
    def makedata(self):
 
 
        delta=[]
 
        koma_select=self.select(self.mode)
 
        for k1 in koma_select:
            kk=self.koma[k1]
            dir=self.makedir(self.mode,kk)
            for d1 in dir:
                p1=self.pos[k1]
                px=self.ban[p1][0]+d1[0]
                py=self.ban[p1][1]+d1[1]
                p=[px,py]
                p2=self.point(p)
            sig=[]
            for p1 in self.pos:
                sig.append(p1)
            sig[k1]=p2
 
            if p2>0:
               delta.append(sig)
 
        de=[]
        for dd in delta:
            ch=self.check(self.mode,dd)
            if ch<50:
               de.append(dd)  
 
        hand_ch=[]
        pos_ch=[]
 
        for dd in de:
 
            ps=[]
            hs=[]
            for pc in dd:
               ps.append(pc)
            for hc in self.hand:
                hs.append(hc)
 
            self.change(self.mode,ps,hs)    
 
            hand_ch.append(hs)
            pos_ch.append(ps)
 
 
 
        num=len(pos_ch)
 
        card=[]
        for i in range(num):
            card.append(i)
 
        n1=np.random.choice(card)
 
        for i in range(6):
            self.pos[i]=pos_ch[n1][i]
            self.hand[i]=hand_ch[n1][i]
 
 
        mm=self.mode
 
        if mm=="先手":
           self.mode="後手"
        if mm=="後手":
           self.mode="先手" 
最終更新:2018年01月13日 07:17