I have 5 instances of the Player
class, and code that simulates games between each of the players. After each game, the time each player took in the game, and their score (2 for a win, 1 for a draw) are stored in self.totaltime
and self.score
. After all games are played I am trying to select the two highest scorers out of the players so they can play best out of 3 to decide a winner. It's highly likely more than 1 player has the same score. If this is the case, whoever has taken less time will be selected.
My problem is that I'm having trouble sorting/comparing these results to each other, and I'm really not sure which approach is best to select the 2 highest scoring players. I have tried a for loop (shown below) but I wasn't really thinking properly and of course this doesn't work.
def findPlayers():
scorers = []
for player in players:
for player2 in players:
if player.score > player2.score:
scorers.append([player.name, player.score, player.totaltime])
I'm sure I sound a fool but I just need nudging in the right direction with this. I have written the bulk of the code for this program, but I seem to be getting stuck on trivial things like this. Regardless, any nudge in the right direction would be greatly appreciated.