sorting - PHP: sort tournament round teams by multiple attributes -
i developing soccer tournament management system , i'm stuck problem. have show user round teams ranking based on different attributes. i'm right considering following order:
- team points ( 3*won match + 1*tie match )
- team confrontational( not sure if right word mean matches between same teams, i.e. if 2 teams have same points 1 defeated other, winning 1 above loser 1 )
- goal difference (goal scored-goal taken)
- goal scored
- alphabetical order
data build model retrieved through different database query , structure i'm using right save them array of objects this:
- teamid
- played matches
- won matches
- lost matches
- tie matches
- points
- goal scored
- goal taken
- goal difference
- teams defeated current 1 = array(teamid1,teamid2...)
- teams defeated current one= array(teamid1,teamid2...)
- teams had tie current 1 = array(teamid1,teamid2...)
for sorting attributes can use php array_multisort function , job done issue team confrontational. example let's have situation:
- team - 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 case have team c should stay above since c defeated while should check goal difference(next attribute in order) determine b position compared b , c. i'm trying develop algorithm able sort issue attribute configuration had no luck far. has suggestion? thank , forgive me if not clear
what call team confrontational new table calculated teams tying same points using games between them. problem evolves particularly nasty situation when have 3 or more teams tied in points, in case cannot sort position table using 1 one comparisons (which sorting algorithms do) need know other teams tied create sub-table. need create function given list of matches , list of teams generates position table teams, sorted caring points. before returning position table check if there groups same points , replace section of table result of recursive call matches tied group teams. sure stop recursion when whole table tied or else infinite loop, in case apply global goal diff, goals scored , alphabetical.
pd: tried solving problem before , gave after realizing dealing non comparable sets. if implement happy check out code.
Comments
Post a Comment