Jump to content

AI Tutorial - For Beginners!

Recommended Posts

Whats up! Welcome to a Beginner Guide on AI Coding. Since there are a lot of AI tutorials that are a bit in depth, but not really helpful to others (DON'T KNOW WHY), Guess I'll post a tutorial on AI Coding.

First, to start AI coding, YOU MUST KNOW HOW TO CODE A CHARACTER WITH SOME EXPERIENCE (Well at least understand the codes)

(Important or you'll get confused like an idiot =x)

First, there are 2 different methods of implementing AI in terms of compatibility:

Var AI coding:

Coding AI through variable activation. Usually having a var set at either the CMD or the CNS file. Use this to recognize if this is the player or not the player, and must include various cpu commands for AI through this method.

NOT recommended since this is old AI coding, refer to mugendocs if you want to do the hard way for custom AI.

Simple steps however:

Varset - var(59) occasionally for AI activation

Trigger - var(59) = 0 or var(59) > 0 to see if this is an AI command or Human Command


CPU COMMANDS : <- NEEDED, usually complex hard to implicate for humans


type = Varset <-VAR SETTING

triggerall = RoundState = 2 <- Occurs if RoundState = 2 (ROUND START)

trigger1 = command = "cpu1" <- make the commands like x,d,f,d,x,f,x -> etc

trigger2 = command = "cpu2"

trigger3 = command = "cpu3"

trigger4 = command = "cpu4"

trigger5 = command = "cpu5"

trigger6 = command = "cpu6"

trigger7 = command = "cpu7"

trigger8 = command = "cpu8"

trigger9 = command = "cpu9"

trigger10 = command = "cpu10"

trigger11 = command = "cpu11"

trigger12 = command = "cpu12"

trigger13 = command = "cpu13"

trigger14 = command = "cpu14"

trigger15 = command = "cpu15"

trigger16 = command = "cpu16"

trigger17 = command = "cpu17"

trigger18 = command = "cpu18"

trigger19 = command = "cpu19"

trigger20 = command = "cpu20"

trigger21 = command = "cpu21"

trigger22 = command = "cpu22"

trigger23 = command = "cpu23"

trigger24 = command = "cpu24"

trigger25 = command = "cpu25"

trigger26 = command = "cpu26"

trigger27 = command = "cpu27"

trigger28 = command = "cpu28"

trigger29 = command = "cpu29"

trigger30 = command = "cpu30"

v = 7 <- Variable is 7 -> var(7)

value = 1 <- Value is 1 -> var(7) = 1

Example of how this works: <- Duplication State Method - One for AI and One for You

[state -1, Stand Medium Left Punch] ; Human State

type = ChangeState

value = 900

triggerall = var (7) != ; Trigger for When var(7) != 1 -> Its Human!

triggerall = command = "Stand Medium Left Punch" ; Human Command

trigger1 = statetype != A ; Your state should not be equal to A - Hence AIR

trigger1 = ctrl ; You Have Control

trigger2 = (stateno = 200 || stateno = 210 || stateno = 400 || stateno = 410 ) && movecontact

trigger3 = (stateno = 901 && time > 17) && movecontact

trigger4 = (stateno = 902 && time > 28) && movecontact

trigger5 = (stateno = 903 && time > 10) && movecontact

Triggers 1-5 are the conditions when it can happen and how many it can be linked or duplicated

Important as you can use more complex triggers for better custom AI

[state -1, Stand Medium Left Punch AI] AI State State

type = ChangeState

value = 900

triggerall = var (7) Trigger for When var(7) = 1 -> Its CPU

triggerall = !Win ; Don't need but usually AI turns on if the AI did not win and won't go again after win.

triggerall = P2bodydist X = [0,20] Move should occur if p2bodydist x is around 0-20 pixels

triggerall = P2StateType != L Move should occur if p2statetype is not lying down

trigger1 = statetype != A Can't do this move in AIR to prevent bugs in AI

trigger1 = ctrl AI must have control to use this

trigger1= random <= 300 Not recommended way to do random, you can use triggerall = random <= (expression) for better transition

trigger2= random <= 300

trigger3= random <= 300

trigger4= random <= 300

trigger5= random <= 300

trigger2 = (stateno = 200 || stateno = 210 || stateno = 400 || stateno = 410 ) && movecontact

trigger3 = (stateno = 901 && time > 17) && movecontact

trigger4 = (stateno = 902 && time > 28) && movecontact

trigger5 = (sta teno = 903 && time > 10) && movecontact

Triggers 2-5! IMPORTANT FOR AI linking combos and states for better AI

Note: AI can be scaled through variable by having a variable placed in the random with an expression, must be for moderate coders only =P

Advantages : Can be used for custom combos really well, if you know how to code more complex triggers and using other triggers and expressions.

Disadvantages: Coding may be complex, and CPU commands tend to override Human commands. Basically, ending up being controlled by the CPU while you SUPPOSE to play.

Note: You can have one state for both AI and Human, just set it different triggers and don't use triggeralls that only apply to AI or Human or it will cause errors.

This is the old method to use, but I recommend the AILevel method.

AILevel Method Coding:

This method of Coding is the most up to date and the best way to code characters as it includes a very handy feature: Adjustable Diffuculties!

There is no need to include CPU commands or variables to activate AI, however, you can use complex expressions and vars for AI custom combos and human commands.

Example: -> You can do it the Duplication State Way

NOTE: For Human Commands


While Triggerall = AIlevel is applied to CPU commands.

[state -1, Lotus Sinking Fangs AI]

type = ChangeState

value = 1200

triggerall = AIlevel ; Applied if AI is activated

triggerall = random <= AIlevel*10 ; AI level is based on level 1 - 8 - AIlevel is multipled by 10 meaning at AIlevel = 8 it has a 80% change of this move happening with 80% of the triggers that is activated.

triggerall = p2bodydist x = [0,20] ; Distance trigger as explained above


trigger1 = statetype = S ; Has to stand to activate move

trigger1 = ctrl ; AI is in control

You can have more triggers to activate this move more by adding other expressions and more triggers. Most you probably need is 10 for triggers, for 10 different outcomes * state triggers outcomes in other states.


Moderate and Expert Coders Occasionally Use Vars and AIlevel coding together for Good AI, but AIlevel is all you really need for AI activation, and triggers are used to define the right trigger to make the move work without bugs and to work properly for AI

NOTE: IF any questions is asked, I will answer and update this post and give feedback on it!

Link to post
Share on other sites
  • 4 months later...

Thanks Vector and like you said 'for beginners'. AI Level is unique to MUGEN 1.0 so use wisely and convert stuff up when possible. Alos, for 'advanced' stuff, AI is used to keep the computer from doing stuff that may cause a character to go into a 'tired' or helpless state. Several other things can be done with AI as well, but its nice to tinker with. But also note that if you don't know what you're doing for sure, playing with the AI can be a nightmare (always have a backup version of a character you are tinkering with). Anyway, I remember back when Reu was doing Evil Ryu with King Tigre and I emailed Reu to let him know that a ~F,b with time = 1 or such command he used could also actually be done by a player which would set off AI mode while playing the character in person vs. person mode or such. Reu then relegated Evil Ryu to "AI only" type status (like Psycho Shredder and the like). Nice tutorial Vector.

Link to post
Share on other sites
  • 2 weeks later...

The use of variables on AI, it happens mostly because of Winmugen coding. It is faulty and it tends to have errors like those. Another reason could be that the creator used the wrong triggers and could possibly lead to the AI taking over.

Link to post
Share on other sites
  • 2 years later...

The AI method with variable, must be applied in CMD file, using commands of cpu y activated in statedef -1, then use routines of each atack with a percent of time, if are codified good, then will no errors, this method applied winmugen and mugen 1.0.

I do AIs for ninja slayer and rugal of Jin, the result of my work are good.

I have a question about the method of AILevel, must be in CMD file? or another file?

I probe in CMD File and mugen 1.0 accepted, now I will test the AI, and do more AIs, is very easy do this.


thanks, sorry my bad english

Link to post
Share on other sites
  • 4 months later...
  • 2 years later...
  • 2 years later...
On 2/13/2018 at 11:40 AM, adallas18 said:

I'm just looking for how to change the AI of each specific mugen char. i know you can go into the data folder to the MUGEN.cfg and change it there but that changes it for all, i just wanna know where to change it inside the character's cfg file? or wherever it is

Usually, under statedef -1 in the cmd file.

Sometimes, other people use the state -2 under some CNS file. It doesn't really matter, as long as you know what you're doing.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...