Optimal damage algorythm

You must understand the Game Editor concepts, before post here.

Optimal damage algorythm

Postby Leif » Sat Oct 08, 2011 8:38 pm

Hi, guys.
Please help me with the next:

There are 6 soldiers, and each soldier have own Damage value. Also there are 6 targets, each have own HP value. On press SHOOT! button they all starts to shoot ( Damage subtracts from HP and if HP<=0 target is destroyed).
Any soldier can apply all his damage to any one target. Several soldiers can shoot the same target. FOr example, if two soldiers have damage values of 2 and 3, they can:
- destroy two targets with HP 2 and HP 3 correspondingly;
- destroy one target with HP 5 or less;
- hit 6HP-target (it stays with 1 HP);
these 2 soldiers can NOT shoot for 3 or more targets anyway;

So, task is - destroy as many targets as possible, and survivers (if any) must get maximum damage. What's the algorytm ??

Program applied. All I need is code to "SHOOT!" button :) :)
Attachments
SixShot.zip
(452.31 KiB) Downloaded 132 times
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Optimal damage algorythm

Postby EvanBlack » Sat Oct 08, 2011 10:16 pm

Looking at the game. I need more information on what is suppose to be happening. The interactions...

Do the soldiers acquire targets automatically, or are targets assigned to the soldiers by the player?

In which case, it would be good to have a canvas set up over the view and on mouse click of solider change animation to highlight the solider, then on mouse click of target draw line from solider to target.

Then make actor variables as such:

int HP
int Damg
int Target

Then on click assign values to each soldier based on the target ID.

Each actor will have the same variables. So you can assign each target an ID when you create it through:

CreateActor("p_target", "1", "(none)", "(none)", -325+130*i, 120, true)->Target = i;

Then when you click on the target after clicking on the solider you can get the value of the target clicked and assign it to the soliders target variable.

Then when you click the shoot button make a global int variable called OnShoot.

Then make a Timer event for the solider

( DO NOT USE: Draw Actor -> Script Editor -> )

Timer-> Script Editor
Code: Select all

if(OnShoot) {
    char buffer[15];
    sprintf(buffer, "p_target.%i", Target);
    getclone(buffer)->HP = HP-Damg;
}


Also since you are using create actor-> script editor to create the texts you can do this

CreateActor("t_target_HP", "icon", "Event Actor", "(none)", 10, 20, false)->Target = Target;

That assigns the target value of the target to the target text.

But then you have to do all the other stuff like updating the text of each t_target_HP through another Timer actor event like.

Timer-> Script Editor ->

Code: Select all
char buffer[15];
sprintf(buffer, "p_target.%i", Target);
sprintf(text, "%i", getclone(buffer)->HP);


that gets the HP value of the target and updates it.


But then you need to create a conditional event for each target.

Code: Select all
if(HP <= 0)
{
   char buffer[15];
   sprintf(buffer, "t_target_HP.%i", Target);
   DestoryActor("buffer");  // Destroy the text first to avoid errors
   DestroyActor("Event Actor");
}



But if you want each solider to just look for an open target then you have to check to see how many clones are left and assign the Target value on the Solider accordingly.

EDIT:
The only thing you need to do is make a timer for all the actors, Which you can do on create actor. You want their timers started when they are created. But if you can make all the events occur on one timer that's optimal.

Using for loops to iterate through your clones and updating there variables is the best way.
Last edited by EvanBlack on Sun Oct 09, 2011 6:44 pm, edited 1 time in total.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Optimal damage algorythm

Postby Leif » Sun Oct 09, 2011 10:40 am

Thanks a lot.

Probably i did not explain quite clear.
I need some kind of AI. So, i created a model with soldiers and targets. Main idea is - when player presses "SHOOT" button PC thinks and desides, which soldier fires which target. Goal is to destroy as many targets as possible
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Optimal damage algorythm

Postby EvanBlack » Sun Oct 09, 2011 6:36 pm

Well first you need to put all their damage values into an array, but in the case that each soliders holds its own damage value, then you just have to go from the clone array already available.

You have to compare against each target, start by setting all the highest damaging soldiers to the highest HP targets unti HP = 0. Use a for loop to iterate through your soldiers and your targets getting the highest values first and pushing them onto arrays called targetArray and soldierArray. This way when the loops finish, you have a list of all your highest value targets and highest damage soliders on the front of the stack.

Then, you go through the stacks, you do another for loop to iterate through your soldiers until the addedDamage value matches the current target's HP on the stack, assigning your soldiers to the target. After the for loops finish you will have some targets left possibly that will not have any soldiers assigned because they are taking out the highest value targets first. The lesser targets will be left.

Then you do your damage loop, the one explained in the above post.

then you do your assign loop again. Until all the targets have been assigned soliders.

Then damage loop again.

Now you see this runs in a loop itself so you can really do this.

while(targetsLeft)
{
AssignSoldiersToTargets();
DamageTargets();
}

And that would be your button code, while the rest would be global script.

I won't write the code for you. This should be a learning experience for you. I gave you the design and all the tools you will need. Its your job to try to understand how to put them in the game. ;)

NOTE: You will not see the actors be destroyed one by one, or even slowly with this design. You need to use a timer and conditional loops. With the design given as soon as you press shoot all the targets will be eliminated.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Optimal damage algorythm

Postby Leif » Mon Oct 10, 2011 6:24 am

I won't write the code for you. This should be a learning experience for you. I gave you the design and all the tools you will need. Its your job to try to understand how to put them in the game.


Thanks for giving me exersises :D
I know basic principes of programming and iterations. Use somebody's tools is much harder then make own. Question is - does anybody have working piece of code? Or where to see it ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron