altf4 / libmelee

Open Python 3 API for making your own Smash Bros: Melee AI that works with Slippi Online
GNU Lesser General Public License v3.0
237 stars 47 forks source link

MenuHelper spamming hmn/cpu swap in character select #99

Open dalton-avery opened 11 months ago

dalton-avery commented 11 months ago

When selecting characters, after the cpu character is selected and the level is set, it navigates to the hmn/cpu toggle and spam clicks it. This blocks the autostart of the game if using that controller to autostart.

If there are two controllers, one for a training AI and one to select a cpu character, the AI Controller will start the game before the 2nd controller has toggled the character to a cpu and set its level, causing the game to be with two players. For each round start after this, it will change it to cpu but not set the level prior to the game starting.

Script to reproduce spamming:

import melee, os

ISO_PATH = os.getenv('ISO_PATH')
SLIPPI_PATH = os.getenv('SLIPPI_PATH')

console = melee.console.Console(path=SLIPPI_PATH, fullscreen=False)

controller = melee.controller.Controller(console, port=1, type=melee.ControllerType.STANDARD)

console.run(iso_path=ISO_PATH)

console.connect()

controller.connect()

gamestate = console.step()

while gamestate.menu_state != melee.Menu.IN_GAME:
    gamestate = console.step()
    if gamestate is None:
        continue

    melee.MenuHelper.menu_helper_simple(
        gamestate=gamestate,
        controller=controller,
        character_selected=melee.Character.CPTFALCON,
        stage_selected=melee.Stage.BATTLEFIELD,
        connect_code="",
        cpu_level=9,
        costume=0,
        autostart=False,
        swag=False
    )

Script to reproduce game starting without cpu/cpulevel selected:

import melee, os

ISO_PATH = os.getenv('ISO_PATH')
SLIPPI_PATH = os.getenv('SLIPPI_PATH')

console = melee.console.Console(
    path=SLIPPI_PATH,
    fullscreen=False
)

controller1 = melee.controller.Controller(console, port=1, type=melee.ControllerType.STANDARD)

controller2 = melee.controller.Controller(console, port=2, type=melee.ControllerType.STANDARD)

console.run(iso_path=ISO_PATH)

console.connect()

controller1.connect()
controller2.connect()

gamestate = console.step()

while gamestate.menu_state != melee.Menu.IN_GAME:
    gamestate = console.step()
    if gamestate is None:
        continue

    melee.MenuHelper.menu_helper_simple(
        gamestate=gamestate,
        controller=controller1,
        character_selected=melee.Character.CPTFALCON,
        stage_selected=melee.Stage.BATTLEFIELD,
        connect_code="",
        cpu_level=0,
        costume=0,
        autostart=True,
        swag=False
    )

    melee.MenuHelper.menu_helper_simple(
        gamestate=gamestate,
        controller=controller2,
        character_selected=melee.Character.DK,
        stage_selected=melee.Stage.BATTLEFIELD,
        connect_code="",
        cpu_level=9,
        costume=0,
        autostart=False,
        swag=False
    )