Author Topic: Evolution of Attack Scripts :: Part #3  (Read 1041 times)

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Evolution of Attack Scripts :: Part #3
« on: August 29, 2009, 01:24:36 PM »
In the last article I discussed my loop intensive battle system. I actually kept up with that system and tried to augment it as much as possible to keep the randoms and king of the hill style of game play down. I tried modifiers, specialty points and limiting strength based on how many attacks the player made (ie to simulate fatigue). None of them worked for me.

The game was gaining more and more players each round and my server just could not take the battle system any longer. So to keep the game half way running I decided to go back to the first systems but use the number generated from the loops. Basically tally up all bullets on each side, tally up all the thugs and there gear and then randomize the bullets to simulate the hits, apply damage to the thugs and declare the winner. Not only did this just extend the problem of the first attack system it actually worsened it because the numbers the randomizer had to choose from were a lot larger now. At least with randomizing between 1-10 you could come up with a half hearted distribution pattern (actually you can't) but when you randomize between 23,000 - 70,000 your results get horribly screwed. That was still a problem but at least the server was starting to keep up a bit better without having all the loops to deal with.

I knew I had a problem but I had no way of fixing it. I tried a lot of things, play tested so many various ideas for battle systems, various ideas on distribution systems everything I could think of and some things that just came to me in a hazy dream. Nothing worked for me, nothing fit the model I needed which boiled down to two goals:

1. Predictable random, powerful players should win the battle but not 100% of the time, someone with say lesser should be able to get lucky and take down a more powerful adversary.

2. Speed, the code had to be fast, period.

I knew what I wanted but didn't have any clue on how to get there. At this point I exhausted all the research material on the web, books and board games I could think of and basically gave up with the mantra of "the battle system is what it is". Then one glorious day I found an article on the web about an attack system. I wish I would have bookmarked it or saved it somewhere so I could give the author credit. The system was perfect, very simple and just perfect for what I needed.

Code: [Select]
$attacker_str = ( sum up attacker's str )
$defender_str = ( sum up defender's str )

// Attacker has 25% more attack strength then defender's defense strength, success rate for attacker 95%
if( $attacker_str >= ( $defender_str + ($defender_str * .25) ) ) {
  if( mt_rand(1,100) <= 95 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
// Attacker has 12.5% more attack strength then defender's defense strength, success rate for attacker 85%
elseif( $attacker_str >= ( $defender_str + ($defender_str * .125) ) ) {
  if( mt_rand(1,100) <= 85 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}
// Attacker has more attack strength then defender's defense strength, success rate for attacker 75%
elseif( $attacker_str > $defender_str ) {
  if( mt_rand(1,100) <= 75 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}
// Attacker has equal attack strength to defender's defense strength, success rate for attacker 50%
elseif( $attacker_str == $defender_str ) {
  if( mt_rand(1,100) <= 50 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}
// Attacker attack strength less then 50% of defender's defense strength success rate for attacker 5%
elseif( ( $attacker_str + ($attacker_str * .5) ) <= $defender_str ) {
  if( mt_rand(1,100) <= 5 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}
// Attacker attack strength less then 25% of defender's defense strength success rate for attacker 15%
elseif( ( $attacker_str + ($attacker_str * .25) ) <= $defender_str ) {
  if( mt_rand(1,100) <= 15 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}
// Attacker attack strength less defender's defense strength success rate for attacker 25%
else {
  if( mt_rand(1,100) <= 25 ) {
    // Attacker wins
  }
  else {
    // Defender wins 
  }
}

As you can see it's simple, actually, it's really simple and I kicked myself profusely for not thinking of it myself. As the difference between strength widens so does the chance of your success. The beauty of it though was it wasn't using the actual strength numbers for the random which kept the distribution of the randomizer controlled. It also had the added benefit of being able to be tweaked quickly. When I first put the system up the tiers were to far apart so it was almost impossible for the attacker to hit the 95% success rate. So as the rounds progressed and I could analyze the numbers more I was able to tighten the tiers closer together.

This system worked well in my mind but the way player's received strength needed to be changed so we didn't get into a "both have best" scenario again which would basically take us back (even with this system) to a 50/50 chance. I always wanted to give my players full control of there accounts. Some players didn't want to really attack all that much they liked the building aspect of the game, attackers of course wanted to do nothing but attack and then of course there were the median players that enjoyed both.

I added what was called training points. These were points given to players based on how well there bordello did when they opened for business. With the training points they could assign them to either attack or defense skills. The skill points were then added to the strength and applied to the above attack script. I released the attack system and it was a huge success, it had everything I wanted and what the players wanted. The heavens parted, golden rays of the sun touched me everywhere I  walked, people threw large amounts of cash at me, gorgeous naked women adored me and fed me beer while they washed my feet as I sit upon my throw :) Ok I may be exaggerating a bit LOL

The awesomeness of the attack system was short lived. Eventually the player, being in control of there own power, basically all merged to a single grouping of attack/defense distribution. The sweet spot became 60% attack, 40% defense and just about every player used it. In the end I was right back where I started. The system stayed the same until we finally closed down BordelloBattles.

I wish I had a moral to this set of articles but I don't. These are just the ramblings of a coder that has hit his head on the wall so many times that it's nothing but a bloody mess with gray matter spattered all about.

« Last Edit: August 29, 2009, 01:28:27 PM by codestryke »
Creating online addictions, one game at a time:

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: Evolution of Attack Scripts :: Part #3
« Reply #1 on: August 29, 2009, 03:46:08 PM »
Haha, this definitely is the best post in the series  :D. Both funny and horrifying at the same time  ;). It really is helpfull, and for posts like these you should create a sticky.

Thanks.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Evolution of Attack Scripts :: Part #3
« Reply #2 on: August 30, 2009, 04:00:30 AM »
I wish I had a moral to this set of articles but I don't.
I will post my moral then, because I have it :D Thinking too much is useless for a programmer, leave it for MENSA members and philosophers. Combat system is a trivial task, as long as you accept it imperfectness and don't split the hair in 4. Make it quick and simple, accept it won't be 100% what you wanted and move on to more important tasks.

If someone has problems, an example system that meet both criterias listed above:
Derivate one number summing all attributes of attacker and defender. Then apply a random roll and add a cap for very lucky shot.
Quote
$winner=$attacker-$defender+rand(-max($attacker,$defender)/10,max($attacker,$defender)/10);
$critical=rand(1,100); if($critical<=5) $winner=1; if($critical>=95) $winner=-1;
If winner <0 the defender won, if higher than 0 the attacker won.
« Last Edit: August 30, 2009, 04:04:37 AM by Chris »

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Evolution of Attack Scripts :: Part #3
« Reply #3 on: August 30, 2009, 04:54:23 AM »
I don't really agree with this. Combat system is as trivial/complex as you design it to be and that depends on game etc.

Quote
accept it won't be 100% what you wanted and move on to more important tasks.
If combat is important in your game then there are really only a few tasts that might be more important. Having realistic attitude is ok, but it shouldn't necessarily imply having combat system as trivial as it could be.

For me as a player, in combat systems listed so far there were far too few tactics and decision making involved so I'm afraid I'd might quickly lose interest in the game shouldn't it be focused and entertaining in something else.

I'd rather see restriction so that only a similarly powerful forces might fight and have more options.
That would of course come with more complex system.

In the game I make (unfortunately don't have a much time for it lately :( ) I plan kinda complex system with fighting with only a few units, but directly controlling them in the combat, number of variables and options etc. Well...thats the plan :) that doesn't mean I'll manage to make it that way and the concept is not bullet-proof so far.

My €0.2
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Scion

  • Level 27
  • **
  • Posts: 402
  • Reputation: +11/-0
    • View Profile
Re: Evolution of Attack Scripts :: Part #3
« Reply #4 on: August 31, 2009, 05:00:02 AM »
WARG....i feel strangely prophetic. Its more or less the same system i proposed in #2....Simplified a little to use hard barriers...but recognisably similar.

@Nox, From what i gather this was one of those click to do a raid/attack/battle type games where battling wasnt necessarily the driving game element. (i could be wrong) In that case there is no room for tactics....and strategy is reduced to preconfiguring you setup prior to the battle. The one click attack system is so common because it only requires one participant to be online at a time, and the battle can be concluded immediately and the world state updated to reflect the outcome.

When you allow for tactics either all parties must be available online at that time or the battle must be drawn out over a much longer time frame....This creates a completely different style of game.

I find it difficult to say one system is 'better' than the other, they suit different styles of game, and probably appeal to slightly different player populations as well.

I do have to admit that its kind of depressing that the player setups tended towards a particular configuration, Although i guess its only natural, given any distribution if one point (or even several) poinst represent a local maximum in performance player populations will tend towards those local maximums. To keep any significant variety in the population you need to create several local maximums that are of equal performance. The broades variety can be achieved when you completely flatten the distribution so that there are no local maximums at all. (ZOMG an actual use/application of principles for the genetic programming i did back in my UNI days ;) )

So in this case  you could have tried to create additonal sweet spots. One possibility that springs to mind is using modifiers after the base strength has been retrieved, that is if a player has invested more points in a particular direction away from that 60/40 sweet spot then they get additional bonuses, so if we have a player that has a 60/40 setup they get no additonal bonus but a player that has invested 80/20 would get an additional bonus when attacking. my gut feeling is that this would create two additonal sweet spots one attack high the other defense high to either side of a balanced approach.

There is of course an alternative approach to two variable battle systems (here it is attack & defence) that is instead of having a two variables you use a three variable system ala paper rock sicsors, where each has another that it can beat and one that it will loose against.. Ive done some monte carlo tests with a battle system that used three variables applied in percentages so you could do for example 60% paper, 30%rock and 10% sicsors...And the results were satisfying, there was no configuration that could allways win, and the best you could hope for against an unknown opponent at the same overal level of strength was a configuration that suggested you could win up to 60% of the time....Unfortunately this system also had local maximums, but at least there were three and each was strong against one and weak against the other....just like the base paper rock sicsors that it was bassed on. Trying to smooth a three variable system is at least 3 times that the two variable one, since there are 3 posible interactions rether then 1 ...so i didnt get that far, but it may be possible to apply something similar, modifiers to try and flatten the performance distribution....Then again..im not sure its necessary when you have 3 local maximums in a three variable system like this.

Finally it was my monte carlo testing that gave me the idea for what might possibly be the absolute fastest implementation of one of these battle sytems. If you have known strength ratings in any number of variables that the battle outcome will be bassed on then it isnt actually necessary to generate a specific battle at all. If you already know through your montecarlo testing that a player with stegth configuration A will beat a player with strength configuration B 31.76% of the time then as long as you have that percentage available (of course therin lies the rub)  you can simple generrate a random number and test...its extreme abstraction i know....but if everything is already available its undeniably fast.

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Evolution of Attack Scripts :: Part #3
« Reply #5 on: August 31, 2009, 05:31:21 AM »
Quote
When you allow for tactics either all parties must be available online at that time or the battle must be drawn out over a much longer time frame
I was rather thinking about
1) Army is divided into groups
2) Defender's group is controlled by AI and tactics are chosen by player in some "defence settings screen", locking the group when defender is online
As I said, it's not really thought through so far and I'm aware that the lock is unpleasant and defender might be disadvantaged and it's not great when you have low number of groups (1-2). Still developing it...don't want to be too much offtopic here so I'll stop now.

Quote
I find it difficult to say one system is 'better' than the other, they suit different styles of game, and probably appeal to slightly different player populations as well.
Agree, it depends how your game is designed and what's important there

Quote
...and the best you could hope for against an unknown opponent...
And this is a point when you can connect it with other game mechanics, like spying (which shouldn't give you a perfect formula for winning, but rather give a slight hint),
which I think suits "Bordello" theme pretty well
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal