Beispiel #1
0
    def test_save_load(self):

        self.assertTrue(save_game(self.file_path, self.active_map,
                                  self.player))
        self.assertTrue(
            load_game(self.file_path, self.loaded_map, self.loaded_player))

        self.assertTrue(
            len(self.active_map.game_map) == len(self.loaded_map.game_map))

        for row_index in range(len(self.active_map.game_map)):

            self.assertTrue(
                len(self.active_map.game_map[row_index]) == len(
                    self.loaded_map.game_map[row_index]))
            for col_index in range(len(self.active_map.game_map[row_index])):
                self.assertTrue(
                    self.active_map.game_map[row_index][col_index] ==
                    self.loaded_map.game_map[row_index][col_index])

        self.assertTrue(self.player.hitpoints == self.loaded_player.hitpoints)
        self.assertTrue(self.player.bag == self.loaded_player.bag)
        self.assertTrue(
            self.player.position[0] == self.loaded_player.position[0])
        self.assertTrue(
            self.player.position[1] == self.loaded_player.position[1])
def start_game():
    """
    Start game dialog
    :return: None
    """

    global active_map
    global active_player
    global thread_enemy

    active_map = DungeonMap(0, False)
    active_player = Player(active_map)

    response = utils.get_input(
        validator_response, "Do you wish to load last saved game? [Y\\N]: ")

    if response.lower() == 'y':

        if not utils.load_game(SAVE_PATH, active_map, active_player):

            print("Failed to load saved game! Starting new game")
            init_game()

    else:

        logger.info("Starting new game.")
        init_game()

    thread_enemy = ThreadEnemyWrapper(active_map, active_player)
    thread_enemy.start()
Beispiel #3
0
	def __init__(self, game_name, game_folder):

		self.game_name = game_name
		self.game_folder = game_folder
                #pdb.set_trace()  
		self.env_list = utils.load_game(game_name, game_folder)

		self.lvl = 0

		self.set_level(self.lvl)

		self.actions = [0, K_RIGHT, K_LEFT, K_UP, K_DOWN, K_SPACE]
Beispiel #4
0
    def __init__(self):
        self.areas = []
        count = 3
        for row in range(3, 14, 2):
            for col in range(row - 3, row + 6, 2):
                if col < 3 or col > 14:
                    continue
                self.areas.extend([(row, col)] * count)
                count += 1

        self.areas.sort(key=lambda c: c[0] * c[1])
        self.levels_count = len(self.areas)
        self.level_number = 0

        self.loaded_level = load_game()
Beispiel #5
0
        batch = []
        for datapoint in response.datapoints:
            observation = tf.make_ndarray(datapoint.observation)
            actions = [Action(index) for index in datapoint.actions]
            targets = [(target.value, target.reward, target.policy.probabilities) for target in datapoint.targets]
            batch.append((observation, actions, targets))
        return batch

    def stats(self):
        return self.remote_replay_buffer.Stats(replay_buffer_pb2.Empty()).metrics

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='MuZero Replay Buffer Server')
    parser.add_argument('--game', type=str, help='One of the games implemented in the games/ directory', required=True)
    parser.add_argument('--port', type=str, help='Port for gRPC communication', required=True)
    args = parser.parse_args()

    def serve(replay_buffer_config, port):
        grpc_server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        servicer = ReplayBufferServer(replay_buffer_config)
        replay_buffer_pb2_grpc.add_ReplayBufferServicer_to_server(servicer, grpc_server)
        grpc_server.add_insecure_port('[::]:{}'.format(port))
        print('Starting replay buffer server, listening on port {}...'.format(port))
        grpc_server.start()
        grpc_server.wait_for_termination()

    config = load_game(args.game, parser)

    logging.basicConfig()
    serve(config.replay_buffer_config, args.port)
Beispiel #6
0
	def reset(self):

		self.env_list = utils.load_game(self.game_name, self.game_folder)
		self.set_level(self.lvl)
		self.current_env.softReset()