YesNoOk
avatar

AI (Read 16828 times)

Started by Lost_Avenger, February 22, 2014, 08:33:31 am
Share this topic:
AI
#1  February 22, 2014, 08:33:31 am
  • ****
  • Busy, busy, busy
    • www.trinitymugen.net/forum/index.php
So, I've been wondering what makes an AI better? I'm trying to avoid things like priority spamming(or dp spam). Guard spam, excessive jumping, etc. How should the AI walk? How do you deal with crouch blocking without throw spamming(jumping is a large risk). Is there a proper way of coding AI?  Imo, my current AI sucks and I really want to improve

I'm hoping this is the right section

-
http://www.Trinitymugen.net/Hosted/CFJ2/
-
thanks again Vans/Jesuszilla!
Re: AI
#2  February 22, 2014, 04:56:58 pm
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
I'd say move this to Mugen Discussion or Development Help

A good AI is one that takes into account Mugen flaws and deals with them accordingly. When coding AI what you should aim to do is
1. Avoid triggering to many anti-airs <- A lot of coders fail at that

2. Test how much your AI triggers guard by setting them against opponents who stay in their attacking states for more than 300 ticks and adjust accordingly <- A lot of coders fail at this to

3. Try not to make your AI to dependent of hyper attacks-- do not make them use their power stock as soon as they get 1000 power so we can see some LVL 3s sometimes and do not make them dependent on the hypers so we can see how they actually fight

4. Designate a reasonable amount of times your AI will uses particular specials THAT DO NOT DO TO MUCH DAMAGE. A shoryuken anti-air with 150 damage done 6 times in 1 match has already taken over 90% of the opponent's health <- that cheap

5. Do not have your AI constantly hop back on wake-up often. That broken. Opt for a guard or a jump.

6. UNDERSTAND RANDOM! Coding two different attacks for "random <= 200" means that one of the two will not activate. What you should do is have one that is "random <= 200" and the other "random = [201,400]". Then test your random attacks to see that your AI is really varying their attacks.

PM me if you would like me to make a video illustrating these things for you

To answer one of your questions, leave walking to the default AI or copy warusaki3's code.
Last Edit: February 22, 2014, 05:01:21 pm by SeanMackgewer
Re: AI
#3  February 22, 2014, 06:02:08 pm
  • ******
  • [E]
    • Mexico
a simple way to code a multileveled ai would be:

1) leave blocking and all the movign around stuff to mugen's default ai, which means having no jumping,blocking, etc.. code in your ai.
2) make it so when the character is ai controlled the attacks don't trigger at all, so the ai avoids doing stupid stuff by accident.
3) code the ai so it performs the attacks when they make sense, so no far away dps, etc... this is teh mroe fun part as you can give it a style of play there, make it use more special moves or mroe basic moves, you can even code errors there if you wish.
4) code some combos, probably checking the ai level there.

I also suggest using varrandom instead of random, so you have better control, as random is evaluated everytime it is called. also, if you can find a way to delay the ai's attacks based on teh difficulty level that's cool too.
Re: AI
#4  February 22, 2014, 10:34:53 pm
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Quote
6. UNDERSTAND RANDOM! Coding two different attacks for "random <= 200" means that one of the two will not activate. What you should do is have one that is "random <= 200" and the other "random = [201,400]". Then test your random attacks to see that your AI is really varying their attacks.
Nope, Random generates a new number each and every time it is called. These 2 attacks have exactly the same chance to come out assuming all other triggers are the same.

Understand random, it's better to think of it in terms of probability per tick. 200 is a 20% probability to occur in a single tick. That sounds fine. But (and i know this isn't how probability actually works but it makes sense) Over 5 ticks that's 100% probability. Basically, the attack is going to fire off every 5 ticks. If that occurs other attacks WILL be taken out. Randoms below 100 actually make for better AI that does more stuff overall.

Really, AI is just testing it over and over and over. Think of a situation you want something to happen in. Code for it. Replicate it in game, does your character do what you want? If yes, next move, if no, tweak and repeat.

Something people don't get is that an AI can be hard and beatable, you need to leave flaws in. If AI is "It has touched you, you're now dead" that's generally not very fun.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: AI
#5  February 23, 2014, 12:29:17 am
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
Quote
6. UNDERSTAND RANDOM! Coding two different attacks for "random <= 200" means that one of the two will not activate. What you should dois have one that is "random <= 200" and the other "random = [201,400]". Then test your random attacks to see that your AI is really varying their attacks.
Nope, Random generates a new number each and every time it is called. These 2 attacks have exactly the same chance to come out assuming all other triggers are the same.
No, No.

Let me write it out in code for you.

These two together are wrong. State 240 will not trigger. Many coders, even warusaki3, made this mistake.
Quote
;Light Punch
type = ChangeState
value = 200
triggerall = AILevel
trigger1 = p2bodydist x < 50
 - trigger1 = random <= 200     ;same as state 240
trigger1 = ctrl


;Medium Kick
type = ChangeState
value = 240
triggerall = AILevel
trigger1 = p2bodydist x < 50
 - trigger1 = random <= 200    ;same as state 200
trigger1 = ctrl


The correction is:
Quote
;Light Punch
type = ChangeState
value = 200
triggerall = AILevel
trigger1 = p2bodydist x < 50
        - trigger1 = random <= 200         ;different as state 240
trigger1 = ctrl


;Medium Kick
type = ChangeState
value = 240
triggerall = AILevel
trigger1 = p2bodydist x < 50
        - trigger1 = random = [201,400]   ;different as state 200
trigger1 = ctrl
Last Edit: February 23, 2014, 12:41:10 am by SeanMackgewer
Re: AI
#6  February 23, 2014, 12:31:23 am
  • ******
  • If you’re gonna reach for a star...
  • reach for the lowest one you can.
    • USA
    • network.mugenguild.com/jmorphman
That doesn't actually change anything. Each time MUGEN sees "random", it generates a different number.
Re: AI
#7  February 23, 2014, 12:36:32 am
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
Doesn't it generate a random number between 1 and 999? I was under the impression that the triggers were essentially


- If the randomly generated number is 88 for example and your character has control in whatever tick, state 200 will activate.

- If the randomly generated number is 377 and your character has control in tick  whatever, state 240 will activate.
Last Edit: February 23, 2014, 12:37:17 am by SeanMackgewer
Re: AI
#8  February 23, 2014, 12:39:53 am
  • ******
  • If you’re gonna reach for a star...
  • reach for the lowest one you can.
    • USA
    • network.mugenguild.com/jmorphman
It does, but that number that's been generated is only used for that specific trigger line; it doesn't persist beyond that. You'd have to use a variable for that.
Re: AI
#9  February 23, 2014, 12:42:37 am
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
Right. You scared me at first.
Re: AI
#10  February 23, 2014, 12:57:29 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Both those codes will trigger. If you don't believe me, do this.

[State -2]
Type = DisplayToClipboard
trigger1 = gametime%10 = 0   ;this is just so you can read the numbers really before they change
params = random, random, random
text = "%d %d %d"

They will all be different.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: AI
#11  February 23, 2014, 01:12:15 am
  • ******
  • [E]
    • Mexico
yup, that is why I said to use varrandom, that way it works as intended and you don't have to make weird calculations. for this topic I tried to think ways to implement my helper system without using helpers, since my method chooses a command, then waits N ticks to actually perform it (N depends on the difficulty, the harder your mugen is, teh faster the commands will fire).
Re: AI
#12  February 23, 2014, 04:03:39 am
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
Holy crap. What accounts for that? How does random work.

I just tested it and it actually seemed to work better (not better but faster) than the <=200--=[201,400] method.

So wait, how does random actually work then?
Re: AI
#13  February 23, 2014, 04:25:56 am
  • ******
  • [E]
    • Mexico
everytime you have the word random in your code mugen gives you a new value, that's fairly standar for programming languages; if you want to have more consistent code you save the random value in a variable so you don't have to do complex calculations. something like

[state whatever]
parameter = X
trigger1= random =[0, 500]

[state whatever2]
parameter = X
trigger1= random =[501, 999]

in practice means that teh second state ctrl has got a 25% change of firing, if you add more sctrls it gets more complex, so doing

[state whatever2]
type = varset
trigger1= 1
var(X) = random

[state whatever]
parameter = X
trigger1= var(x) =[0, 500]

[state whatever2]
parameter = X
trigger1= var(x) =[501, 999]

means that each statectrl has got a 50% chance of firing, so teh actual probability claculations actually make moresense the more sctrls you add, and your ai must have at least 3 possible outputs for each possible situation (well 2, because donig nothing/blocking also count).
Re: AI
#14  February 23, 2014, 04:36:16 am
  • avatar
  • *
    • Austria
    • seanmarion91@gmail.com
Wow. Had no idea it was that complicated. I'll try it out. I need to learn more about the engine. Thanks maximilian
Re: AI
#15  February 23, 2014, 08:49:14 am
  • ****
  • Busy, busy, busy
    • www.trinitymugen.net/forum/index.php
Ah. Ive trying to keep my dashes(and possibly the walks) just within range of their pokes. I've got Phantom's jump coding iirc.

Ill look through my code when I get home. Is there a better way of coding links? I've got it set up to do specific combos, but I'm looking to try something that checks the hittimes for linkable moves. like... the enemy will be in a hit state for 6 more ticks.

-
http://www.Trinitymugen.net/Hosted/CFJ2/
-
thanks again Vans/Jesuszilla!
Re: AI
#16  March 18, 2014, 02:46:54 pm
  • avatar
  • ***
  • ̢̻̮̫̬̹̞̼̲̪̜̭͇̲͒ͪ̌ͬ̒̄̔̐͘͟ͅ ̢̋ͬ̓͗̏̇̌̑͐ͤ͗̔̊̕͏̴̣͎̟͈̬͚
    • Monaco
to make AI better prevent them to use the same hyper after previous hyper executed.
no more repeated hyper is more joyful to watch
http://signavatar.com/32255_s.gif

please visit my request thread. here
bad grammar is art
Re: AI
#17  March 19, 2014, 05:29:59 am
  • **
  • A foosball to the face!
    • USA
    • fretterg@gmail.com
If you're talking about AI in Mugen 1.0 or above, I'd suggest looking at this: http://elecbyte.com/wiki/index.php/AI
I think this is what maximilianjenus is trying to say to you, though I'm not sure.

I'll give you another example via my Dan's AI that's trying to execute his Hard/Heavy version of his Gadoken.

Code:
[State -1, AI]
type = ChangeState
value = 1120
triggerall = Var(59) > 0                             ;This is used when the AI is ON.
triggerall = Var(29) = 0                             ;This is used for Guard Checking, which is made by Adamskie to start with, but I tweaked it to be
                                                         more efficient in my game. This is to make sure the AI can't act out of his guarding state immediately
                                                         after blocking an attack.
triggerall = NumProj = 0                             ;This tells the AI that it can only shoot a fireball, if it doesn't own one on the map yet. This is to make
                                                         sure the AI can't spam his fireball constantly.
triggerall = StateType != A                          ;This tells you that the AI can't use this move in midair;
                                                         meaning that the AI has to be on the ground in order to use it.
trigger1 = P2BodyDist X <= 175                       ;The AI has to be 175 or less pixels away from the nearest enemy. If left as "P2Dist X," the AI looks at
                                                         its axis point of 0,0 and the enemy's axis point of 0,0, and looks at the distance between the two. If it's
                                                         used as "P2BodyDist X," it's the same  but the AI looks at the closest hurtboxes between theirs and the
                                                         enemy's instead.
trigger1 = EnemyNear, StateType != L                 ;The closest enemy is NOT lying down.
trigger1 = EnemyNear, MoveType != H                  ;The closest enemy is NOT hit yet.
trigger1 = Random < Var(50)*0.05                     ;This represent the AI's reaction time. Variable 50 represents the the original value of it's reaction
                                                         time, but it depends on the level. Look at AI Activation on Mugen 1.0+ via the website above that I've
                                                         given you. Guide was made by Seravy. The AI's reaction time is 5% its ORIGINAL reaction time. Example,
                                                         I've set my AI to have its original reaction time to be a value of 32.83 (Yes, you can put in decimals.),
                                                         if the difficulty is set at 6; if the value is supposed to be 5% its original value, then the value will
                                                         become ~2, or 499 frames, or ~8.3 seconds. May not sound much, but this AI uses the move quite
                                                         often at Level 6, so don't catch yourself off-guard when it comes to frames and percentages.
trigger1 = Ctrl                                      ;The AI has to be in full control of itself.
trigger2 = P2BodyDist X >= 200                       ;The AI has to be 200 or more pixels away from the nearest enemy.
trigger2 = EnemyNear, NumProj > 0 && !InGuardDist    ;The nearest enemy has at least a projectile on the field and the AI is NOT within guarding
                                                         distance with the projectile or the enemy itself. Look at "attack.dist" and "proj.attack.dist" on the
                                                         character's "Size" section of its cns file, to show how close their enemy has to be in order to go into
                                                         their guarding state.
trigger2 = Random < Var(50)*0.4                      ;The AI's reaction time to use the move is 40% its original reaction time.
trigger2 = Ctrl                                      ;The AI has to be in full control of itself.

I hope this website, along with this example, should explain everything about having better AI. I'm trying to make my AI to be similar to the ones in the SFA series, so good luck, me. ;)
Re: AI
#18  March 29, 2014, 02:59:21 am
  • *
    • Vietnam
    • trissey113.wordpress.com
1. Avoid triggering to many anti-airs  --> what is the reason? I guest it is the best way to defense since alot of char only start their poking with a short jump attack

2. Test how much your AI triggers guard by setting them against opponents who stay in their attacking states for more than 300 ticks and adjust accordingly  --> not understand

3. Try not to make your AI to dependent of hyper attacks-- do not make them use their power stock as soon as they get 1000 power so we can see some LVL 3s sometimes and do not make them dependent on the hypers so we can see how they actually fight  --> agree that should not dependent only on hyper but in my AI, I perform 1 gauge ASAP cause the effective is highest and the damage is most efficient. When it is 2k power, the damage rate is lower, because the damage of 2 gauge is not exactly double the 1gauge. So that depend on which result you want most effective or most beautiful performance? In some AI, I only trigger 1 gauge when it is counter and if I want to attack with hyper (not counter but active attack), I will look at the char's life, if life is higher, then I can wait for power to reach higher gauge

Conclusion my AI habit, I usually want the AI to get the highest potential of the moveset of the char first, then modify that highest is a considerable option to cover more opponents. If we human want to win a fighting game against the AI then the most fanstatic thing is fight with them, lose and surprisingly find out the weak point of that char ( from moveset and AI compose). Any way, we are just slower than AI, not less intelligent than machine :twisted:
Re: AI
#19  March 29, 2014, 05:21:30 am
  • ******
  • [E]
    • Mexico
about anti airs, it's very easy to bait them and they usually leave characters fully open.
Re: AI
#20  March 29, 2014, 10:07:03 am
  • ****
  • Busy, busy, busy
    • www.trinitymugen.net/forum/index.php
So should I trigger them outside of the optimal hitzone(maybe giving up on damage?). I'm coding fullgame AI so I can probably make character specific anti airs? Or is that unfair?

Some characters have quick jumps(Blanka) or have anti - anti- airs(Commando's j.hp). I can code for these if its not broken

-
http://www.Trinitymugen.net/Hosted/CFJ2/
-
thanks again Vans/Jesuszilla!