Beispiel #1
0
def draw(step_dict=None):
    # 绘制棋盘
    canvas.delete('Piece')
    color = {1: 'black', 0: 'white'}
    if step_dict is None:
        step_dict = Chess.getStep().copy()
    for step in step_dict.items():
        row = ord(step[1][0]) - 97
        column = ord(step[1][1]) - 97
        y1 = START + (LENGTH * row) - 20
        x1 = START + (LENGTH * column) - 20
        y2 = START + (LENGTH * row) + 20
        x2 = START + (LENGTH * column) + 20
        canvas.create_oval(x1,
                           y1,
                           x2,
                           y2,
                           fill=color[(step[0] % 2)],
                           tags='Piece')
        if step[0] == len(step_dict.items()):
            canvas.create_oval(x1 + 15,
                               y1 + 15,
                               x2 - 15,
                               y2 - 15,
                               fill='pink',
                               tags='Piece')
        if order:
            canvas.create_text(x1 + 20,
                               y1 + 20,
                               text=str(step[0]),
                               fill=color[int(not bool((step[0] % 2)))],
                               tags='Piece')
Beispiel #2
0
def tips():
    # 提示
    if len(Chess.getStep().items()) == 0:
        b.moveChessmen(7, 7)
    # elif not M:
    else:
        rc = aiChess()
        move(rc[0], rc[1])
    draw()
Beispiel #3
0
def save_gbs():
    # 保存棋谱文件 `gbs` 格式
    gbs_data = tkinter.filedialog.asksaveasfile(mode='w',
                                                title="选择棋谱",
                                                initialdir=ex_folder,
                                                defaultextension=".espace",
                                                filetypes=[("Gobang棋谱文件",
                                                            ".gbs")])
    if gbs_data is not None:
        gbs_data.write(str(Chess.getStep()))