Example #1
0
def run_bbox(verbose=False):
    n_features = n_actions = max_time = -1

    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        bbox.load_level("../levels/train_level.data", verbose=1)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()

    av_table = ActionValueTable(n_features, n_actions)
    av_table.initialize(0.2)
    print av_table._params
    learner = Q(0.5, 0.1)
    learner._setExplorer(EpsilonGreedyExplorer(0.4))
    agent = LearningAgent(av_table, learner)
    environment = GameEnvironment()
    task = GameTask(environment)
    experiment = Experiment(task, agent)

    while environment.finish_flag:
        experiment.doInteractions(1)
        agent.learn()
 
    bbox.finish(verbose=1)
Example #2
0
def prepare_bbox():
	global n_features, n_actions
	if bbox.is_level_loaded():
		bbox.reset_level()
	else:
		bbox.load_level("../levels/test_level.data", verbose=1)
		n_features = bbox.get_num_of_features()
		n_actions = bbox.get_num_of_actions() 
Example #3
0
def prepare_bbox():
    global n_features, n_actions
    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        bbox.load_level("../levels/test_level.data", verbose=1)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
def prepare_bbox():
    global n_f, n_a, max_time
 
    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        bbox.load_level("../levels/train_level.data", verbose=1)
        n_f = bbox.get_num_of_features()
        n_a = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()
Example #5
0
def prepare_bbox():
    global n_features, n_actions, max_time

    # Reset environment to the initial state, just in case
    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        # Load the game level
        bbox.load_level("../levels/train_level.data", verbose=1)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()
Example #6
0
def prepare_box():
    global n_features, n_actions, max_time

    # Reset the environment to the initial state, just in case
    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        # Load the game level
        bbox.load_level('levels/train_level.data', verbose=1)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()
Example #7
0
    def reset(self):
        if bbox.is_level_loaded():
            bbox.reset_level()
        else:
            bbox.load_level(self.level, verbose=1)
            self.n_features = bbox.get_num_of_features()
            self.n_actions = bbox.get_num_of_actions()
            self.max_time = bbox.get_max_time()

        self._steps = 0
        self._state = np.zeros((1, self.n_features))
        self._is_over = False
        self._prev_score = -float('inf')
        self._actions_log = []
Example #8
0
    def reset(self):
        if bbox.is_level_loaded():
            bbox.reset_level()
        else:
            bbox.load_level(self.level, verbose=1)
            self.n_features = bbox.get_num_of_features()
            self.n_actions = bbox.get_num_of_actions()
            self.max_time = bbox.get_max_time()

        self._steps = 0
        self._state = np.zeros((1, self.n_features))
        self._is_over = False
        self._prev_score = -float('inf')
        self._actions_log = []
Example #9
0
def load_level(level, verbosity):
    """
    Loads the named level and returns its name and description.
    """
    path = join(dirname(__file__), 'levels', level)
    if not path.endswith('_level.data'):
        path = '{}_level.data'.format(path)
    if verbosity > 3:
        print("Loading level from {}".format(path))
    bb_load_level(path, verbose=verbosity > 3)
    return {'key': level,
            'steps': get_max_time(),
            'actions': get_num_of_actions(),
            'features': get_num_of_features()}
Example #10
0
def prepare_bbox():

    global n_features, n_actions, max_time, vectors, pool, num_of_vectors

    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        bbox.load_level("../levels/train_level.data", verbose=1)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()

    vectors = np.zeros((num_of_vectors, n_features), np.float32)
    print("preparing")
    pool = multiprocessing.Pool(processes=processes)
Example #11
0
def load_level(level, verbosity):
    """
    Loads the named level and returns its name and description.
    """
    path = join(dirname(__file__), 'levels', level)
    if not path.endswith('_level.data'):
        path = '{}_level.data'.format(path)
    if verbosity > 3:
        print("Loading level from {}".format(path))
    bb_load_level(path, verbose=verbosity > 3)
    return {
        'key': level,
        'steps': get_max_time(),
        'actions': get_num_of_actions(),
        'features': get_num_of_features()
    }
Example #12
0
def prepare_bbox():
    global n_features, n_actions, max_time
    ## TODO: Save the interactions with the environment as an output data frame
    global interaction_list
    interaction_list = []
    
    ## Reset the environment to initial state, just in case
    if bbox.is_level_loaded():
        bbox.reset_level()
    else:
        ## Load the game level
        bbox.load_level("../levels/train_level.data", verbose=True)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()
        
        ## The matrix that contains the output data frame
        states = ['state_'] * n_features
        state_list = [states[i] + str(i) for i in range(n_features)]
        header_list = state_list + ['reward', 'action']
        interaction_list.append(header_list)
Example #13
0
def prepare_bbox():
    '''
    Prepares the environment (learning/test data).
    '''
    
    global n_features
    global n_actions
    global max_time
    global q_function
    global epsilon
    global gamma
    global alpha
    global valid_actions
    global init_value
    
    if bbox.is_level_loaded():
        ## Reset the environment to initial state
        bbox.reset_level()
    else:
        ## Load the training/test data
        bbox.load_level('../levels/train_level.data', verbose=True)
        n_features = bbox.get_num_of_features()
        n_actions = bbox.get_num_of_actions()
        max_time = bbox.get_max_time()
Example #14
0
#!/usr/bin/env python3

"""
A minimal bot player.

Loads the level and params and lets the bot act.
"""
from interface import (get_max_time, get_num_of_actions, get_num_of_features,
                       finish, load_level)
from numpy import get_include, load
from pyximport import install

install(setup_args={'include_dirs': get_include()}, reload_support=True)
from bot_wrapper import do_act

if __name__ == '__main__':
    load_level('../levels/train_level.data', verbose=1)
    level = {
        'steps': get_max_time(),
        'actions': get_num_of_actions(),
        'features': get_num_of_features()
    }
    params = dict(load('params.npz'))
    do_act(level, params)
    finish(verbose=1)
Example #15
0
#!/usr/bin/env python3
"""
A minimal bot player.

Loads the level and params and lets the bot act.
"""
from interface import (get_max_time, get_num_of_actions, get_num_of_features,
                       finish, load_level)
from numpy import get_include, load
from pyximport import install

install(setup_args={'include_dirs': get_include()}, reload_support=True)
from bot_wrapper import do_act

if __name__ == '__main__':
    load_level('../levels/train_level.data', verbose=1)
    level = {
        'steps': get_max_time(),
        'actions': get_num_of_actions(),
        'features': get_num_of_features()
    }
    params = dict(load('params.npz'))
    do_act(level, params)
    finish(verbose=1)