Exemplo n.º 1
0
 def __init__(self,
              env_id,
              roms_path,
              difficulty=3,
              frame_ratio=3,
              frames_per_step=3,
              render=True,
              throttle=False,
              debug=False):
     self.difficulty = difficulty
     self.frame_ratio = frame_ratio
     self.frames_per_step = frames_per_step
     self.throttle = throttle
     self.emu = Emulator(env_id,
                         roms_path,
                         "sfiii3n",
                         setup_memory_addresses(),
                         frame_ratio=frame_ratio,
                         render=render,
                         throttle=throttle,
                         debug=debug)
     self.started = False
     self.expected_health = {"P1": 0, "P2": 0}
     self.expected_wins = {"P1": 0, "P2": 0}
     self.round_done = False
     self.stage_done = False
     self.game_done = False
     self.stage = 1
Exemplo n.º 2
0
def run_emulator(env_id, game_id, roms_path, memory_addresses, output_queue):
    emulator = None
    try:
        emulator = Emulator(env_id, roms_path, game_id, memory_addresses)
        output_queue.put(emulator.step([]))
    finally:
        emulator.close()
Exemplo n.º 3
0
 def test_step(self):
     memory_addresses = {"test": Address("02000008", "u8")}
     game_id = "sfiii3n"
     emulator = None
     try:
         emulator = Emulator("testEnv1", game_id, memory_addresses)
         data = emulator.step([])
         assert_that(data["frame"].shape, equal_to((224, 384, 3)))
         assert_that(data["test"], equal_to(0))
     finally:
         emulator.close()
Exemplo n.º 4
0
 def test_screen_dimensions(self):
     memory_addresses = {"test": Address("02000008", "u8")}
     game_id = "sfiii3n"
     roms_path = "/home/michael/dev/MAMEToolkit/MAMEToolkit/emulator/mame/roms"
     emulator = None
     try:
         emulator = Emulator("testEnv1", roms_path, game_id, memory_addresses)
         assert_that(emulator.screenDims["width"], equal_to(384))
         assert_that(emulator.screenDims["height"], equal_to(224))
     finally:
         emulator.close()
Exemplo n.º 5
0
 def test_step(self):
     memory_addresses = {"test": Address("02000008", "u8")}
     game_id = "sfiii3n"
     roms_path = "/home/michael/dev/MAMEToolkit/MAMEToolkit/emulator/mame/roms"
     emulator = None
     try:
         emulator = Emulator("testEnv1", roms_path, game_id, memory_addresses)
         data = emulator.step([])
         assert_that(data["frame"].shape, equal_to((224, 384, 3)))
         assert_that(data["test"], equal_to(0))
     finally:
         emulator.close()
Exemplo n.º 6
0
    def __init__(self, env_id, roms_path, self_play=True, vs_rounds_before_single_player=2, player='P1', character = 19, 
                 frame_ratio=2, frames_per_step=1, render=True, throttle=False, debug=True, new_training=True):

        self.p1_character_selection = character  # 'Scorpion' (default) is 6 #19 and over for random character
        self.p2_character_selection = character

        # This will need Xvfb X11 virtual server installed on GNU/Linux system
        if not render:
            os.system("Xvfb :1 -screen 0 800x600x16 +extension RANDR &")
            os.environ["DISPLAY"] = ":1"

        self.env_id = env_id
        self.self_play = self_play
        self.frame_ratio = frame_ratio
        self.frames_per_step = frames_per_step
        self.throttle = throttle
        self.debug = debug
        self.emu = Emulator(env_id, roms_path, "umk3", setup_memory_addresses(), frame_ratio=frame_ratio, render=render,
                            throttle=throttle, debug=debug)
        self.started = False

        self.expected_time_remaining = 0
        self.time_remaining = 0
        self.done = False
        self.round_done = False
        self.stage_done = False
        self.game_over = False
        self.game_completed = False
        self.finished_single_player = False
        self.num_total_characters = umk3_num_total_characters

        # Create two Player objects with useful values for each player (a player can be an agent or the game's AI)
        self.P1 = Player('P1', self.p1_character_selection, self.num_total_characters)
        self.P2 = Player('P2', self.p2_character_selection, self.num_total_characters)
        self.env_player = player  # If environment's agent controls 'P1', 'P2' or both in 2 Player self-play 'Vs'

        # Player is initialized to 'Vs' if self_play is True
        if self.self_play is True:
            self.env_player = 'Vs'

        # Number of self-play Vs rounds to be played before the agent plays a single player benchmark in story mode
        self.vs_rounds_before_single_player = vs_rounds_before_single_player
        self.current_vs_rounds_before_single_player = vs_rounds_before_single_player

        # Stage is counting only if playing in single-player mode
        # If 'Vs' mode, Stage remains at 0
        self.stage = 0 if player is 'Vs' else 1

        self.last_vs_game_winner = ''
        self.highest_stage = 0
        self.path = 'Novice'
        self.difficulty = 0
        self.expected_difficulty = 0  # Assumes UMK3 starts with Very Easy pre-selected

        self.paths = ['Novice', 'Warrior', 'Master', 'MasterII']
        self.difficulties = ['Very Easy', 'Easy', 'Medium', 'Hard', 'Very Hard']

        # If the game somehow reaches round 5 in a stage (3 draws), it resets after round 5 ends
        self.round_this_stage = 1
        self.reset_this_round = False

        self.total_episodes_played = 0
        self.memory_values = []

        # Track if any milsetones have been logged to decide if to create a new file or append
        self.new_training = new_training

        if not self.new_training and os.path.exists(os.path.join('milestones', self.env_id + '_milestones.txt')):
            self.logged_first_milestone = True
        else:
            self.logged_first_milestone = False