Sign in to follow this  

AI System in Actionscript - Sorting Arrays

This topic is 4028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I'm Patrick. I'm new here... and I have a problem. I'm now working on the battle system for my game and I'm now officially stuck with the enemy AI. To begin with the system I want to be able to have all information about the enemy ready for use. So my step now is finding the enemy's strongest to weakest attacks from an Array. Here's what I have. Code: enemyAttacks = new Array(); for(kP=0;kP<4;kP++){ enemyAttacks[kP] = new Array(); enemyAttacks[kP]['name'] = _root['enemyAttack'+(kP+1)]; enemyAttacks[kP]['ap'] = _root['enemyAttack'+(kP+1)+'_AP']; enemyAttacks[kP]['damage'] = _root['attack_'+enemyAttacks[kP]['name']+'Damage']; } That all works nicely. But sorting it is kind of tricky, considering that it's a pretty intricate array. I need each of these to contain all the info of the attack (name, ap and damage), except in a way that it's ordered from strongest to weakest (or other way around.. doesn't really matter). Could someone give me a headstart here. I'm kinda stuck.

Share this post


Link to post
Share on other sites
Well, this is more of an idea than an answer, but hopefully it'll give you an idea.

Put this in some old frame in a new movie and observe:

a = new Array();
for( i = 0; i < 10; i++ ){
a[i] = new Array();
a[i]['nifty'] = random( 10 );
}

for( i = 0; i < 10; i++ ){
for( k = 0; k < 10; k++ ){
if( a[k]['nifty'] < a[k-1]['nifty'] ){
temp = a[k];
a[k] = a[k-1];
a[k-1] = temp;
}
}
}

for( i = 0; i < 10; i++ ){
trace( a[i]['nifty'] );
}


Hope this helps!

Share this post


Link to post
Share on other sites
Thanks guys - I got some help on another forum and yeah, it did involve the sortOn thing. It's pretty complicated.. o_o' But thanks anyway.. It's working fantastically. Although writing an AI system that works effectively isn't the easiest thing in the world... I'm worried. :P

Share this post


Link to post
Share on other sites
Agreed. I think I'm going to make it a bit simple... but.. yeah. How many 14 year olds make fully functional AI scripts?

Basically all he does as of now is, depending on how intelligent he is (a set number between 0 and 100), makes either a random move, or a systematic one. If it's random he just takes any attack out of four, but if he goes for systematic.. then he checks for.. user health/initial health/is the user better off and such and such.

It's not movement either so that makes the whole thing a lot simpler for me. It's just one of them battle engines similar to the one from them Pokémon games. XD

Share this post


Link to post
Share on other sites

This topic is 4028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this