def console_setup(self): # Game console self.console = melee.Console(path=SLIPPI_EXECUTABLE_PATH, slippi_address="127.0.0.1", slippi_port=51441, blocking_input=False, polling_mode=False) # Your / Our AI's controller self.ai_controller = melee.Controller( console=self.console, port=AI_PORT, type=melee.ControllerType.STANDARD) self.enemy_controller = melee.Controller( console=self.console, port=ENEMY_PORT, type=melee.ControllerType.STANDARD) signal.signal(signal.SIGINT, self.signal_handler) self.console.run(iso_path=MELEE_ISO) if not self.console.connect(): print("ERROR: Failed to connect to the console.") sys.exit(-1) if not self.ai_controller.connect(): print("ERROR: Failed to connect the controller.") sys.exit(-1) if not self.enemy_controller.connect(): print("ERROR: Failed to connect the controller.") sys.exit(-1) print("Controller connected")
def test_character_select(self): """ Start up the console and select our charcter then quit """ console = melee.Console(path=DOLPHIN_PATH, slippi_port=12345) controller = melee.Controller(console=console, port=1, type=melee.ControllerType.STANDARD) console.run(iso_path=ISO_PATH) self.assertTrue(console.connect()) self.assertTrue(controller.connect()) first_frame = True while True: gamestate = console.step() if first_frame: self.assertEqual(gamestate.frame, 0) first_frame = False if gamestate.menu_state == melee.enums.Menu.IN_GAME: pass else: melee.MenuHelper.menu_helper_simple(gamestate, controller, melee.Character.FOX, melee.Stage.BATTLEFIELD, "", costume=1, autostart=False, swag=False) if gamestate.menu_state == melee.enums.Menu.CHARACTER_SELECT and (gamestate.frame > 50): self.assertEqual(gamestate.players[1].character_selected, melee.Character.FOX) break console.stop()
def start(self): if sys.platform == "linux": dolphin_home_path = str(self.d.slippi_home)+"/" elif sys.platform == "win32": dolphin_home_path = None self.console = melee.Console( path=str(self.d.slippi_bin_path), dolphin_home_path=dolphin_home_path, blocking_input=self.blocking_input, tmp_home_directory=True) # print(self.console.dolphin_home_path) # add to logging later # Configure Dolphin for the correct controller setup, add controllers human_detected = False for i in range(len(self.players)): curr_player = self.players[i] if curr_player.agent_type == "HMN": self.d.set_controller_type(i+1, enums.ControllerType.GCN_ADAPTER) curr_player.controller = melee.Controller(console=self.console, port=i+1, type=melee.ControllerType.GCN_ADAPTER) curr_player.port = i+1 human_detected = True elif curr_player.agent_type in ["AI", "CPU"]: self.d.set_controller_type(i+1, enums.ControllerType.STANDARD) curr_player.controller = melee.Controller(console=self.console, port=i+1) self.menu_control_agent = i curr_player.port = i+1 else: # no player self.d.set_controller_type(i+1, enums.ControllerType.UNPLUGGED) if self.ai_starts_game and not human_detected: self.ai_press_start = True else: self.ai_press_start = False # don't let ai press start without the human player joining in. if self.ai_starts_game and self.ai_press_start: self.players[self.menu_control_agent].press_start = True self.console.run(iso_path=self.iso_path) self.console.connect() [player.controller.connect() for player in self.players if player is not None] self.gamestate = self.console.step()
def test_two_controllers_in_game(self): """ Two controllers, get into game then quit """ console = melee.Console(path=DOLPHIN_PATH, slippi_port=23456) controller_one = melee.Controller(console=console, port=1, type=melee.ControllerType.STANDARD) controller_two = melee.Controller(console=console, port=2, type=melee.ControllerType.STANDARD) console.run(iso_path=ISO_PATH) self.assertTrue(console.connect()) self.assertTrue(controller_one.connect()) self.assertTrue(controller_two.connect()) first_frame = True while True: gamestate = console.step() if first_frame: self.assertEqual(gamestate.frame, 0) first_frame = False if gamestate.menu_state == melee.enums.Menu.IN_GAME: self.assertEqual(gamestate.players[1].character, melee.Character.FOX) self.assertEqual(gamestate.players[2].character, melee.Character.MARTH) break else: melee.MenuHelper.menu_helper_simple(gamestate, controller_one, melee.Character.FOX, melee.Stage.BATTLEFIELD, "", costume=1, autostart=True, swag=False) melee.MenuHelper.menu_helper_simple(gamestate, controller_two, melee.Character.MARTH, melee.Stage.BATTLEFIELD, "", costume=1, autostart=False, swag=False) console.stop()
def __init__(self, p, partner=False): self.port = p self.con = melee.Console(path=GAME_PATH) self.pad = melee.Controller(console=self.con, port=p) self.partner = partner if not partner: self.con.run(iso_path=ISO_PATH) print('console connect: {}'.format(self.con.connect())) self.pad.connect() print('test port: {}'.format(p))
console = melee.Console(path=args.dolphin_executable_path, slippi_address=args.address, slippi_port=51441, blocking_input=False, logger=log) # Dolphin has an optional mode to not render the game's visuals # This is useful for BotvBot matches console.render = True # Create our Controller object # The controller is the second primary object your bot will interact with # Your controller is your way of sending button presses to the game, whether # virtual or physical. controller = melee.Controller(console=console, port=args.port, type=melee.ControllerType.STANDARD) controller_opponent = melee.Controller(console=console, port=args.opponent, type=melee.ControllerType.GCN_ADAPTER) # This isn't necessary, but makes it so that Dolphin will get killed when you ^C def signal_handler(sig, frame): console.stop() if args.debug: log.writelog() print("") #because the ^C will be on the terminal print("Log file created: " + log.filename) print("Shutting down cleanly...")
slippi_address=args.address, slippi_port=51441, blocking_input=False, polling_mode=False, logger=log) # Dolphin has an optional mode to not render the game's visuals # This is useful for BotvBot matches console.render = True # Create our Controller object # The controller is the second primary object your bot will interact with # Your controller is your way of sending button presses to the game, whether # virtual or physical. controller = melee.Controller(console=console, port=args.port, type=melee.ControllerType.STANDARD) controller_opponent = melee.Controller(console=console, port=args.opponent, type=melee.ControllerType.STANDARD, ai=True) # This isn't necessary, but makes it so that Dolphin will get killed when you ^C def signal_handler(sig, frame): console.stop() if args.debug: log.writelog() print("") #because the ^C will be on the terminal print("Log file created: " + log.filename)
plat_top[0], plat_top[1], plat_left[0], plat_left[1]] client.send( OSCMessage("/platforms", ordered) ) # print(ordered) # Port assignment playerPort = 2 enemyPort = 1 # Creates a console object that represents Slippi Online / Dolphin instance. console = melee.Console(path="C:/Users/Michael/Documents/_Spring 2021/Music and Tech 2/FM-Slippi-2.2.5-Win") # Note: File path must use forward slashes or double back slashes. # Single back slashes will result in unicode error. # Creates controller objects for the bot (port 1) and the human (port 2). controller_bot = melee.Controller(console=console, port=enemyPort) controller_human = melee.Controller(console=console, port=playerPort, type=melee.ControllerType.GCN_ADAPTER) # Runs the Dolphin instance and connects the program code to it. console.run() console.connect() # "Plugs in" the controllers for the bot and human. controller_bot.connect() controller_human.connect() ############################### ########## Main Loop ########## ############################### while True: gamestate = console.step() # Steps to the next frame. # If we're not in any gamestate yet, no need to run rest of loop for now.
def test_two_controllers_in_game(self): """ Two controllers, get into game """ console = melee.Console(path=DOLPHIN_PATH, slippi_port=23456) controller_one = melee.Controller(console=console, port=1, type=melee.ControllerType.STANDARD) controller_two = melee.Controller(console=console, port=2, type=melee.ControllerType.STANDARD) console.run(iso_path=ISO_PATH) self.assertTrue(console.connect()) self.assertTrue(controller_one.connect()) self.assertTrue(controller_two.connect()) first_frame = True while True: gamestate = console.step() if first_frame: self.assertEqual(gamestate.frame, 0) first_frame = False if gamestate.menu_state == melee.enums.Menu.IN_GAME: if gamestate.frame == -123: self.assertEqual(gamestate.players[1].character, melee.Character.FOX) self.assertEqual(gamestate.players[2].character, melee.Character.MARTH) self.assertEqual(gamestate.stage, melee.Stage.FINAL_DESTINATION) elif gamestate.frame == 20: # Do a shine controller_one.press_button(melee.Button.BUTTON_B) controller_one.tilt_analog(melee.Button.BUTTON_MAIN, 0.5, 0) # Dash forward (left) controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 0, 0.5) elif gamestate.frame == 21: self.assertEqual(gamestate.players[1].action, melee.Action.DOWN_B_GROUND_START) self.assertEqual(gamestate.players[1].action_frame, 1) self.assertEqual(gamestate.players[2].action, melee.Action.DASHING) self.assertEqual(gamestate.players[2].action_frame, 1) self.assertTrue(gamestate.players[2].moonwalkwarning) controller_one.release_all() controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 0.2, 0.5) elif gamestate.frame == 22: # self.assertAlmostEqual(gamestate.players[2].controller_state.main_stick[0], 0.018750011920928955) controller_one.release_all() controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 0.5, 0.5) elif gamestate.frame == 23: controller_one.release_all() controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 0.7, 0.5) elif gamestate.frame == 24: controller_one.release_all() controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 1, 0.5) elif gamestate.frame == 25: controller_one.release_all() controller_two.tilt_analog(melee.Button.BUTTON_MAIN, 0, 0.5) elif gamestate.frame == 35: # Last frame of pivot turn self.assertEqual(gamestate.players[2].action, melee.Action.TURNING) controller_one.release_all() controller_two.release_all() elif gamestate.frame == 36: # This is the first frame of standing after the pivot turn self.assertEqual(gamestate.players[2].action, melee.Action.STANDING) controller_one.release_all() controller_two.press_shoulder(melee.Button.BUTTON_L, 1) elif gamestate.frame == 37: controller_one.release_all() controller_two.press_shoulder(melee.Button.BUTTON_L, 0.8) elif gamestate.frame == 38: controller_one.release_all() controller_two.press_shoulder(melee.Button.BUTTON_L, 0.3) else: controller_one.release_all() controller_two.release_all() if gamestate.frame == 60: break else: melee.MenuHelper.menu_helper_simple( gamestate, controller_one, melee.Character.FOX, melee.Stage.FINAL_DESTINATION, "", costume=1, autostart=True, swag=False) melee.MenuHelper.menu_helper_simple( gamestate, controller_two, melee.Character.MARTH, melee.Stage.FINAL_DESTINATION, "", costume=1, autostart=False, swag=False) console.stop()
import math from melee import framedata from melee.framedata import FrameData from strategies.defensive import Defense from recovering.recovery import Recover from recovering.recovery import getEdgeDist from tech.chain_ws import ChainWaveShines from tech.waveshine import WaveShine from tech.multishine import MultiShine from tech.smashattack import SmashAttack from tech.intumble import InTumble from tech.dashdance import DashDance from config import slippilocation console = melee.Console(path=slippilocation) controller = melee.Controller(console=console, port=1, type=melee.ControllerType.STANDARD) console.run() console.connect() controller.connect() chainshine = ChainWaveShines() defense = Defense() tumbleCheck = InTumble() smashhh = SmashAttack() frmData = framedata.FrameData() dashDance = DashDance() def stateStep(gamestate, ai_state, enemy_state, controller, frmdata): enemy_atk = frmData.is_attack(enemy_state.character, enemy_state.action)
def main(saved_model_path, dolphin_path, iso_path, _log): embed_game = embed.make_game_embedding() policy = tf.saved_model.load(saved_model_path) sample = lambda *structs: policy.sample(*tf.nest.flatten(structs)) hidden_state = policy.initial_state(1) console = melee.Console(path=dolphin_path) # This isn't necessary, but makes it so that Dolphin will get killed when you ^C def signal_handler(sig, frame): console.stop() print("Shutting down cleanly...") # sys.exit(0) signal.signal(signal.SIGINT, signal_handler) controller = melee.Controller(console=console, port=1, type=melee.ControllerType.STANDARD) cpu_controller = melee.Controller(console=console, port=2, type=melee.ControllerType.STANDARD) # Run the console console.run(iso_path=iso_path) # Connect to the console _log.info("Connecting to console...") if not console.connect(): _log.error("Failed to connect to the console.") return _log.info("Console connected") for c in [controller, cpu_controller]: print("Connecting controller to console...") if not c.connect(): print("ERROR: Failed to connect the controller.") sys.exit(-1) print("Controller connected") action_repeat = 0 repeats_left = 0 # Main loop while True: # "step" to the next frame gamestate = console.step() if gamestate is None: continue if gamestate.frame == -123: # initial frame controller.release_all() # The console object keeps track of how long your bot is taking to process frames # And can warn you if it's taking too long if console.processingtime * 1000 > 12: print("WARNING: Last frame took " + str(console.processingtime * 1000) + "ms to process.") # What menu are we in? if gamestate.menu_state in [ melee.Menu.IN_GAME, melee.Menu.SUDDEN_DEATH ]: if repeats_left > 0: repeats_left -= 1 continue embedded_game = embed_game.from_state(gamestate), action_repeat batched_game = tf.nest.map_structure( lambda a: np.expand_dims(a, 0), embedded_game) sampled_controller_with_repeat, hidden_state = sample( batched_game, hidden_state) sampled_controller_with_repeat = tf.nest.map_structure( lambda t: np.squeeze(t.numpy(), 0), sampled_controller_with_repeat) sampled_controller = sampled_controller_with_repeat['controller'] action_repeat = sampled_controller_with_repeat['action_repeat'] repeats_left = action_repeat for b in embed.LEGAL_BUTTONS: if sampled_controller['button'][b.value]: controller.press_button(b) else: controller.release_button(b) main_stick = sampled_controller["main_stick"] controller.tilt_analog(melee.Button.BUTTON_MAIN, *main_stick) c_stick = sampled_controller["c_stick"] controller.tilt_analog(melee.Button.BUTTON_C, *c_stick) controller.press_shoulder(melee.Button.BUTTON_L, sampled_controller["l_shoulder"]) controller.press_shoulder(melee.Button.BUTTON_R, sampled_controller["r_shoulder"]) else: melee.MenuHelper.menu_helper_simple(gamestate, controller, melee.Character.FOX, melee.Stage.YOSHIS_STORY, connect_code=None, autostart=False, swag=False) melee.MenuHelper.menu_helper_simple(gamestate, cpu_controller, melee.Character.FOX, melee.Stage.YOSHIS_STORY, connect_code=None, cpu_level=9, autostart=True, swag=False)
client.connect((ip, port)) playerAdd = "/playerButtons" # player address # Buttons ordered as: # A, B, X, Y, Z, L, R, D_UP, D_DOWN, D_LEFT, D_RIGHT, (11 booleans) # main_stick_x, main_stick_y, c_sticK_x, c_stick_y, l_shoulder, r_shoulder (6 floats) playerButtons = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # Creates a console object that represents Slippi Online / Dolphin instance. console = melee.Console( path= "C:/Users/Michael/Documents/_Spring 2021/Music and Tech 2/FM-Slippi-2.2.5-Win" ) # Note: File path must use forward slashes or double back slashes. # Single back slashes will result in unicode error. # Creates controller objects for the bot (port 1) and the human (port 2). controller_bot = melee.Controller(console=console, port=1) controller_human = melee.Controller(console=console, port=2, type=melee.ControllerType.GCN_ADAPTER) # Runs the Dolphin instance and connects the program code to it. console.run() console.connect() # "Plugs in" the controllers for the bot and human. controller_bot.connect() controller_human.connect() ############################### ########## Main Loop ########## ############################### while True: gamestate = console.step() # Steps to the next frame.