HHSProgrammingClub / smash-my-buttons

Le all-purpose AI Fighting Game and possible eSport if everything goes better than expected lol
GNU General Public License v3.0
4 stars 1 forks source link

AI Coroutines #58

Open lgtyqz opened 5 years ago

lgtyqz commented 5 years ago

So if you try to get the AI to jump and then input a move, the AI will just use the move without jumping.

Sample Code:

AIName = "DestroyerOfWorlds"
AIAuthor = "L G T Y Q Z"
AITargetCharacter = "Birboi"

def loop(player, enemy):
    player.jump()
    player.tilt()

No jumping occurs when this code is used. Can anyone help me with this?

clman94 commented 5 years ago

This is because the init() method of the JumpState is not getting a chance to execute because the tilt AttackState is being pushed to stack after the JumpState in the same frame.

The CharacterState only calls the init() method when its update() method is called (here) and the update() method for a CharacterState is only called if it is at the top of the stack.

lgtyqz commented 5 years ago

Yeah, realized that. My current solution for AIs is to do:

player.jump()
if player.getYVel() < -1:
    player.tilt()

We'll have to explain that to the participants

le-birb commented 5 years ago

maybe add a yield() function to wait until the next frame?

clman94 commented 5 years ago

The python interpretor does not support coroutines so a yield would not work in this case.