return self::Endorsement($e)[1];
}
- function ByBestSpeed($a, $b) {
- $A = $a->getBestSpeed(); $B = $b->getBestSpeed();
+ function Sort($a, $b, $method, $reverse = false) {
+ $A = $a->$method(); $B = $b->$method();
if ($A == $B) return 0;
- return $A < $B ? 1 : -1;
+ $ret = $reverse ? 1 : -1;
+ return $A < $B ? $ret : -$ret;
+ }
+
+ function ByDistance($a, $b) {
+ return self::Sort($a, $b, "getTotalDistance", true);
+ }
+
+ function ByPenaltyTime($a, $b) {
+ return self::Sort($a, $b, "getPenaltyTime");
+ }
+
+ function ByTotalTime($a, $b) {
+ return self::Sort($a, $b, "getTotalTime");
+ }
+
+ function ByBonusTime($a, $b) {
+ return self::Sort($a, $b, "getBonusTime");
+ }
+
+ function ByCutShort($a, $b) {
+ return self::Sort($a, $b, "cutShort", true);
+ }
+
+ function ByBestSpeed($a, $b) {
+ return self::Sort($a, $b, "getBestSpeed", true);
}
function ByAverageSpeed($a, $b) {
- $A = $a->getAverageSpeed(); $B = $b->getAverageSpeed();
- if ($A == $B) return 0;
- return $A < $B ? 1 : -1;
+ return self::Sort($a, $b, "getAverageSpeed", true);
}
function ByFastestLap($a, $b) {
- $A = $a->getFastestLap(); $B = $b->getFastestLap();
- if ($A == $B) return 0;
- return $A < $B ? -1 : 1;
+ return self::Sort($a, $b, "getFastestLap");
}
function ByAverageLap($a, $b) {
- $A = $a->getAverageLap(); $B = $b->getAverageLap();
- if ($A == $B) return 0;
- return $A < $B ? -1 : 1;
+ return self::Sort($a, $b, "getAverageLap");
+ }
+
+ /*
+ Ordering by total distance then penalty time will classify racers
+ appropriately in endurance races, while having no effect on dashes.
+ Ordering by total time will classify racers in dashes while not
+ affecting endurance races.
+ Ordering by bonus time will allow a racer who didn't use the joker
+ to win a tiebreak with one who did.
+ Ordering by cut short endorsement will penalise those who didn't
+ compete for the full race time but only when tied for penalty.
+ */
+ function StandardSort($a, $b) {
+ $methods = array("ByDistance", "ByPenaltyTime", "ByCutShort", "ByTotalTime", "ByBonusTime");
+ while (count($methods)) {
+ $method = array_shift($methods);
+ $ret = self::$method($a, $b);
+ if ($ret) return $ret;
+ }
+ return 0;
}
function getName() {