示例#1
0
def button_m():
    # 人机对战菜单
    c_s()
    Chess.new()
    draw()
    global auto
    auto = threading.Thread(target=detector)
    auto.start()
    canvas.delete('ButtonMain')
    # 新局
    open_gs_button = tk.Button(root, text='新局', command=new)
    canvas.create_window(720,
                         100,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonM')
    # 悔棋
    regret_button = tk.Button(root, text='悔棋', command=regret)
    canvas.create_window(720,
                         190,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=regret_button,
                         tags='ButtonM')
    # 提示
    tips_button = tk.Button(root, text='提示', command=tips)
    canvas.create_window(720,
                         280,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=tips_button,
                         tags='ButtonM')

    # 保存棋谱
    save_gbs_button = tk.Button(root, text='保存棋谱', command=save_gbs)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=save_gbs_button,
                         tags='ButtonM')
    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         460,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonM')
示例#2
0
def button_score():
    # 初始化
    c_s()
    Chess.new()
    draw()
    canvas.delete('ButtonMain')
    # 新局
    open_gs_button = tk.Button(root, text='新局', command=new)
    canvas.create_window(720,
                         100,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonScore')

    # 载入棋谱
    open_gs_button = tk.Button(root, text='载入棋谱', command=open_gs)
    canvas.create_window(720,
                         190,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonScore')
    # 悔棋
    regret_button = tk.Button(root, text='悔棋', command=regret)
    canvas.create_window(720,
                         280,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=regret_button,
                         tags='ButtonScore')
    # 保存棋谱
    save_gbs_button = tk.Button(root, text='保存棋谱', command=save_gbs)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=save_gbs_button,
                         tags='ButtonScore')
    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         500,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonScore')
示例#3
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')
示例#4
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()
示例#5
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()))
示例#6
0
def score_mode(step_dict):
    canvas.delete('ButtonScore')
    temp_dict = step_dict.copy()
    Chess.new()
    dicttoChees(step_dict)
    draw()

    def forward():
        # 下一步
        if len(temp_dict) != len(step_dict):
            temp_dict.update(
                {len(temp_dict) + 1: step_dict[len(temp_dict) + 1]})
            dicttoChees(temp_dict)
            draw()

    def retreat():
        # 上一步
        if len(temp_dict) != 0:
            temp_dict.popitem()
            dicttoChees(temp_dict)
            draw()

    def play():
        def stop():
            thread_stop.stop_thread(t)
            regret_button = tk.Button(root, text='⏩', command=play)
            canvas.create_window(767,
                                 370,
                                 anchor='nw',
                                 width=30,
                                 height=30,
                                 window=regret_button,
                                 tags='ScoreMode')

        regret_button = tk.Button(root, text='⏸', command=stop)
        canvas.create_window(767,
                             370,
                             anchor='nw',
                             width=30,
                             height=30,
                             window=regret_button,
                             tags='ScoreMode')
        nonlocal temp_dict
        if len(temp_dict) == len(step_dict):
            temp_dict = {}

        def play_t():
            for i in range(len(step_dict) - len(temp_dict)):
                forward()
                time.sleep(1)
            regret_button = tk.Button(root, text='⏩', command=play)
            canvas.create_window(767,
                                 370,
                                 anchor='nw',
                                 width=30,
                                 height=30,
                                 window=regret_button,
                                 tags='ScoreMode')

        t = threading.Thread(target=play_t)
        t.start()

    regret_button = tk.Button(root, text='◀', command=retreat)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    regret_button = tk.Button(root, text='⏩', command=play)
    canvas.create_window(767,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    regret_button = tk.Button(root, text='▶', command=forward)
    canvas.create_window(810,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         500,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonScore')
示例#7
0
def new():
    # 新局
    if tkinter.messagebox.askyesno('重新开始', '要重新开始游戏吗?'):
        Chess.new()
        draw()
示例#8
0
                         height=50,
                         window=game_exit_button,
                         tags='ButtonMain')

    # 测试按钮
    # debug_button = tk.Button(root, text='测试按钮', command=Test__)
    # canvas.create_window(720,
    #                      460,
    #                      anchor='nw',
    #                      width=120,
    #                      height=50,
    #                      window=debug_button,
    #                      tags='ButtonMain')


b = Chess('b', player_name="Computer.Python.AI", can_regret=True)
w = Chess('w', player_name="Computer.Python.AI", can_regret=True)

order_checkbutton = tk.Checkbutton(root,
                                   text="显示序号",
                                   variable=order_checkbutton_var,
                                   onvalue=1,
                                   offvalue=0,
                                   height=5,
                                   width=20,
                                   command=show_order)
canvas.create_window(667,
                     617,
                     anchor='nw',
                     width=120,
                     height=50,