アットウィキロゴ

ooo))

import game
 
def hash(m1,h1,p1):
 
        ha=""
        if m1=="先手":ha=ha+"w"
        if m1=="後手":ha=ha+"x"   
        if m1=="先手勝利":ha=ha+"y"
        if m1=="後手勝利":ha=ha+"z"
 
        for h2 in h1:
            if h2=="先手":ha=ha+"p"
            if h2=="後手":ha=ha+"q"   
 
        alp=["a","b","c","d","e","f","g","h","i","j"]
        for p2 in p1:
            ha=ha+alp[p2]
 
        return ha 
 
koma=["王","金","銀","王","金","銀"]
ban=[]
ban.append([0,0])
for y1 in [1,2,3]:
    for x1 in [1,2,3]:
        ban.append([x1,y1])
pos=[2,1,3,8,7,9] 
hand=["先手","先手","先手","後手","後手","後手"]
mode="先手"
 
hax=hash(mode,hand,pos)
 
sub=game.game()
sub.koma=koma
sub.ban=ban
sub.hash=hax
sub.makedata()
pol_hash=sub.pol_hash
 
han=[hax]
 
link_a=[]
link_b=[]
for p1 in pol_hash:
    link_a.append(hax)
    link_b.append(p1)
 
print(link_b)
 
han_trial=[]
for p1 in link_b:
    z=0
    if p1 in han:z=100
    if z<50:han_trial.append(p1)
 
han_dic=[]
for p1 in han_trial:
    z=0
    if p1 in han:z=100
    if z<50:han_dic.append(p1)
 
print(han_dic)
 
for hax in han_dic:
    sub2=game.game()
    sub2.koma=koma
    sub2.ban=ban
    sub2.hash=hax
    sub2.makedata()
    pol_hash=sub2.pol_hash
    for z in pol_hash:
        link_a.append(hax)
        link_b.append(z)
 
 
print(link_b)
 
import numpy as np
 
class game:
 
    def decode(self):
       self.hand=["","","","","",""]
       self.pos=[0,0,0,0,0,0]
       self.mode=""
       z1=self.hash[0]
       if z1=="w":self.mode="先手"
       if z1=="x":self.mode="後手"   
       if z1=="y":self.mode="先手勝利"
       if z1=="z":self.mode="後手勝利"
       for i in range(6):
            z1=self.hash[i+1:i+2]
            if z1=="p":self.hand[i]="先手"
            if z1=="q":self.hand[i]="後手"
       for i in range(6):
            z1=self.hash[i+7:i+8]
            if z1=="a":self.pos[i]=0
            if z1=="b":self.pos[i]=1
            if z1=="c":self.pos[i]=2
            if z1=="d":self.pos[i]=3
            if z1=="e":self.pos[i]=4
            if z1=="f":self.pos[i]=5
            if z1=="g":self.pos[i]=6
            if z1=="h":self.pos[i]=7
            if z1=="i":self.pos[i]=8
            if z1=="j":self.pos[i]=9
 
    def code(self,m1,h1,p1):
 
        ha=""
        if m1=="先手":ha=ha+"w"
        if m1=="後手":ha=ha+"x"   
        if m1=="先手勝利":ha=ha+"y"
        if m1=="後手勝利":ha=ha+"z"
 
        for h2 in h1:
            if h2=="先手":ha=ha+"p"
            if h2=="後手":ha=ha+"q"   
 
        alp=["a","b","c","d","e","f","g","h","i","j"]
        for p2 in p1:
            ha=ha+alp[p2]
 
        return ha 
 
 
    def win(self,mode,h1):
 
        mx=mode
        mx1=mx
        if mx1=="後手":mx="先手"
        if mx1=="先手":mx="後手"     
        if h1[0]=="後手":mx="後手勝利"
        if h1[3]=="先手":mx="先手勝利"     
 
        return mx
 
    def rev(self):
 
        pp=[0,0,0,0,0,0,0,0,0,0]
 
        for i in range(6):
            sx=self.pos_ch[i]
            pp[sx]=pp[sx]+1   
 
        ch=0
        for i in range(6):
            h=0
            sx=self.pos_ch[i]
            if pp[sx]>1:h=100
            if self.hand_ch[i]==self.mode:h=0    
            if h>50:self.hand_ch[i]=self.mode
            if h>50:self.pos_ch[i]=0    
 
    def check(self,px):
 
        pp=[0,0,0,0,0,0,0,0,0,0]
 
        for i in range(6):
            sx=px[i]
            if self.hand[i]==self.mode:pp[sx]=pp[sx]+1   
 
        ch=0
        for i in range(1,10):
            if pp[i]>1:ch=100
 
        return ch 
 
    def pointx(self,d):
 
        m=-1  
        for i in range(10):
           if self.ban[i]==d:
              m=i
        return m  
 
    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]) 
 
        h=0
        if k1=="桂":
           h=h+1
        if h1=="先手":
           h=h+1
        if h==2:
           dir.append([1,2])     
           dir.append([-1,2]) 
 
        h=0
        if k1=="桂":
           h=h+1
        if h1=="後手":
           h=h+1
        if h==2:
           dir.append([1,-2])     
           dir.append([-1,-2])
 
        h=0
        if k1=="香":
           h=h+1
        if h1=="先手":
           h=h+1
        if h==2:
           dir.append([0,1])     
           dir.append([0,2]) 
 
        h=0
        if k1=="香":
           h=h+1
        if h1=="後手":
           h=h+1
        if h==2:
           dir.append([0,-1])     
           dir.append([0,-2])
 
        if k1=="飛": 
           dir.append([1,0])
           dir.append([0,1])
           dir.append([-1,0])
           dir.append([0,-1])      
           dir.append([2,0])
           dir.append([0,2])
           dir.append([-2,0])
           dir.append([0,-2])
 
        if k1=="角": 
           dir.append([1,1])
           dir.append([1,-1])
           dir.append([-1,1])
           dir.append([-1,-1])      
           dir.append([2,2])
           dir.append([2,-2])
           dir.append([-2,2])
           dir.append([-2,-2]) 
 
        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([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([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([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])
 
        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])
           dir.append([2,0])
           dir.append([0,2])
           dir.append([-2,0])
           dir.append([0,-2])
 
        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])
           dir.append([2,2])
           dir.append([-2,-2])
           dir.append([-2,2])
           dir.append([2,-2])
 
        return dir
 
    def makedata(self):
 
        self.decode() 
        koma_sel=self.select()
 
        koma_pol=[]
        pos_pol=[]
 
        for n in koma_sel:
            dx=self.makedir(self.hand[n],self.koma[n])
            for d1 in dx:
                p1=self.pos[n]
                x1=self.ban[p1][0]+d1[0]
                y1=self.ban[p1][1]+d1[1]
                p2=self.pointx([x1,y1])
                if p2>0:koma_pol.append(n)
                if p2>0:pos_pol.append(p2)
 
        sig=[]
        for i in range(len(koma_pol)):
            px=[0,0,0,0,0,0]
            for j in range(6): 
                px[j]=self.pos[j]
            p1=koma_pol[i]
            p2=pos_pol[i]
            px[p1]=p2
            sig.append(px)
 
        sigx=[]
        for px in sig:              
            if self.check(px)<50:sigx.append(px)
 
        pol_pos=[]
        pol_hand=[]
        pol_mode=[]
        for px in sigx: 
            self.pos_ch=[]
            self.hand_ch=[]
            for i in range(6):
                self.pos_ch.append(px[i])
                self.hand_ch.append(self.hand[i])
            self.rev()
            pol_pos.append(self.pos_ch)
            pol_hand.append(self.hand_ch)
            mx=self.win(self.mode,self.hand_ch)
            pol_mode.append(mx)
 
        self.pol_hash=[]
        for i in range(len(pol_mode)):
            self.pol_hash.append(self.code(pol_mode[i],pol_hand[i],pol_pos[i]))
 
最終更新:2018年04月04日 11:14