コード例 #1
0
def main(args):

    length = args.l
    breadth = args.b

    learning_rate = args.lr
    discount_rate = args.dr
    min_explore_rate = args.p
    max_explore_rate = args.q
    decay_factor = args.d

    num_episodes = args.ep
    num_iterations = args.iter

    board = grid.draw_grid(length, breadth)
    # board = [['S', '-', '*', '*', '-'], ['*', '-', '*', '*', '-'], ['-', '-', '*', '-', '-'], ['-', '*', '-', '-', '-'], ['-', '-', '-', '*', 'G']]
    print("Board -:\n\n", board)
    q_table = np.zeros((length * breadth, len(actions)))

    explore_rate = max_explore_rate
    i = 0
    while i < num_episodes:
        j = 0
        completed = False
        x = y = 0  # Start State
        while j < num_iterations and completed == False:
            current_state = (x, y)
            action = choose_action(q_table, current_state, explore_rate,
                                   breadth)
            next_state = perform_action(current_state, action, length, breadth)
            if board[next_state[0]][next_state[1]] == 'G':
                completed = True
            reward = get_reward(board, next_state)
            x_new, y_new = next_state
            q_table[x * breadth + y][actions.index(action)] = q_table[
                x * breadth + y][actions.index(action)] + learning_rate * (
                    reward +
                    discount_rate * q_table[x_new * breadth + y_new].max() -
                    q_table[x * breadth + y][actions.index(action)])
            x, y = x_new, y_new
            explore_rate = min_explore_rate + (max_explore_rate -
                                               min_explore_rate) * np.exp(
                                                   -decay_factor *
                                                   (i * num_iterations + j))
            j = j + 1

        i = i + 1
        print("Episode {} : Iterations : {}".format(i, j))

    print("\nFinal Q-Table -:\n\n", q_table)
コード例 #2
0
def test_lsd_consistant(fit=True):
    import matplotlib.pyplot as plt
    image = tf.placeholder(tf.uint8, shape=[None, None, 3])
    N = [2, 3]
    path = '/media/george/1a4f4334-123f-430d-8a2b-f0c0fa401c75/data/alchohol/alchohol_104.jpeg'
    lines = lsd(image, N, fit=fit)
    sess = tf.InteractiveSession()

    _image = cv2.cvtColor(cv2.imread(path, cv2.IMREAD_COLOR),
                          cv2.COLOR_BGR2RGB)
    _image1 = draw_grid(_image.copy(), N)
    plt.imshow(_image1)
    plt.show()
    _lines = sess.run(lines, feed_dict={image: _image})
    for i in range(_lines.shape[0]):
        line = _lines[i]
        if not check_in_single_grid(line, N):
            print(line)
コード例 #3
0
ファイル: game.py プロジェクト: Tyler-the-Wizard/WebSlash
        menu.draw_character_builder(screen)
        pygame.display.flip()

    elif settings.game_state == constants.GAMEPLAY:
        surface_messages.fill(constants.COLOR_BG)
        surface_grid.fill(constants.COLOR_BG)
        surface_inv.fill(constants.COLOR_BG)
        surface_equip.fill(constants.COLOR_BG)

        # Draw messages
        text.draw_messages(surface_messages)

        screen.blit(surface_messages, (10, 10))

        # Draw grid
        grid.draw_grid(settings.grid, surface_grid)
        for v in settings.tiles:
            v.draw(surface_grid)
        for v in settings.item_stacks:
            v.draw(surface_grid)
        for v in settings.monsters:
            v.draw(surface_grid)

        screen.blit(surface_grid, (10, 110))

        # Draw inv
        pygame.draw.rect(surface_inv, (0, 0, 0),
            pygame.Rect(170, 0, 5, 40))
        if is_inv:
            inv.draw_inv(settings.player.inv, surface_inv)
        else:
コード例 #4
0
ファイル: game.py プロジェクト: tom2802/pong
                placed.add(coming_pipes[2]((-2, 1)))
                placed.add(coming_pipes[1]((-2, 2)))
                placed.add(coming_pipes[0]((-2, 3)))

    # Fyller surface med farge (RGB)
    surface.fill((255, 255, 255))

    # Listen har en update() funksjon. Den kaller i tur og orden update() funksjonen
    # på objektene vi har lagt til i elements listen.
    # eks. For sprite in elements.sprites:
    #   sprite.update()
    # Selv om spritene er av forskjellig type, så vil en kunne kalle update() uten å sjekke type.
    # Det er det som menes med "polymorfi" i objektorientertprogramering.
    planned.update()
    placed.update()
    draw_grid(surface)

    # elements.draw() går gjennom alle objektene i listen.
    # Fuksjonen bruker så image og rect egenskapene fra spritene for å tegne dem på "surface"
    planned.draw(surface)
    placed.draw(surface)

    # Her blir surface tegnet på skjerm
    screen.blit(surface, (0, 0))

    # Disse funksjonene forteller pygame at "skjermen" skal oppdateres med innholdet i "screen"
    pygame.display.flip()
    pygame.display.update()

    # Her tar programmet en pause for at det skal kjøre med en hastighet på frames pr. second.
    # FPS er en "konstant" vi har opprettet i settings modulen