# Formula 1 Score Counting Function

## Recommended Posts

To whom it concerns,

I have a formula one racing calculator that should work like this:

1. Through the GUI users guess the top 8 drivers in the order they think they will finish.

2. Through the GUI users guess who will get the fastest lap.

3. Through the GUI users guess who will start at pole position.

(these are written to the MySQL database in a 'racebets' table)

4. When a race is run, the administrator enters the actual top drivers in order and who got the fastest lap and pole position.

(these are written to the MySQL database in a 'raceresults' table)

5. A php calculation is done against the two database tables whereby, if a user guessed a driver in the correct position in the top eight, the points array distributes points as follows (10,8,6,5,4,3,2,1).

Just by guessing a driver in the top 8 (whether in the correct position or not) the user gets 1 point

i.e. if you guess Michael Schumacher to come first and he does come first, you get 11 points (10 + 1). If you guess Michael Scumacher to come first and he actually comes third, you get 1 point etc etc...

If the user guessed the driver with the fastest lap they get 3 points and pole position they get 3 points too.

Here is the script that is being used but IT IS NOT CALCULATING CORRECTLY and so we are forced to calculate manually and enter the results in the database manually!

---------------------

class pointCalculator {

//amount of points earned

var \$earnedPoints;

//points given for each guess

var \$pointHash;

//drivers that user has selected

var \$selectedDrivers;

//real drivers in the end of the race

var \$finalDrivers;

//pole driver

var \$poleDriver;

//driver with fastest lap

var \$fastestDriver;

/**

* @return void

* @param

* @desc Constructor

*/

function pointCalculator(){

\$this->earnedPoints=0;

\$this->setPoints(array(10,8,6,5,4,3,2,1));

}

/**

* @return void

* @param int \$n

* @desc Set the pole driver

*/

function setPole(\$n){

/*

if(!is_numeric(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

*/

\$this->poleDriver=\$n;

}

/**

* @return void

* @param int \$n

* @desc Set the faster driver.

*/

function setFastest(\$n){

/*

if(!is_numeric(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

*/

\$this->fastestDriver=\$n;

}

/**

* @return void

* @param array \$n

* @desc Set drivers selected by user

*/

function setSelected(\$n){

if(!is_array(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

\$this->selectedDrivers=\$n;

}

/**

* @return void

* @param array \$n

* @desc Set drivers selected by user

*/

function setSelectedFastest(\$n){

/*

if(!is_numeric(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

*/

\$this->selectedFastest=\$n;

}

/**

* @return void

* @param array \$n

* @desc Set drivers selected by user

*/

function setSelectedPole(\$n){

/*

if(!is_numeric(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

*/

\$this->selectedPole=\$n;

}

/**

* @return void

* @param hash \$n

* @desc Set amount of points per dirver (IN ORDER)

*/

function setPoints(\$n){

/*

if(!is_numeric(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

*/

\$this->pointHash=\$n;

}

/**

* @return void

* @param int \$n

* @desc Set results of race

*/

function setFinalDrivers(\$n){

if(!is_array(\$n)){

echo 'Wrong usage in'.__FILE__.':'.__LINE__;

return;

}

\$this->finalDrivers=\$n;

}

/**

* @return int

* @param

* @desc Get calculated score

*/

function calculate(){

foreach(\$this->finalDrivers as \$k=>\$v){

if(\$this->selectedDrivers[\$k]==\$v)

\$this->earnedPoints+=\$this->pointHash[\$k];

if(in_array(\$v,\$this->selectedDrivers))

\$this->earnedPoints++;

}

// check pole and fastest

if(\$this->selectedPole==\$this->poleDriver)

\$this->earnedPoints+=3;

if(\$this->selectedFastest==\$this->fastestDriver)

\$this->earnedPoints+=3;

return \$this->earnedPoints;

}

}

---------------------

If you can help that would be fantastic...

P.S. You can view the f1 tipping comp at: http://www.f1tipping.org/

Regards,

Byron

##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.