Jump to content

Help converting this maths


GetReady

Recommended Posts

Hi i use this scoring formula below for my cold fusion website. i am now re coding this into a php site.... could anyone explain how i would change the following line of code into php?

 

** itemPts = basePrice * quantity * eff% / 150

** drugPts = sqrt(drugVal) * 100 + drugVal

** cashPts = sqrt(cash) * 50 + cash

 

** ScorePotential = itemPts + drugPts + cashPts

** + NT/15

** + SC/15

** + PR * 1.5

** + (OffensiveTroops + MaxOffense) * (OffensiveBonus + 0.1) * 2 * (4 + streetcredlevel + notorietylevel)

** + (DefensiveRating + MaxDefense) * (DefensiveBonus + 0.1) * 2 * (4 + streetcredlevel + notorietylevel)

** + Hoes * (HoIncomeBonus + 0.1) * (1-HoDrugUseBonus) * 300

** + TotalGrown / 2

** + TotalSold / 2

** + (SoldiersKilled-SoldiersLost)/20

** + (drugsStolen-drugsLost)/500

** + (hoesStolen-hoesLost) * 4

** + (cashStolen-cashLost) / 1000

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/174801-help-converting-this-maths/
Share on other sites

  • 2 weeks later...

Most of that code is using the same math operators that PHP uses: plus (+), multiply (*), divide (/), and even the function for square root (sqrt()) is the same.

 

The only exception, as marvelade pointed out, is "eff%". I'm thinking that that is either a special operator in cold fusion or it is simply a variable and CF support the percent sign in variables.

 

So, just change the variables to PHP variables (and figure out the use of "eff%") and you should have something similar to this

 

$itemPts = $basePrice * $quantity * $effPercent / 150;
$drugPts = sqrt($drugVal) * 100 + $drugVal;
$cashPts = sqrt($cash) * 50 + $cash;

$ScorePotential = $itemPts + $drugPts + $cashPts
               + $NT/15
               + $SC/15
               + $PR * 1.5
               + ($OffensiveTroops + $MaxOffense) * ($OffensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel)
               + ($DefensiveRating + $MaxDefense) * ($DefensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel)
               + $Hoes * ($HoIncomeBonus + 0.1) * (1-$HoDrugUseBonus) * 300
               + $TotalGrown / 2
               + $TotalSold / 2
               + ($SoldiersKilled - $SoldiersLost) / 20
               + ($drugsStolen -$drugsLost) / 500
               + ($hoesStolen - $hoesLost) * 4
               + ($cashStolen - $cashLost) / 1000;

 

Personally I would create a variable for the following:

$personality = ($OffensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel);

(or some other description that is more appropriate)

 

And then use that variable on lines 5 & 6 for the definition of $ScorePotential for readability of the code

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.