Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shymeck's AI
#1
I decided to publish some AI scripts independently from LF2 Plus mod. So here they are:

Silva's AI:
Code:
int face_distance()
// distance to target, positive when faced towards it
// 80 pixels may be considered as a maximum distance allowing close combat
{
    return ( self.x - target.x ) * ( 2 * ( self.facing ? 1 : 0 ) - 1 );
}

bool dist_between( int min, int max )
// checks whether distance to target is within bounds
{
    return ( ( face_distance() < max ) && ( face_distance() > min ) );
}

bool z_axis_dist( int dist )
{
    return ( abs( self.z - target.z ) <= dist ) ? true : false;
}

bool same_z_axis()
// checks whether our character is on the same z axis as the opponent
{
    return ( abs( self.z - target.z ) <= 8 ) ? true : false;
}

int ego()
{

    // mid and long range

    if( self.frame == 235 )
    {
        if( dist_between(400,700) && ( self.mp > 350 ) )
            D();
        if( dist_between(150,400) && (self.mp > 200) )
            J();
    }

    if( dist_between(400,700) && ( self.mp > 350 ) )
    {
        if( self.facing )
        {
            DlA();
        }
        else
        {
            DrA();
        }
        return 0;
    }

    if( dist_between(150,400) && same_z_axis() && ( self.mp > 70 ) && ( target.state < 3 ) )
    {
        if( self.facing )
        {
            DlA();
        }
        else
        {
            DrA();
        }
        return 0;
    }

    // close range combos

    if( self.frame == 257 )
    {
        if( target.state == 12 )
            J();
        if( target.y == 0 )
            A();
        return 0;
    }

    if( self.frame == 75 )
    {
        J();
        return 0;
    }

    if( dist_between(10,60) && ( target.state < 3 ) && same_z_axis() && ( self.mp > 50 ) )
    {
        DdA();
        return 0;
    }

    return 0;
}

Aeron's AI:
Code:
int face_distance()
// distance to target, positive when faced towards it
// 80 pixels may be considered as a maximum distance allowing close combat
{
    return ( self.x - target.x ) * ( 2 * ( self.facing ? 1 : 0 ) - 1 );
}

bool dist_between( int min, int max )
// checks whether distance to target is within bounds
{
    return ( ( face_distance() < max ) && ( face_distance() > min ) );
}

bool z_axis_dist( int dist )
{
    return ( abs( self.z - target.z ) <= dist ) ? true : false;
}

bool same_z_axis()
// checks whether our character is on the same z axis as the opponent
{
    return ( abs( self.z - target.z ) <= 8 ) ? true : false;
}

void select_nearest_opponent()
{
    int temp;
    int k = -1;
    int min_dist = 0;
    for( int i = 0; i < 400; ++i )
    {
        temp = loadTarget(i);
        if( ( temp == 0 ) && ( target.team != self.team ) && ( ( abs( self.x - target.x ) < min_dist ) || ( k == -1 ) ) )
        {
            k = i;
            min_dist = abs( self.x - target.x );
        }
    }
    loadTarget(k);
}

void follow_target()
{
    if( ( self.x > 100 ) && ( self.x < stage_bound - 100 ) )
    {
        if( self.x > target.x )
        {
            left();
            if( face_distance() > 400 )
                J();
        }
        if( self.x < target.x )
        {
            right();
            if( face_distance() > 400 )
                J();
        }
        if( self.z + 3 < target.z )
            down();
        if( self.z > target.z + 3 )
            up();
        if( dist_between(-25,25) )
            J(); // we do not want to be too close..
    }
    else
    {
        if( self.x <= 100 )
            right();
        if( self.x >= stage_bound - 100 )
            left();
    }
}

void attack_opponent()
{
    if( target.team != self.team )
    {
        if( dist_between(100,200) && same_z_axis() && ( self.mp > 300 ) && ( target.state != 14 ) )
        {
            if( self.facing )
            {
                DlJ();
            }
            else
            {
                DrJ();
            }
            return;
        }
        if( dist_between(200,500) && same_z_axis() && ( self.mp > 200 ) && ( target.state != 14 ) )
        {
            if( self.facing )
            {
                DlA();
            }
            else
            {
                DrA();
            }
            return;
        }
        if( dist_between(100,200) && same_z_axis() && ( target.state < 3 ) && ( target.state != 14 ) )
        {
            J();
            return;
        }
        if( dist_between(50,100) && same_z_axis() && ( target.state != 14 ) )
        {
            A();
            return;
        }
    }
}

void reset_input()
{
    left(0,0);
    right(0,0);
    up(0,0);
    down(0,0);
    A(0,0);
    D(0,0);
    J(0,0);
}

void id()
{
    reset_input();
    if( !stage_clear )
    {
        select_nearest_opponent();
        attack_opponent();
        follow_target();
    }
    else
    {
        right();
        if( !self.facing )
            J();
    }
}

Frozen's AI:
(YinYin and Siegvar's Frozen version)
Code:
int face_distance()
// distance to target, positive when faced towards it
// 80 pixels may be considered as a maximum distance allowing close combat
{
    return ( self.x - target.x ) * ( 2 * ( self.facing ? 1 : 0 ) - 1 );
}

bool dist_between( int min, int max )
// checks whether distance to target is within bounds
{
    return ( ( face_distance() < max ) && ( face_distance() > min ) );
}

bool z_axis_dist( int dist )
{
    return ( abs( self.z - target.z ) <= dist ) ? true : false;
}

bool same_z_axis()
// checks whether our character is on the same z axis as the opponent
{
    return ( abs( self.z - target.z ) <= 8 ) ? true : false;
}

int ego()
{
    if( ( self.frame >= 261 ) && ( self.frame <= 269 ) )
    {
        if( ( target.state == 13 ) || ( target.state == 14 ) )
        {
            D();
            return 0;
        }
        if( ( self.frame == 269 ) && ( target.y == 0 ) )
        {
            D();
            return 0;
        }
        return 1;
    }
    else
    {
        // grab the opponent if he is prone to :)
        if( dist_between(40,80) && ( target.state == 16 ) && same_z_axis() )
        {
            if( self.facing )
                left();
            else
                right();
            return 0;
        }

        // while grabbing
        if( ( self.state == 9 ) && ( target.state == 10 ) && same_z_axis() && ( self.ctimer < 75 ) && ( self.mp > 30 ) )
        {
            DJA();
            return 0;
        }

        if( dist_between(10,50) && ( target.state == 3 ) && same_z_axis() && ( self.mp > 30 ) )
        {
            DJA();
            J();
            return 0;
        }

        if( dist_between(25,80) && ( target.state < 3 ) && same_z_axis() && ( self.mp > 60 ) )
        {
            DdA();
            return 0;
        }

        if( dist_between(150,500) && same_z_axis() && ( self.mp > 200 ) )
        {
            if( self.facing )
            {
                DlA();
                A();
            }
            else
            {
                DrA();
                A();
            }
            return 0;
        }

        if( dist_between(-200,200) && z_axis_dist(70) && ( self.mp > 400 ) && ( target.state != 13 ) && ( target.state != 14 ) )
        {
            DuJ();
            return 1;
        }
    }
    return 0;
}

Enjoy.
Reply
Thanks given by:
#2
At least please tell us what does AI do for us?
This place motivates me to become an artist, this place motivates me to learn coding, this place made me grow up, showed me the ways to interact with people. Unlike the old childish of me myself, I've learned a lot and gotten some experiences. For me, it's not just a fan forum, it's a helpful community. From a noob to someone who would think before he speaks, looking back at my old post made me laugh hard, I'm grateful of the differences between these 2 years.
~Thank You All and Farewell
~Goodbye, LFE.
RIP - 14/04/2014
Reply
Thanks given by:
#3
(08-12-2012, 06:37 AM)Hero destroyer Wrote:  At least please tell us what does AI do for us?

where have you been the past few months?
[this thread] will answer that question.

@topic
i haven't tried it out yet, will do some point in the future



Azriel~
Reply
Thanks given by:
#4
He probably meant "What does this AI do opposed to basic AIs?", which is a valid question.
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#5
Characters with AI use combos, I think it was the main reason of AI scripts creation. I especially like Frozen's one. Every script is meant to be also used in Stage Mode, it is really nice to watch our companion moves. Unfortunately they are pretty poor in 1vs1 (just like classic characters, maybe a bit better). If you do not like installing them yourselves, download LF2 Plus Mod/Pack, it was meant to present AI scripts "out-of-the-box", although I should think about some kind of automatic installer (but not simple data.txt exchange, some people do not use legacy LF2).
Reply
Thanks given by:
#6
i really like the structure of the Aeron AI

i'm starting to think about applying something as simple as that to my template AI and also try to make it learn about it's capabilities (i.e. have preset range/load/cool/damage/risk etc variables for each basic attack that the AI will measure and thus optimize conditions on its own)
this will be fun
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)