Kitty Corp Meow Mix Forums

Super Smash Bros. Brawl Hacking => Programming => Topic started by: Bero on September 11, 2013, 08:43:46 AM



Title: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 11, 2013, 08:43:46 AM
(http://i.imgur.com/HoJW3fS.png)
AIScriptpad2.0 (http://forums.kc-mm.com/Gallery/BrawlView.php?Number=34163&Moderated=All&facebook=true)
    Hello, I'm Bero, author of AIScriptpad.
    Have you ever been interested in AI coding? AIScriptpad is a program for making AI. I developed version 1 two years ago. And this time, AIScriptpad evolved drastically including new coding language, which was developed only for AI. The syntax of this language is so simple that you can learn it within 2 days. Graphical tutorial is included in the program, but I write them down here. In the program this tutorial is a lot easier to read.



Introduction
    AIScriptpad is a program for making artificial intelligence(AI) in Super Smash Brothers Brawl.
    AI should essentially play an important role in SSBB. Though this game was made to play with friends, many people spend time playing with CPU. So CPU's quality directly affects the game's quality. It goes without saying that the original AI is optimized for original game and AI doesn't work fine on modded characters. Using this program, you can fix things like your character cannot recover, use weapons, etc. Some may try to make ultimate AI which does techniques perfectly. Let's make smart AI with this.

Creating project
    What you do first is to make a "project". Project manages resources which are needed to make AI. You can create a project from Menu->File->New->Project. When you click it, a window called ProjectManager will appear. In this window, you fill these informations:Project name, Pac file to develop, Working folder in which scripts and built node will be saved. Pac file can be "FitCharMotionEtc" or "common3". The former holds AI scripts of one character in binary format and the latter holds shared AI scripts. You can mark "Use absolute" checkbox. When you create working folder in other drive, mark this checkbox. After you filled these informations, press "Create project".

Building pac file
    After you wrote scripts, you can compile into pac. Click Tool->Full rebuild and the pac file will appear in WorkingFolder/Build. You will be already able to use this pac in the game. There are other options. "Rebuild AIMain" will rebuild only AIMain scripts. The same thing can be said about "Rebuild AIPD", "Rebuild ATKD". "Full rebuild all projects" will compile all the projects in your "solution",which will be mentioned in the next page. "Build and distribute" will build pac file and copies to the place in which original pac file was stored.

Creating solution
    When you make some projects, you may want to access them and switch them at once. Solution makes it possible. Solution is a unit which manages many projects. You can regard it as a shortcut for each projects. To create solution, click File->New->Solution. After you click, a window titled "SolutionWizard" will appear. You decide the name of the solution, a place where the solution file will go, and optionally you can select projects that already exist. You can mark "Use absolute path". Then click "Create solution" and the solution will be created. You can add projects after making a solution by clicking "Add projects".

Miscellaneous features
    Find/Replace offers a function by which you can search particular texts and replace them. You can also use this function by using "ctrl+F","ctrl+H".
    In "Property", you can change some settings of the program ,project and solution. By checking"Emit command lists",the program emits raw command calls after you build a project. These command calls will be shown in LogWindow.  You can associate file formats used by AIScriptpad to AIScriptpad by selecting one of them in "Associate".
    In "Reference", you can see the usage of commands, functions, requirements, events, modules and subactions. The information are gathered from header file which defines them.
    In "Help" you can see this help or this program's description.

AIMain introduction
    AIMain is a main file which describes most of CPU's behavior. In this file you make decision and decide stick input direction and buttons to be pressed.
    You use "commands" to request the system to do some work. There are many commands but the number of really useful commands is small. Let's see from very easy example.

Stick input
    First example is "AbsStick". This command controls CPU's stick input. "AbsStick 1" moves the character to right. "AbsStick -1" moves left. The digit means how you input stick horizontally. So "AbsStick 0.5" inputs stick right with 50% power. You can specify vertical input strength. "AbsStick 0 1" inputs stick up and "AbsStick 0 -1" inputs stick down.
    There is another similar command, "Stick". The difference is that Stick takes the character's facing direction into account. Let's see an example. "Stick 1" inputs stick to the direction of the character's front. "Stick -1" inputs stick to the back. Vertical input is the same as that of AbsStick. You may wonder why we didn't name "AbsStick" as "Stick" and "Stick" as something because AbsStick seems to be standard stick input method. It's because Stick was found first and AbsStick next. At first they couldn't see difference between them and named Stick and "TargetStick".

Buttons
    After you learned stick inputs you may well wonder how to input buttons.
    To input buttons you can simply write "Button A". This inputs A button. You can specify multiple buttons writing like "Button A | R".

Input examples
    At this point, we could already write the CPU's behavior.
    A combination of "Button R" and "AbsStick 1" will have the CPU roll right. "AbsStick 0 -1","Button A" will produce DTilt. "AbsStick 0.5" will make CPU walk right and "Stick -1" will cause constant dashdance.

Variables
    To make better decision, some calculation is necessary. For example, if you would like to know if the opponent is in front of the character, you have to take the character's facing direction and the opponent's position(left or right) into consideration. You use "variables" to do this. Variables are something like boxes which contain values. There are 24 variables that can be used. To use variables, you can simply write "var0=1". This code assigns 1 to var0. "var0=var1" will copy the value of var1 to var0. You can do some calculations and assign the result using this syntax:"var0=var1+var2".
    You can get information of the environment using "Functions". Functions can be used like variables and normal values. For example, "XCoord" is a function which returns the character's x coordinate. You can use this by "var0=XCoord". Of course you can do calculations "var0=XCoord-10".
    Following code is a more advanced example. "var0=OPos*Direction" OPos is a function which returns 1 if the opponent is right and -1 if is left. Direction is a function which returns 1 if the character is facing right and -1 if facing left. So if the result of this code is positive, the opponent is in front of the character. Otherwise the opponent is in back of the character.

If sentences
    If you couldn't switch the behavior of the character depending on situations, the character would do the same thing constantly. Of course you can switch moves of CPU. "if" sentences enable it. To use if sentences, write "if var0 > 0". This code means if var0 is positive, the system will execute following codes. if sentences must be closed by "endif". After writing some lines after if sentence, write "endif" to close if block. You may want to do something if the requirement is false. In such situation, write "if !(var0>0)". If var0 is lower or equal to 0, following codes are executed.
    You may want to do something when the requirement is met and also when the requirement is not met. In such case, write "else".
if ...
    ...
else
    ...
endif
is a standard syntax of if block.
    When you want to evaluate additional requirement, you can write "elif". With elif, you can evaluate requirements if previous requirements are all false. Example:
if ...
    ...
elif ...
    ...
endif
    Please note that you cannot write "if" right after an "else" because the count of "endif" becomes wrong. Use "elif" instead.
    There are many cases that you want to evaluate multiple requirements at one time. In such cases, write "&&" "||". "&&" means "and" requirement and "||" means "or" requirement. Let's see an example. "if var0 > 0 && var0 < 10" means "if var0 is in between 0 and 10, execute following codes". "if var0 < 0 || var0 > 10" means "if var0 is negative or greater than 10, execute following codes". Finally, I show you a big example.
if XCoord > 10
    AbsStick 1
elif XCoord > 0
    Button X
else
    Stick 1
endif
    With this code, the character goes right if the X coordinate is larger than 10. Otherwise, if X coordinate is positive, presses x button. Otherwise, the character goes front.

Labels and seek
    We have looked important parts of AIMain and we have learned 70% of it. The las 30% is control flow syntax. The match lasts more than 1 frame of course. To deal with situations more than 1 frame, it is necessary to write loop. To write loop, you use these commands:"label","Return". It's a little difficult to explain in words, let me explain using an example.
label
...(Do something. Call this part A)
Return
    This code executes A and when the execution reaches "Return", the system stops execution for 1 frame. After 1 frame passed, the system resumes from the position of "label" and executes A, reaches "Return",... When you want to finish loop, there are two options. One is that you stop the execution of the routine. You can simply do this by writing "Finish". This is the example:
label
...
if var0 > 0
    Finish
endif
Return
    The other is to go other label block. You can do this by a command "Seek". By simply writing "Seek", the system searches next "label" in the code. And if it could find one, the system remember the position of it. The execution from next frame will resume from the point. This is the example:
label
...
if var0 > 0
    Seek
endif
Return

label
...
    Seek can have an argument, which refers to names of labels.
label
...
if var0 > 0
    Seek _foo
else
    Seek
endif
Return

label
...
Return

label _foo
...
Return
    In first loop,if var0 is positive, goes to _foo after 1 frame. if var0 is 0 or negative, goes to next label.

Jump and Goto
    We go on seeing execution flow. You may want to jump to next label immediately. In such case, write "Jump". With this command, the system immediately goes to a label which was saught before.
    There is a useful command named "Goto". This command resembles to Seek, but you can immediately jump to a label and you can go back to previous position. This is the example:
...
Goto _subroutine
...(A)

label _subroutine
...
Return    //go back to (A)

Routines
    AIMain codes are separated into "routines", which have their own roles. For example, routine 6031 deals with ground jab, and routine 70 deals with roll. You can call routines from AIMain script. "Call 0x6031" will call routine 6031. I have already named some routines and you can use the names as an argument. So this is valid command call:"Call Jab123". (Jab123 is the name of routine 6031). Don't forget prefix "0x" when you use raw routine names, otherwise AIScriptpad recognizes the value as normal value like "var0=1".
    Sometimes you may want to add routines. To add routines, you can do it by simply adding scripts into "Scripts" folder in the project directory.

Coding idioms
   We have aquired basic knowledge of AIMain. Now I'll explain coding idioms that are often used in binary and actual coding.
    To know whether the opponent is in front or not, write this:
var0=OPos*Direction
if var0 > 0
    //code when the opponent is in front of the character
else
   //code when the opponent is in behind of the character
endif
    When coding, we often want to wait for the character to finish current action. In such case, write this:
if !Dashing && !Idling
    Return
endif
    If you want to fast fall in air, write this code:
if InAir && YSpeed < 0
    AbsStick 0 -1 //this can be substituted with Stick 0 -1
endif
   
Coding miscs
    It is highly recommended to write comments in your source code. It's common that you cannot understand what you wrote yesterday. You can write comment by "//comment".
   
    When the compiler compiles scripts, it expands expressions into raw command calls. For example, it will expand "var0=OXCoord-XCoord" to "SetVar var0 OXCoord" and "Sub var0 XCoord". Sometimes it allocates temporary memory from var23. So usage of high number memories like var23,var22 may sometimes cause some troubles. You should avoid using such memories.
   
    When you compile, you may get some error messages. Sometimes line number in the message may be pointing odd place. In this case, the error is in header file. Check your header file or those in "Include" folder.
   
    When you are coding AI, you may discover new function, requirement, routine usage, etc. In such case you can define your findings in header file. For example, if you find a new function, you can write like this:
func MyFunc : 0x50
    This defines function number 0x50 as MyFunc. You can use this name in AIMain scripts. This is a list of definition syntaxes:
*Command---cmd CmdName : 0x(number) argument1 argument2 ...
*Function---func FuncName : 0x(number)
*Requirement---req RequirementName : 0x(number) argument1 argument2...
*Routine--- act RoutineName : 0x(number)
*AIPD requirement(situation)---event ReqName : 0x(number)
*Subaction---sact SubactionName : 0x(number)
    You can add explanation for each definitions. Write "///" just before these definitions and after ///, write explanation. It will show up in FunctionWindow,which you can open from Reference->Command,etc.

AIPD
    I will explain how to code AIPD.
   AIPD defines largely two things. Attack dice roll definitions and AIMain call definitions. Generally you don't have to edit the former. The latter defines when each AI script is called. The latter has sets of  entries which have following things: AIMain routine name,high frequency value,low frequency value,max level, min level. I explain from head. AIMain routine name is what you use as "Call" argument in AIMain. They are such as RollF, Jab123. How frequent the routine will be called is calculated by following expression: (levelvalue-min)/(max-min)*low+(max-levelvalue)/(max-min)*high. If levelvalue > max, (max-levelvalue)/(max-min) will be 1. If levelvalue < min, (levelvalue-min)/(max-min) will be 1. Levelvalue is a value which changes depending on the CPU level. This is a list of levelvalue.
Level1---0
Level2---15
Level3---21
Level4---31
Level5---42
Level6---48
Level7---60
Level8---75
Level9---100
    Each set has requirement and if the requirement is met, one of the entries in the set will be called after dice roll considering the frequency value. You can specify two requirements but you can omit one of them. This is the example:
fXClose{
    Jab123 100,0,75,21
   FTilt 30,25,100,0
}
    In this example, Jab123 and FTilt will be called when the opponent is in front of the character and they are close together. High value of Jab123 is 100,low is 0,max is 75,min is 21. High value of FTilt is 30,low is 25,max is 100,min is 0. So Jab is likely to be called in this situation.
    To specify multiple requirements to one set, you can do it by writing "&&" and "||". The role of these is the same as that in AIMain so I skip the explanation. You can also negate a requirement using "!". Usage is the same as that in AIMain.
    Sometimes you may want to set a requirement which is applied to multiple sets. In such case, write "if ..." before the head of the sets. This is the example:
if SamePlane

fXClose{
    ...
}

...
endif


ATKD
    ATKD means "Attack definition" and it defines the attacks of the character. There are entries for each subaction and each entry defines following things:
*Start frame
*End frame
*Offensive collision minimum x length
*Offensive collision maximum x length
*Offensive collision minimum y length
*Offensive collision maximum y length
Start frame and end frame are integer values and the rest can be any value. There is also a value called "unk" but it's always 0 so you don't have to be aware of it.

Debugging
    After you build pac file, you have to debug it on Wii. There are two useful codes which help you debug. Dantarion's routine visualizer code visualizes running routine in training mode. To use it, create GCT file with the code and go to training mode, turn on information, and running routine will be displayed in one of the information windows. My force code with button activation will force the system to run specified routine. While you are pressing a button, the system constantly runs the spesified routine.


    Please feel free asking me any questions about AI coding here. Also, when you find some bugs in this program, I'll be grad if you tell me how it occurred.

Screen shots:
Script
(http://i.imgur.com/cP9CVcz.png)
Interface
(http://i.imgur.com/a9xxB8T.png)
Tutorial window
(http://i.imgur.com/j40XdWQ.png)


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: pikazz on September 12, 2013, 09:05:07 AM
wow! this looks awesome! finally time to edit some AI!


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 12, 2013, 12:05:12 PM
Thank you:D
In fact, I made version 1 two years ago.
It didn't gain so much popularity and people forgot its existence. No one seems to be interested in this version too. lol

Do you have any questions? Questions not related to coding are OK.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Shun_One on September 12, 2013, 12:17:56 PM
I think no one knows what the heck to even do with this.

Would it be possible to adjust which character is a computers primary target with this?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 12, 2013, 12:30:27 PM
We couldn't set targets of CPU from AI scripts. It is decided by the game.

With this program, we could make characters recover well, use weapons, play more aggressive .  I should have made an example first.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: pikazz on September 12, 2013, 12:52:38 PM
Thank you:D
In fact, I made version 1 two years ago.
It didn't gain so much popularity and people forgot its existence. No one seems to be interested in this version too. lol

Do you have any questions? Questions not related to coding are OK.
I do actually remember that you (and possible dant) did this by playing with the AI and did program to make them more easy to edit!

and yes, I do remember you helped brawlbox at some point before bj96 took over x3

right now, I dont have any question


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 12, 2013, 01:08:18 PM
Oh thanks.
This summer I made a lot of discoveries and this version includes them.
So making good AI became easier.

I think people cannot see how this program works, so I'll make an example soon.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Tailsmiles249 on September 12, 2013, 06:12:36 PM
If it weren't for the older version, I wouldn't have made that AI mod for L-canceling. I'm surprised you even continued working on this! I'll be using this in the future and hopefully I can be more efficient with it.

I like that it looks like C++ by the way.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: SonicBrawler on September 12, 2013, 06:18:17 PM
so wit this, someone could make it so that the cpu dont team up on you, and will go after each other?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Eternal Yoshi on September 12, 2013, 06:25:58 PM
so wit this, someone could make it so that the cpu dont team up on you, and will go after each other?

That's not controlled by the AI files sadly. It's hard coded elsewhere in the game.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: SonicBrawler on September 12, 2013, 06:44:24 PM
That's not controlled by the AI files sadly. It's hard coded elsewhere in the game.

*flips desk*


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 12, 2013, 06:46:01 PM
@Tailsmiles249
I'm very surprised to see a person who uses AIS except for KingClubber.
I repeatedly stopped and resumed researching AI these 2 years. I hope you like this new version.

@SonicBrawler
As Eternal Yoshi says, it isn't controlled by AI files. Surprisingly, the developer of this game intentionally made CPUs target human players.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 13, 2013, 12:21:31 AM
Man this is great!  So much vocab though!  it is going over my head, and I onl want to make slight edits across the board.  Can I get help?  I play brawl minus and our Mario can use up special twice in succession.  The AI won't do it.  Still trying to learn everything.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 13, 2013, 08:17:59 AM
If you could tell me more specifically I would be willing to help you:)


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 13, 2013, 09:31:58 AM
Basically, I don't want to change his overall behavior, but every instance he uses upb, I want him to use it again, taking into account the ledge for recovery or me when he uses it as an attack.  Just slight edits to some characters.  From what I understand, I need to find the var in which he would do upb and edit that?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 13, 2013, 10:50:27 AM
To implement that feature, we need to do following things:
Copy recovery routine(ID:2010 and 2040) from Fighter.pac
Edit up b section

Basically, when you perform some attack, the system automatically quits current script and arbitrarily goes to other scripts. Thanks to your post, I noticed that Pikachu could use up b properly though it needs another input after up b. It is worth looking into and after I find something, I will tell you how to make Mario use up b properly.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: DoctorFlux(Mariodk) on September 13, 2013, 11:49:15 AM
this program will sure be usefull for me

so i can make a AI for goku moveset to use kamehameha right

also is it possible to make a AI to use Taunt if a Mode is actived?
like if the CPU flashing yellow and thats a sign on the mode is actived (like SSJ mode for vegeta PSA) or
 if the PSA got moveset changer on PSA as a taunt the AI will use that taunt sometimes and the AI know how to use the new moves  ?


and is it possible to change OlimarĀ“s AI
since i heard that one was hard code so even if got someone over olimar like a .rel port
it will keep using N-B all time


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 13, 2013, 11:57:10 AM
CPU's  taunt is controlled by the system and cannot be controlled by scripts by default.
Also, to know variables used in PSA, we have to make codes to get the information.
But yes, you could make Goku use Kamehameha using this program if it doesn't require complicated input.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Leon Exodio on September 13, 2013, 12:05:53 PM
i may mess around with this looks interesting


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 13, 2013, 12:18:17 PM
@Leon Exodio
I hope you would like it:)

@NEWB
Could you tell me the second-input frame?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 13, 2013, 03:54:56 PM
Figuring that out.  Do you want my motionfile?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 13, 2013, 04:36:10 PM
It would be helpful if you could give it to me.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: StupidMarioFan1 on September 13, 2013, 04:58:42 PM
Damn it'd be nice to figure this out once I finish SM64 Moveset, or one of my other WIP severally modified movesets, like Dream Luigi over Bowser or Mario & Luigi over Ice Climbers. Plus we can finally make it so CPUs don't constantly use the Mario Tornado to try and load Fludd when they're on the other side of the map. XD


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 13, 2013, 05:37:33 PM
The link to it is here.  https://www.dropbox.com/sh/v3xj8wxabn239mj/fmasIsEZ5z/private/wii/app/rsbe/pf/fighter/mario (https://www.dropbox.com/sh/v3xj8wxabn239mj/fmasIsEZ5z/private/wii/app/rsbe/pf/fighter/mario)

Post Merge: September 14, 2013, 07:55:16 PM
Does this work for bosses?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 14, 2013, 08:30:46 PM
Sorry, I haven't worked on it yet. I may work on it in a day or two.
As for bosses, I'm not sure but I think it won't work.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Akeno/Archer on September 15, 2013, 11:41:07 AM
I heard there was a contest of which one would make the best CPU character... Is it with this program that the CPUs were "made"?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: DarkPikachu on September 15, 2013, 12:22:42 PM
*looks at screenshots*
*mashes the download button*


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 15, 2013, 10:55:23 PM
@Akeno-sempai
Yes, this must be. AIS is the only AI editor that is published.

@DarkPika
Thank you. If you have any requests, feel free posting it!

@NEWB
https://www.dropbox.com/s/2yeumu4b0pogs4e/ai_mario.pac (https://www.dropbox.com/s/2yeumu4b0pogs4e/ai_mario.pac)
Please replace FitMarioMotionEtc/FitMarioEtc/ai_mario with this.
All I did is to write 1 line to a script from Fighter.pac which handles recovery.
This is the part of source:
Code:
label _2
if !(InAir) || Falling
    Finish
endif
GetRndPointOnStage var0
if !(FrameGE 4)
    var3=var1+(-10)
    if YCoord < var3
        GetNearestCliff var0
    endif
endif
if XCoord < var0
    AbsStick 1
else
    AbsStick (-1)
endif
Button B
if FrameGE 25
    Finish
endif
Return
This is a section which deals with the situation after using up B.
I added this line:Button B
With this line, Mario holds B button while using up B.
I tested this code and confirmed Mario used second up B.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 15, 2013, 11:57:20 PM
Thanks so much!  Still studying the tutorials.  I want to learn how this works to help the brawl minus team.  When I need help understanding it, I will ask.

Post Merge: September 16, 2013, 12:40:40 AM
Does Mario know that he can reverse directions?  That he can go left and then go right with the second upb?  Does he also know that if he overshoots the ledge that he doesn't need to use it twice?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 12:54:04 AM
No, I have little time now and didn't implement them.
To implement direction change, I would write like this:
label _2
if Rnd < 0.5    //50% right
    var4=1
else    //50% left
    var4=-1
endif
label
...    //the same as previous post
Button B
AbsStick var4 1    //input stick

To implement only 1 input, I would write like this:
label _2
...
GetNearestCliff var0    //var0=Nearest Cliff X coordinate, var1=Nearest Cliff Y coordinate
if YCoord < var1
    Button B
endif

However I didn't test these codes.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 16, 2013, 01:55:33 AM
So bero, you basically exported AImario.pac with brawl box and opened it using the AIScriptpad?  As you can tell, I don't want to make AI from scratch, there are just some additions that I want to make.  Is this how I would take and edit the existing AI?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 02:05:04 AM
As I wrote in tutorial, AIScriptpad loads FitChar(Motion)Etc.pac, common3.pac, and Fighter.pac. After the program loads these pacs, it automatically exports scripts. After that, you can edit them.
After you make a project, you won't have to do these steps next time.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: DarkPikachu on September 16, 2013, 08:15:55 AM
Thank you. If you have any requests, feel free posting it!

indeed ;)

I havn't installed it yet due to massive amounts of web cleanup and reorganization I'm trying to perform...
(especially with my forum)

but once I install it,
I hope you don't mind me requesting convenience features. :)
(some of them may be complex)


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 16, 2013, 10:13:29 AM
No, I have little time now and didn't implement them.
To implement direction change, I would write like this:
label _2
if Rnd < 0.5    //50% right
    var4=1
else    //50% left
    var4=-1
endif
label
...    //the same as previous post
Button B
AbsStick var4 1    //input stick

To implement only 1 input, I would write like this:
label _2
...
GetNearestCliff var0    //var0=Nearest Cliff X coordinate, var1=Nearest Cliff Y coordinate
if YCoord < var1
    Button B
endif

However I didn't test these codes.

So, do I edit what you edited to look this?  And when you say same as previous ost, I squeeze that in there?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 01:57:43 PM
@DarkPika
I'm a little feared by your word 'complex' :)
But I will do my best when you give me feedback though I cannot touch my PC for 2 weeks from now.

@NEWB
Yes, please place correspond part there. To be more specific, lines after "label _2" and before "Button B".
However the code isn't tested so you may have to do trial-error.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: ??_? on September 16, 2013, 05:44:43 PM
I heard there was a contest of which one would make the best CPU character... Is it with this program that the CPUs were "made"?
That was mine from like 2 years ago back when v1.0 was released. Nobody submitted anything though.

Good to see you bero, looking forward to some AI submissions in the vault soon


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Tailsmiles249 on September 16, 2013, 05:47:44 PM
I managed to clean up my L-canceling code for Project M by a lot. It still only works for individual attacks but it's much made progress. Unfortunately, there are some issues when dealing with platforms. I would assume the Y Coordinate is relative to what's directly below a character. This is still a good thing since it won't end up only L-canceling at the very ground. However, when moving around, the Y coordinate (assuming I'm correct) changes drastically when moving over a platform (ground is lowest -> platform is lowest).

Here's an example for Marth's Nair:

Code:
if FrameGE 1 && !(FrameGE 2)
    Button A
endif
if FrameGE 3 && !(FrameGE 24) && InAir
    if FrameGE 15 && !(FrameGE 16) && InAir  // Ideal Fast Fall Frame
        Stick 0 (-1)
    endif
    if YCoord <= 1  // L-cancel when close to the ground
        Button R
        Finish
    endif
Return
endif
if FrameGE 24 || !(InAir)
    Finish
endif
Return


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 06:20:39 PM
@ NaOH
My previous version had many problems like complex syntax, UI bugs, and this is the largest, lacked much information which was necessary to implement AI.
This version solves these problems. So I hope many people use this.

@Tailsmiles249
If you would like to know distance between platform and the CPU, "GetNearestCliff" is useful. It returns nearest cliff coordinates into specified variables. For example,
GetNearestCliff var3
results in that var3=nearest cliff x coordinate, and var4=nearest cliff y coordinate.
If the stage is flat, this will work fine with your code.

Have you already learned AI coding!?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Tailsmiles249 on September 16, 2013, 06:43:24 PM
In a sense I did; I can at least read it without much problems.

So are you telling me "Cliff" doesn't refer to a ledge? It simply refers to an sort of floor?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 07:05:31 PM
It doesn't always return ledge coordinate. Stages like Summit don't have ledge and this command returns the left or right end of the floor on which CPU is.
If you want to get coordinates of ledge, use GetNearestHangable.
I didn't know the term 'ledge' when I found this command so I named like this.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: DarkPikachu on September 16, 2013, 07:41:15 PM
@DarkPika I'm a little feared by your word 'complex' :) But I will do my best when you give me feedback though I cannot touch my PC for 2 weeks from now.

lol not in my terms of complexity, is what I mean. XD
it's the normal terms of complexity, meaning things shouldn't be 50x more complex than average ;)
(at least... this is what I hope for)

and pardon my curiosity, but may I ask why?? ._.
or would you rather feel better not explaining it??


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 16, 2013, 08:05:23 PM
It's very personal reason that I have club activity event in my university.
After that, I return home for 1 week.
I usually work using desktop PC so I cannot touch it.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 16, 2013, 08:27:40 PM
So, I found where you made the change in 2040.as, only it said label _0 not 2.  I am now trying to change it.

Post Merge: September 16, 2013, 09:09:58 PM
Can you show me what the whole code should now look like, so I can compare?  Not sure I did it right...


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Tailsmiles249 on September 18, 2013, 08:50:41 AM
Alright, I've redone my L-cancel code a bit, but I think I found the real issue: Looping. While it does seem that the code is looping, the AI will only press 'R' either on the 3rd frame or on a fast fall frame when close to the ground.

Marth's Nair:

Code:
if FrameGE 1 && !(FrameGE 2)
    Button A
endif
if FrameGE 3 && !(FrameGE 24) && InAir
    GetNearestCliffR var0
    if FrameGE 15 && !(FrameGE 16) && InAir && !OutOfStage  // Ideal Fast fall frame
        Stick 0 (-1)
    endif
    if var1 <= 1  // L-cancel when close to the ground
        Button R
        Finish
    endif
Return
endif
if FrameGE 24 || !(InAir)
    Finish
endif
Return


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 18, 2013, 03:22:25 PM
@NEWB
I'm sorry but I am using smart phone to post here and cannot use my PC for 4 days.
When I return home, I will post the script.

@Tailsmiles249
It's an inherent issue.
The AI system cancels execution when the character performs attack.
To avoid it, you have to edit AIPD to load only 1 routine when on stage.
However, it means you have to write all the moves in one script.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 18, 2013, 04:46:43 PM
I know.  You said you couldn't a few posts ago.  Don't worry about it.

Man this thing is awesome!  I can't wait to have the minus AI coded better!  I will really be able to get behind this once I figure it out.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 24, 2013, 02:57:41 AM
https://www.dropbox.com/s/4usnwtgfl2grg29/FitMarioMotionEtc.pac (https://www.dropbox.com/s/4usnwtgfl2grg29/FitMarioMotionEtc.pac)
I haven't tested this so I can't guarantee if it works.

I can use my PC now but can't use wii until September 30th.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Kneato on September 24, 2013, 11:49:10 AM
Hey Bero. Kudos on making such a slick program. I have a problem though and googling around hasn't helped that much.

1: Where is the AIMain file located? When I open up a character's MotionEtc, all I see are the AIPD, ATKD, and routine files.

2: One of your comments says this program utilizes common3, MotionEtc, and Fighter.pac files. Where are fighter.pac files located? They aren't the "FitCaptain.pac" or "FitLuigi.pac" type files are they?

Thanks!


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 24, 2013, 05:26:20 PM
A.
1. AIMain file is located in FitChar(Motion)Etc/FitCharEtc/ai_char/MiscData[2].
BJ's BrawlBox displays it as "CE", which is a name based on my misunderstanding 2 years ago.

2. You can find Fighter.pac in Disc/fighter/Fighter.pac. Fighter.pac is also buried in common3 so editing Fighter.pac is the same thing as editing common3. File Patch Code cannot load Disc/fighter/Fighter.pac and you will have to edit common3 if you would like to change overall AI behavior.

Further questions are of course OK.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 25, 2013, 12:14:08 AM
Thanks Bero!  Works much better now.  I will now try to tell the AI to do side b for some other characters in minus.  Will come back for assistance if needed.

Post Merge: September 25, 2013, 10:10:06 AM
Having an issue with squirtle's AI. I want to copy paste you did to Mario and put it in squirtle, but the poketrainer is organized differently.  If you can point me to where squirtle uses up b to recover, I can make the change.  Probably.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Albafika on September 25, 2013, 10:12:49 AM
Ohh boy, now I know how I'll waste my free time. Thanks for sharing, Bero!


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Kneato on September 25, 2013, 02:26:18 PM
Thanks Bero! That makes much more sense. Another question sir. What exactly is the function of * in this language? For example this snippet "var14*=-1" what exactly does it do?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 25, 2013, 04:32:29 PM
@NEWB
Squirtle doesn't overrides default recovery AI so you have to take 2040 from common3 and paste it in Squirtle's source folder. Then, you can edit it as you'd like.

@Albafika
The language is easy to understand so you may not waste so much time ;)

@Kneato
It works like other programming language. * means "multiply" so "var14*=-1" means "change sign of var14".


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 25, 2013, 05:38:44 PM
I take the entire 2040 and paste it in squirtle's motion or poketrainer's motion?  I assume squirtle's.

Post Merge: September 25, 2013, 05:56:06 PM
I'm not sure how to add it in with brawl box.  I exported 2040 from common3, fighter, aicommon, events.  That is the 2040 I found.  I don't know how to add into squirtle's motion.  I know how to replace existing things, but not add them in.  Do I just play with the import button?
I should probably upgrade brawl box from 0.68c to 0.68d.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 25, 2013, 08:22:32 PM
Please use AIScriptpad2.0. Rebuilder of BrawlBox is made by me and it contains bugs.

First, create project specifying common3. It automatically exports scripts into source folder.
Then, create project of squirtle and copy 2040.as from common3 source folder and paste it in squirtle's source folder. Then, press Tool->Full build and squirtle's pac file is built in "Build" folder.

EDIT:
Squirtle's pac file is FitPokeZenigameMotionEtc.pac


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: E-scope12 on September 27, 2013, 12:11:41 PM
What about Brawl stages for this program?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Mr. AI | Sluigi123 on September 27, 2013, 04:26:31 PM
Let's say you're modifying Fox's Up-B recovery tactics. If I want to have the AI have a limitation of directing Fox between angles during startup of his UpB, how would you code it for it work?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 27, 2013, 05:44:21 PM
@E-scope12
Could you explain what you mean by "stage" more specifically?

@sluigi123
I would find the position where Fox uses up B and write like this:
if var0 > 0.5
    var0=0.5
elif var0 < 0.3
    var0=0.3
endif
if var1 > 0.5
    var1=0.5
elif var1 < 0.3
    var1=0.3
endif
AbsStick var0 var1

I'm not sure if I answered your question though.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: NEWB on September 28, 2013, 04:16:44 PM
Having issues with squirtle.  For using up b, like Mario, do I need to edit the same label number?

Squirtle's up behaves like Mario!s in minus, except holding b gets him more air instead of the attack repeating.  I added button b like you did to Mario at the end before Finsh and now, he uses Neutral instead of up b.  I assume I edited the wrong label.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on September 28, 2013, 05:23:41 PM
I think yes.
If I remember correctly, the label number was 2.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: E-scope12 on October 01, 2013, 11:33:05 AM
@E-scope12 Could you explain what you mean by "stage" more specifically? @sluigi123 I would find the position where Fox uses up B and write like this: if var0 > 0.5    var0=0.5 elif var0 < 0.3    var0=0.3 endif if var1 > 0.5    var1=0.5 elif var1 < 0.3    var1=0.3 endif AbsStick var0 var1 I'm not sure if I answered your question though.
I mean The Brawl stages in brawl like Battlefield, Final Destination, Delfino Plaza, Bridge of Eldin, Halberd & Spear Pillar.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on October 02, 2013, 12:23:37 PM
AI works on every stage if it is coded properly.
Is this answering your question?


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: E-scope12 on October 02, 2013, 12:40:01 PM
AI works on every stage if it is coded properly.
Is this answering your question?
Sure I guess that helps.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Kneato on October 03, 2013, 05:16:01 PM
Hey Bero, another question. Do you have a general list for what each .as protocol controls? Like is 2010 recovery, 3030 grabs etc etc


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on October 03, 2013, 11:33:45 PM
They are defined in Routines.h.
Routines which start with "Unk" are unknown. But using Dantarion's visualizer code, you may figure out something.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Kneato on October 04, 2013, 03:45:47 PM
I'm sorry I have so many questions, but I'm just trying to get the hang of this and haven't done any AI work before. What is Dantarion's visualizer code? Or could you at least give me a link to it and I'll figure it out. Thank you :)


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Bero on October 04, 2013, 04:36:20 PM
I included small debug codeset in AIScriptpad zip.
Visualizer code is this:
Training Mode AI Super Debuggah ALPA v0.1xgt [Dantarion]
* C2918964 00000010
* 901900B8 90820000
* 90A20004 90C20008
* 90E2000C 91020010
* 90620014 91420018
* 9162001C 91820020
* 3C00803F 600089FC
* 7C0903A6 3C608167
* 606375AB A099007C
* 3C809014 60840000
* 4E800421 38800001
* 98860005 80820000
* 80A20004 80C20008
* 80E2000C 81020010
* 80620014 81420018
* 8162001C 81820020
* 2C050000 00000000
* 4A000000 90000000
* 14140000 25303458
Go to training mode and turn on information window. One of them shows current executing routine.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: GenRJ on April 06, 2014, 01:44:49 AM
When I try to rebuilt the log shows this error: System.OutOfMemoryException'.

What does it mean?

Thanks.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: DarkPikachu on April 18, 2014, 09:02:31 AM
I'm still interested to figure out how Brawl's AI is capable of learning and adapting...
(it's a proven fact, and I have experience in fighting my CPU and training it)
^ my CPU no longer edge-hogs and now fights with a more TAS-like fighting style.

for the skeptics:
I havn't made any mods to my AI and have no reason to lie to anyone here. ;)


the actual "learning" code may not be located in the local character's AI but maybe in the games's script...

I just find it interiguing how you can actually train your CPU. :3
I just wish it was easier to train them. XD

anyone know anything towards this?? :)


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: PPXEXE on March 30, 2015, 12:29:43 PM
AI Do Not Learn, they are programmed.

Sorry for necroposting. Please fill free to PM me if anyone has any questions.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: teh-myuutsu on August 17, 2015, 05:14:34 AM
Why don't people do more guides on this? Also, I'm sorry for necroposting, it's just that this is the only place where I will be able to learn.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Alexarah2014 on December 14, 2015, 10:30:51 PM
Hi Bero do you know if this awesome tool you made will work with Project M? The Project M team heavily altered the AI somehow for them to tech the way they do in the latest releases.


Title: Re: [AI coding]AIScriptpad2.0 Support Thread
Post by: Ebola16 on December 19, 2019, 09:24:52 PM
I used the latest version of this program for a quick fix that can be further customized for better results: AI teleporting recovery for custom movesets based on non-teleporting characters (http://forums.kc-mm.com/index.php?topic=81003.0)