パーソナルブログメモリ

a = [1, 1]
for _ in "*" * 999: a += [sum(a[-2:])]
print(a)

将棋盤の検討

2019-02-19 | python入門(すぐさまマスター)
動かせるというものではなくて閲覧用に作成中です。
成り駒の漢字は一部当て字です。
2文字で表現しようか悩んだのですが、棋譜を見るのに2文字だと少し見づらいので。

寒いと血流が悪いのかさっぱり進まない。
(東京が冷え込んだバレンタイン前の3連休から、暖房器具をほぼ使わずカイロのみで謎の我慢大会をしている)



import tkinter
import random

tk = tkinter.Tk()
tk.title("shogi 100")
tk.geometry("800x600")

cv = tkinter.Canvas(tk, width = 800, height = 600)
cv.create_rectangle(0, 0, 800, 600, fill = 'gray')

#cv.create_rectangle(20, 20, 80, 80)
koma=["","歩兵","香車","桂馬","銀将","金将","角行","飛車","玉将","と金","成香","成桂","成銀","","竜馬","竜王",""]
koma2=["","歩","香","桂","銀","金","角","飛","玉","と","今","企","全","","馬","竜",""]
board=[]
def boardInit():
    global board
    bd=["234585432","070000060","111111111","060000070","234585432"]
    for y in range(3):
        l=[]
        for x in range(9):
            l+=[int(bd[y][x])*-1]
        board+=[l]
    for y in range(3,6):
#        board+=[[0,0,0,0,0,0,0,0,0]]
        board+=[[9,10,11,12,14,15,0,0,0]]
    for y in range(2,5):
        l=[]
        for x in range(9):
            l+=[int(bd[y][x])]
        board+=[l]
    board+=[[0,1,2,3,4,5,6,7,0]]
    board+=[[0,1,2,3,4,5,6,7,0]]

def writeKoma(x,y,kn,tb,count=0):#tb 1:sente 2:gote
    writeKoma2(x,y,kn,tb,count)
    return
    sx=220
    sy=120
    f=("Helvetica", 12, "bold")
    n1,n2=0,1
    if tb==2:n1,n2=1,0
    cv.create_text(x*40+sx, y*40+sy, text=koma[kn][n1], font=f,angle=[0,0,180][tb])
    cv.create_text(x*40+sx, y*40+sy+15, text=koma[kn][n2], font=f,angle=[0,0,180][tb])
    if count>1:cv.create_text(x*40+sx+15, y*40+sy+10,text=str(count),font=f,angle=0)

def writeKoma2(x,y,kn,tb,count=0):#tb 1:sente 2:gote
    sx=220
    sy=120
    f=("Helvetica", 25, "bold")
    cv.create_text(x*40+sx, y*40+sy, text=koma2[kn], font=f,angle=[0,0,180][tb])
    if count>1:cv.create_text(x*40+sx+25, y*40+sy+5,text=str(count),font=f,angle=0)

def writeBoard(b):
    for y in range(9):
        for x in range(9):
            n=b[y][x]
            if n!=0:
                if n>0:
                     writeKoma(x,y,n,1)
                else:
                     writeKoma(x,y,-n,2)
    for x in range(1,8):
        if b[9][x]>0:
            writeKoma(10,9-x,x,1,b[9][x])
        if b[10][x]>0:
            writeKoma(-2,x-1,x,1,b[10][x])

boardInit()
print(board)
writeBoard(board)

cv.place(x=0, y=0)
tk.mainloop()

最新の画像もっと見る

コメントを投稿

ブログ作成者から承認されるまでコメントは反映されません。