Home Gallery Resources The Team Rules chat Login Register
Pages:  [1] 2 3 4 5
Author Topic: [AI coding]AIScriptpad2.0 Support Thread  (Read 61689 times)
0 Members and 1 Guest are viewing this topic.
Bero
Expert Kitten
****
Offline Offline

Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « on: September 11, 2013, 08:43:46 AM »


        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

    Interface

    Tutorial window

    Logged

    pikazz
    Heroic Kitten
    **
    Offline Offline

    Posts: 2286


    Machinimator!

  • Awards Renowned Hacker Pin Collector Good Citizen Helping Hand

  • View Profile Awards
    « Reply #1 on: September 12, 2013, 09:05:07 AM »


    wow! this looks awesome! finally time to edit some AI!
    Logged

    Stupid Tinypic :C

    Bero
    Expert Kitten
    ****
    Offline Offline

    Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « Reply #2 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.
    Logged

    Shun_One
    Lol Kitten
    *********
    Offline Offline

    Posts: 888


  • Awards >9000 Star Hacker Smash 3 Team Pin Collector

  • View Profile WWW Awards
    « Reply #3 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?
    Logged

    I'm no longer around. If you really need to get my attention, send a PM

    Bero
    Expert Kitten
    ****
    Offline Offline

    Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « Reply #4 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.
    Logged

    pikazz
    Heroic Kitten
    **
    Offline Offline

    Posts: 2286


    Machinimator!

  • Awards Renowned Hacker Pin Collector Good Citizen Helping Hand

  • View Profile Awards
    « Reply #5 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
    Logged

    Stupid Tinypic :C

    Bero
    Expert Kitten
    ****
    Offline Offline

    Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « Reply #6 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.
    Logged

    Tailsmiles249
    Advanced Kitten
    ***
    Offline Offline

    Posts: 32


  • Awards Star Hacker Active Contributor >9000 Diamond in the Rough

  • View Profile Awards
    « Reply #7 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.
    Logged


    SonicBrawler
    Magical Girl
    Overlord Kitten
    ******
    Offline Offline

    Posts: 6977


    Bae

  • Awards Star Hacker Renowned Hacker Active Contributor Heart Container

  • View Profile WWW Awards
    « Reply #8 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?
    Logged

    Quotes:
    Not all people have the luxury of being able to buy things whenever they want.

    Some people are barely scraping by in the economy.
    Modding has made you guys so spoiled.

    Eternal Yoshi
    Heroic Kitten
    **
    Offline Offline

    Posts: 2425


    Boss? Is that you?

  • Awards KCMM Old Timer Super Saiyan Topic Active Contributor Former PMDT

  • View Profile Awards
    « Reply #9 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.
    Logged


    SonicBrawler
    Magical Girl
    Overlord Kitten
    ******
    Offline Offline

    Posts: 6977


    Bae

  • Awards Star Hacker Renowned Hacker Active Contributor Heart Container

  • View Profile WWW Awards
    « Reply #10 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*
    Logged

    Quotes:
    Not all people have the luxury of being able to buy things whenever they want.

    Some people are barely scraping by in the economy.
    Modding has made you guys so spoiled.

    Bero
    Expert Kitten
    ****
    Offline Offline

    Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « Reply #11 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.
    « Last Edit: September 12, 2013, 06:48:48 PM by Bero » Logged

    NEWB
    Intermediate Kitten
    **
    Offline Offline

    Posts: 19


    View Profile Awards
    « Reply #12 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.
    Logged

    Bero
    Expert Kitten
    ****
    Offline Offline

    Posts: 65

  • Awards Fiery Topic

  • View Profile Awards
    « Reply #13 on: September 13, 2013, 08:17:59 AM »


    If you could tell me more specifically I would be willing to help you:)
    Logged

    NEWB
    Intermediate Kitten
    **
    Offline Offline

    Posts: 19


    View Profile Awards
    « Reply #14 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?
    Logged

    Pages:  [1] 2 3 4 5
    Print
    Jump to: