SharkBait Posted December 6, 2006 Share Posted December 6, 2006 Ok I have a small project at work to keep some of the employees entertained while they do their job and I am having troubles balancing the attack/defend portion of the game.I base their initial attack/defend power on their level. They gain experience based on various aspects of the website they use in their daily tasks.What I am having troubles is when they attack each other. They earn 'soldiers' to fight/defend with so those numbers can vary. What is the best way to determine who wins in the battle?Ex:Player1 is lvl 10 with 1000 troopsPlayer2 is lvl 8 with 800 troopsObviously Player1 is stronger than Player 2Player1 is lvl 12 with 1200 troopsPlayer2 is lvl 8 with 1500 troopsWho should win this?I'm just fuzzy on the logic. Also I plan on having bonuses like +1 to offense or +1 to defense.On a side note I currently add a small bonus modifier if a player is attacking another player who is higher level. IE Attacker Level > Defender Level. Hoping that it isnt total hopeless for a lower level character to attack a higher level.Make sense? Link to comment https://forums.phpfreaks.com/topic/29710-calculating-attacksdefends/ Share on other sites More sharing options...
Daniel0 Posted December 6, 2006 Share Posted December 6, 2006 Make a function that calculates an attack score based like this: [code]function calculate($level,$troops,$bonus=false){ $result = pow(sqrt(pow(($level*22),2)/($troops*18)+$troops/100),3); if($bonus==true) { $result *= 1.25; $result += 3; } $result = round($result); return $result;}[/code]Highest score wins. The bonus is given if you are attacking a higher leveled person.Example 1: Player1 wins (P1: 45; P2: 43) - bonus to Player2Example 2: Player2 wins (P1: 59; P2: 84) - bonus to Player2Edit: Here is the formula:[img]http://img223.imageshack.us/img223/5219/formulayx1.png[/img]and for the bonus:[img]http://img134.imageshack.us/img134/6052/formula2tv3.png[/img](S: Score; T: Troops; L: Level) Link to comment https://forums.phpfreaks.com/topic/29710-calculating-attacksdefends/#findComment-136530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.