dev-labs-bg / sportify

Football match prediction game with simple rules, built on Symfony
GNU Affero General Public License v3.0
33 stars 13 forks source link

change scoring system #26

Closed aminvakil closed 6 years ago

aminvakil commented 6 years ago

I want to change scoring system to something I prefer more. How can I do that?

It's basically just this with little differences. For example: 6 points for exact score instead of 3

Also how can I implement scoring for goal difference?

cmihaylov commented 6 years ago

Check this class: Devlabs\SportifyBundle\Entity\Prediction. You can change its constants POINTS_OUTCOME and POINTS_EXACT to something you prefer. Also calculatePoints method in this class does the points calculation for a prediction. Inside it, you can implement whatever logic you like for points calculation, including goal difference.

aminvakil commented 6 years ago

I changed the POINTS_OUTCOME and POINTS_EXACT. This is the code written for exact and outcome, can you please add goal_difference to it for me? I just know some linux, I don't know any symphony sadly.

if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
            return self::POINTS_EXACT;
        } else if ($this->getResultOutcome() === $match->getResultOutcome()) {
            return self::POINTS_OUTCOME;
        }
aminvakil commented 6 years ago

As they are not identical I guessed I should use == instead of ===, is this code correct?

if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
            return self::POINTS_EXACT;
        } else if (($this->homeGoals - $this->awayGoals) == ($match->getHomeGoals - $match->getAwayGoals)) {
            return self::POINTS_DIFFERENCE;
        } else if ($this->getResultOutcome() === $match->getResultOutcome()) {
            return self::POINTS_OUTCOME;
        }
cmihaylov commented 6 years ago

Both calculations should yield an integer, so === is actually ok. You logic is pretty much ok, you've only misused $match->getHomeGoals and $match->getAwayGoals, those are methods so you need to have parentheses, i.e call them.

So here's the corrected version of your code:

if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
    return self::POINTS_EXACT;
} else if (($this->homeGoals - $this->awayGoals) === ($match->getHomeGoals() - $match->getAwayGoals())) {
    return self::POINTS_DIFFERENCE;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
    return self::POINTS_OUTCOME;
}

return 0;