News:

MFG's Character of the Month: September 2026 Voting

Main Menu

Is there a more recent AI coding tutorial/document?

Started by Nocturnis, September 02, 2022, 03:03:34 AM

Previous topic - Next topic

Nocturnis

I've been having a lot of issues coding AI recently, leading me to believe that either I'm being unwittingly bullheaded about my approach or that the documentation that we have here at the guild is a bit antiquated. Perhaps both?

Now, I'm more than willing to admit that I'm not looking in the right place for information, but goodness knows I also have little idea as to where I should be looking. Again - this is likely error on my behalf.

Some of the issues I've been observing from my AI are as follows:

Combo chains simply not activating and defaulting to another that're in the code.

Combo extenders (e.g. during falling states) are not activating and are instead defaulting to combo starters.

Certain moves cancel from states that they should not be able to. This appears to be flaw in my code in a few cases - however there are a couple of instances I cannot explain. (This is still likely an error in my code.)

An absolutely unreasonable amount of jumping. I suspect it's due to my activation commands containing an Up input.

I'd also like some clarification on the random trigger and it's applications. In an effort to cause less confusion I've opted to set certain ranges such as random = [250,300] - the greater than or less than ranges ( <,>) were becoming unreliable. Was this a mistake?

I'm also concerned about creating an unreasonable difficulty with my AI, as I've observed it best some characters it otherwise should not when it is operating properly.

Thanks for reading.

SteelHammers

There are some essential things that you should know, some of which you probably do. Firstly, you must separate the player's changestate from the AI's so that the AI doesn't enter the human states when it parses through the commands.

Basic movements such as walk, crouch, jump (& double jump), stand & guard are all hardcoded in and can't be disabled.  The AI doesn't need you to tell it to do these things, it'll just do it as mugen randomly parses the commands.  You character jumping too much is a result of this. You can re-code/ add codes to some of these states and [statedef -1] to mitigate this and make it so the AI meet your needs either for partial or full control of how your AI moves. Some people, I myself as well, use AI only states for AI movements.

In parsing states, Mugen parses from top to bottom, so every changestate sctrl on top will have priority over the ones below it.  If you have 2 or more combo routes that uses the same/similar conditions, then the one on top will take precedence over the one below. Even if you use random. If the random number picked happens to be within range, then only the top one will trigger.

I'm assuming you're using at least mugen 1.0 and above but saw on your other post you using a variable to activate the AI.  Is there a reason why you can't use the AILevel trigger? Asking since I don't know the condition for your AI activation, and using AILevel will solve your AI difficulty problem.

Regarding the difficulty of your AI, beating down other AI's, that's not a testament to how difficult it is. Humans can exploit patterns and behaviours while AI's cannot, making the most difficult AI a punching bag once you've figured out it's pattern.  Difficult AI's should be less predictable for humans which makes it harder for them to predict its patterns.

With random, I've heard of it being unreliable so people either store it in a variable or use varrangeset to replace it all together. There's actually a lot of threads on 'random' so you can look it up. As long as your random falls within a small range, should be ok. range of 50 like you have is alright.





Nocturnis

Changestates have been separated.

Code is organized from top to bottom. Still having issues with things like juggles. I've set it up so that it continues the juggle while p2 is in a falling state, and usually the first attack fires but stops after that, despite there being a follow up coded. Not sure what I'm messing up here. Follow up attack is higher in the code than the initial hit.

AILevel is a thing? Crap. (Thanks)


WastedCoder

You can try Seravy's AI guide or video tutorials on the AI that Beterhans from Beterwork channel did. To my mind they are pretty useful. Good luck.

Nocturnis

Quote from: WastedCoder on September 02, 2022, 06:05:10 PM
You can try Seravy's AI guide or video tutorials on the AI that Beterhans from Beterwork channel did. To my mind they are pretty useful. Good luck.

I'll check it out. Thanks :)

HOWEVER

My other brain cell woke up and realized I had a stupid typo in the next move. I did a dumb, lol.

For anyone who reads this in the future: Remember to not only check your code line by line, but also double check your integers and operators.

Welp, SteelHammers, you solved my dang AI issues. Thanks much!

WastedCoder

Quote from: Nocturnis on September 02, 2022, 06:17:36 PM
Quote from: WastedCoder on September 02, 2022, 06:05:10 PM
You can try Seravy's AI guide or video tutorials on the AI that Beterhans from Beterwork channel did. To my mind they are pretty useful. Good luck.

I'll check it out. Thanks :)

HOWEVER

My other brain cell woke up and realized I had a stupid typo in the next move. I did a dumb, lol.

For anyone who reads this in the future: Remember to not only check your code line by line, but also double check your integers and operators.

Welp, SteelHammers, you solved my dang AI issues. Thanks much!

So true, especially for me XD
That's why you do a lot of tests

inktrebuchet

#6
Unfortunately, AI coding is so different from character to character it makes it hard to make tutorials or code snippets that are easy to use.

Moves canceling into or switching states when they shouldn't be, is definitely a coding error on your end. That can only happen if you triggers/conditions aren't strict enough.

I recommend using the ailevel trigger for AI detection if you are coding for 1.0, 1.1 or Ikemen. It's completely reliable where the older var method can have some unwanted results. Ailevel trigger should be on EVERY changestate in statedef -1, so either trigger1 = ailevel or trigger1 = !ailevel for example.

Also, it's best to copy all of the changestates that aren't for AI and paste them to convert them to AI changestates in statedef-1, that's what we mean by separating AI. This also makes it easy to keep the conditions the same for AI as they are for a user. *Charge moves, would need a variable, if you want it to be more like a user.

More advanced stuff would involve preventing the default AI from jumping and walking randomly and writing your own logic for that. That can be tough coming up with when to walk and jump though. Cutting out jumping alone makes even kfm a harder character to fight.


I have some snippets you can find in my signature for AI detecting projectiles, if you are interested in that kind of thing.