Example #1
0
def set_parameters():
    try:
        int(n_var.get())
        int(p_var.get())
        int(m_var.get())
    except:
        set_label_text(warning_label, "Please enter valid integers only.")
        return
    nn = int(n_var.get())
    np = int(p_var.get())
    mm = int(m_var.get())
    t = int((nn * nn * np) / 100)
    if mm > t:
        set_label_text(
            warning_label,
            "Target should be less/eq to num of sq in percentage cover.")
        return
    global ai
    del ai
    n, p, m = nn, np, mm
    ai = Ai(n, p, m, status_bar)

    global pen
    h, v = ai.initial_state_generator()
    pen = bfs_turtle
    draw_grid(h, v, None, None, init=True)
    pen = dfs_turtle
    draw_grid(h, v, None, None, init=True)

    set_label_text(warning_label, "")
    set_label_text(status_bar, "Grid parameters changed.")
    toggle_button(dfs_path_button, False)
    toggle_button(bfs_path_button, False)
Example #2
0
def set_parameters():
    try:
        int(input1_var.get())
        int(input2_var.get())
    except:
        set_label_text(warning_label, "Please enter valid integers only.")
        return
    global ai
    del ai
    n, m = int(input1_var.get()), int(input2_var.get())
    ai = Ai(n, m)
    
    set_label_text(warning_label, "")
    toggle_button(astar_path_button, False)
    toggle_button(hc_path_button, False)
Example #3
0
def runtime_graph(run=False):
    global ai
    # These are the results from previous runs
    time = [(0.8058971352609088, 0.7959112525268416), (5.767188457820188, 1.7839178601334078),\
            (7.0034266835409795, 2.983069520901978), (8.636212998031588, 4.616296621770378),\
            (10.97483654365763, 6.617920596080964), (19.500726808795065, 8.78038179454515)]
    time = [(0.8034134646042023, 0.8229737673923273), (1.5956936986166195, 1.5917969050000629),\
            (2.846747373550863, 2.8401113741969146), (4.300874637468331, 4.2552083309090865),\
            (6.25773836093562, 6.005873583211578), (14.017652400610118, 8.400256838356142)]
    if run:
        time = []
        for size in range(2, 8):
            del ai
            ai = Ai(size, 80, int(size * size * 0.7), status_bar)
            ai.initial_state_generator()
            meta_bfs = ai.bfs(bfs_turtle, init_state=True)
            meta_dfs = ai.dfs(dfs_turtle, init_state=True)
            print("on size: ", size, (meta_bfs['time'], meta_dfs['time']))
            time.append((meta_bfs['time'], meta_dfs['time']))
    t = cmp_turtle
    t.clear()
    o = (-110, -110)
    t.pencolor('black')
    t.penup()
    t.setposition(o[0], o[1])
    t.pendown()
    t.setposition(o[0] + 280, o[1])
    t.penup()
    t.setposition(o[0] + 230, o[1] + 2)
    t.pendown()
    t.write('Grid size')
    t.penup()
    t.setposition(o[0], o[1])
    t.pendown()
    t.setposition(o[0], o[1] + 220)
    t.write('Time')
    t.pencolor('red')
    time = [(0, 0)] + time
    stepx, stepy = 40, 8
    for i in range(1, len(time)):
        j = time[i][0]
        t.penup()
        t.setposition(o[0] + (i - 1) * stepx, o[1] + time[i - 1][0] * stepy)
        t.pendown()
        t.setposition(o[0] + i * stepx, o[1] + j * stepy)
    t.write('bfs')
    t.pencolor('blue')
    for i in range(1, len(time)):
        j = time[i][1]
        t.penup()
        t.setposition(o[0] + (i - 1) * stepx, o[1] + time[i - 1][1] * stepy)
        t.pendown()
        t.setposition(o[0] + i * stepx, o[1] + j * stepy)
    t.write('dfs')
Example #4
0
def set_parameters():
    global ai
    ai = Ai()
Example #5
0
    ab_cmp_win1_label = tk.Label(compare_frame, text='', anchor='w')
    ab_cmp_win1_label.grid(row=3, column=2, sticky='w')
    ab_cmp_win2_label = tk.Label(compare_frame, text='', anchor='w')
    ab_cmp_win2_label.grid(row=4, column=2, sticky='w')

    # Graph frames
    tk.Label(right, text='Game Canvas').grid(row=0, pady=2, sticky=tk.W)

    canvas = tk.Canvas(right, **border_params)
    canvas.grid(row=1, sticky='nsew', padx=4, pady=4)
    canvas_turtle = turtle.RawTurtle(canvas)
    sel = canvas_turtle.clone()

    # Print Some Guidelines
    desc = 'CHECKERS AI\n\nSome specifications:'\
    +'\n1. This program is gui based, there is no command line interaction with the user.'\
    +'\n2. The gui is fully capable of handling all user inputs.'\
    +'\n3. For all the options specified in the project description a button is implemented, please use them.'\
    +'\n4. To make a move, first select a green coin and then select the position where you want to move it.'\
    +'\n5. Please be patient while the Ai is calculating its next move.'\
    +'\n Clicking on the canvas or pressing any button during this process may produce unexpected results.'\
    +'\n\n\n'
    print(desc)

    ai = Ai()

    #     log('I m in Main')
    #     print "voila"

    root.mainloop()
Example #6
0
        '3. Now use "show path" button to show corresponding path computed.')
    add_inst(
        '4. Option numbers are written on respective buttons, please use them.'
    )
    add_inst(
        '5. Whenever bfs/dfs is called initial state is shown in their respective canvas.'
    )
    add_inst(
        '6. Program might not respond while its computing bfs/dfs path, so please be patient.'
    )
    add_inst('7. Clicking on buttons while something is under process may produce unexpected results, '\
             + 'please refrain from doing that.')

    # Print Some Guidelines
    desc = 'MATCHSTICK AI\n\nSome specifications:'\
    +'\n1. This program is gui based, there is no command line interaction with the user.'\
    +'\n2. The gui is fully capable of handling all user inputs.'\
    +'\n3. For all the options specified in the project description a button is implemented, please use them.'\
    +'\n\n\n'
    print(desc)

    # Set default values in entry fields
    n, p, m = (3, 100, 6)
    n_var.set(n)
    p_var.set(p)
    m_var.set(m)

    ai = Ai(n, p, m, status_bar)

    root.mainloop()
Example #7
0
 add_inst('1. Input grid parameters (size & percentage coverage) and target number of squares.')
 add_inst('2. Then compute bfs/dfs path using "start bfs/dfs" button.')
 add_inst('3. Now use "show path" button to show corresponding path computed.')
 add_inst('4. Option numbers are written on respective buttons, please use them.')
 add_inst('5. Whenever bfs/dfs is called initial state is shown in their respective canvas.')
 add_inst('6. Program might not respond while its computing bfs/dfs path, so please be patient.')
 add_inst('7. Clicking on buttons while something is under process may produce unexpected results, '\
          + 'please refrain from doing that.')
 
 # Print Some Guidelines
 desc = 'STACKING CONTAINERS PROBLEM\n\nSome specifications:'\
 +'\n1. This program is gui based, there is no command line interaction with the user.'\
 +'\n2. The gui is fully capable of handling all user inputs.'\
 +'\n3. For all the options specified in the project description a button is implemented, please use them.'\
 +'\n\n\n'
 print(desc)
 
 
 # Set default values in entry fields
 n, m = (6, 3)
 input1_var.set(n)
 input2_var.set(m)
 
 ai = Ai(n, m)
 
 log('I m in Main')
 
 root.mainloop()