I am developing a soccer tournament management system and I'm stuck with a problem. I have to show to the user round teams ranking based on different attributes. I'm right now considering the following order:
- team points ( 3*won match + 1*tie match )
- team confrontational( not sure if this is the right word but I mean matches between same teams, i.e. if two teams have the same points but one was defeated by the other, the winning one will be above the loser one )
- goal difference (goal scored-goal taken)
- goal scored
- alphabetical order
Data to build this model are retrieved through different database query and the structure I'm using right now to save them is an array of objects like this:
- teamId
- played matches
- won matches
- lost matches
- tie matches
- points
- goal scored
- goal taken
- goal difference
- teams that were defeated current one = array(teamId1,teamId2...)
- teams that defeated current one= array(teamId1,teamId2...)
- teams that had a tie with current one = array(teamId1,teamId2...)
For most sorting attributes I can use php array_multisort function and get the job done but the issue is about team confrontational. As an example let's say I have this situation:
- Team A - 3 points - won against D
- Team B - 3 points - won against D
- Team C - 3 points - won against A
- Team D - 0 points - won against D
In this case I have that team C should stay above A since C defeated A while I should check goal difference(next attribute in the order) to determine B position compared to B and C. I'm trying to develop an algorithm able to sort this issue with any attribute configuration but had no luck so far. Anyone has any suggestion? Thank you very much and forgive me if I were not clear