<commit_before># Module to simulate an agent's movements in the environment

import geometry_helpers
import environment_details
import agent_percepts as percepts
import agent

def run_simulation(number_of_turns, goal_point, goal_reward,
                   initial_location, visible_obstacles,
                   x_bounds, y_bounds):
    """
    Given the number of turns allowed, run the simulation for the agent
    navigating a maze of polygons.
    """
    agent_location = initial_location
    remaining_turns = number_of_turns

    # persistent for LRTA*

    # a table indexed by state and action
    result = {}
    # a table of cost estimates indexed by state
    cost_estimates = {}
    prev_state = None
    prev_action = None
    agent_score = 0
    agent_reached_goal = False

    print('Agent starting at point {}'.format(initial_location))
    print('Agent goal: {}'.format(goal_point))

    while remaining_turns > 0:
        print('Agent currently at point {}'.format(agent_location))

        prev_action, prev_state, result, cost_estimates = agent.LRTA_star_agent(
            agent_location, goal_point, visible_obstacles, result,
            cost_estimates, prev_state, prev_action)

        if not prev_action:
            # TODO assigning None to prev_action may have unexpected
            # consequences - make sure this works.
            agent_location = percepts.get_new_position(
                visible_obstacles, x_bounds, y_bounds)
            print('Resetting agent to point {}'.format(agent_location))

            agent_score += goal_reward
            print('Agent score: {}'.format(agent_score))

            agent_reached_goal = True

            continue

        print('Agent attempting to reach point {}'.format(prev_action))

        agent_location = percepts.perform_action(prev_action)

        print('Agent now at point {}'.format(agent_location))
        agent_score -= geometry_helpers.distance(prev_state, agent_location)
        print('Agent score: {}'.format(agent_score))

        remaining_turns -= 1

    if not agent_reached_goal:
        print('Agent failed to find goal in alloted turns.')
        print('Final agent location: {}'.format(agent_location))

    return agent_reached_goal


if __name__ == "__main__":
    number_of_turns = 250
    goal_point = geometry_helpers.Point(34, 22)
    goal_reward = 1000
    initial_location = geometry_helpers.Point(5, 5)
    visible_obstacles = environment_details.visible_obstacles
    x_bounds = environment_details.x_bounds
    y_bounds = environment_details.y_bounds

    run_simulation(number_of_turns, goal_point, goal_reward,
                   initial_location, visible_obstacles,
                   x_bounds, y_bounds)<commit_msg>Allow simulation parameters to be configurable by user.<commit_after># Module to simulate an agent's movements in the environment

import sys
import ast

import geometry_helpers
import environment_details
import agent_percepts as percepts
import agent

def run_simulation(number_of_turns, goal_point, goal_reward,
                   initial_location, visible_obstacles,
                   x_bounds, y_bounds):
    """
    Given the number of turns allowed, run the simulation for the agent
    navigating a maze of polygons.
    """
    agent_location = initial_location
    remaining_turns = number_of_turns

    # persistent for LRTA*

    # a table indexed by state and action
    result = {}
    # a table of cost estimates indexed by state
    cost_estimates = {}
    prev_state = None
    prev_action = None
    agent_score = 0
    agent_reached_goal = False

    print('Agent starting at point {}'.format(initial_location))
    print('Agent goal: {}'.format(goal_point))

    while remaining_turns > 0:
        print('Agent currently at point {}'.format(agent_location))

        prev_action, prev_state, result, cost_estimates = agent.LRTA_star_agent(
            agent_location, goal_point, visible_obstacles, result,
            cost_estimates, prev_state, prev_action)

        if not prev_action:
            # TODO assigning None to prev_action may have unexpected
            # consequences - make sure this works.
            agent_location = percepts.get_new_position(
                visible_obstacles, x_bounds, y_bounds)
            print('Resetting agent to point {}'.format(agent_location))

            agent_score += goal_reward
            print('Agent score: {}'.format(agent_score))

            agent_reached_goal = True

            continue

        print('Agent attempting to reach point {}'.format(prev_action))

        agent_location = percepts.perform_action(prev_action)

        print('Agent now at point {}'.format(agent_location))
        agent_score -= geometry_helpers.distance(prev_state, agent_location)
        print('Agent score: {}'.format(agent_score))

        remaining_turns -= 1

    if not agent_reached_goal:
        print('Agent failed to find goal in alloted turns.')
        print('Final agent location: {}'.format(agent_location))

    return agent_reached_goal


if __name__ == "__main__":
    if len(sys.argv) < 5:
        print("Usage: python simulation.py number_of_turns goal_reward"
        " \"goal_point\" \"initial_point\"")
    else:
        number_of_turns = int(sys.argv[1])
        goal_reward = int(sys.argv[2])

        user_goal = ast.literal_eval(sys.argv[3])
        goal_point = geometry_helpers.Point(user_goal[0], user_goal[1])

        user_init = ast.literal_eval(sys.argv[4])
        initial_location = geometry_helpers.Point(user_init[0], user_init[1])

        visible_obstacles = environment_details.visible_obstacles
        x_bounds = environment_details.x_bounds
        y_bounds = environment_details.y_bounds

        run_simulation(number_of_turns, goal_point, goal_reward,
                       initial_location, visible_obstacles,
                       x_bounds, y_bounds)
{'fraction_non_alphanumeric': 0.07743137919349373, 'fraction_numerical': 0.004744154523890207, 'mean_word_length': 2.9041005291005293, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7435115', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1637, 'n_words': 431}