Hello friends, I hope you can help me with this.
I have this object
class Player(Game):
"""docstring for Jugador"""
def __init__(self, name, sex):
self.name = name
self.sex = sex
self.points = 0
self.efectividad = 0
self.wins = 0
self.lose = 0
self.rank = 0
def changeSex(self, sex):
""" Change the Player Sex """
self.sex = sex
def addPoints(self, points):
""" Add points a player """
self.points = points
def win(self):
self.wins += 1
def lose(self):
self.lose += 1
Which is created and stored in a list with this function
def addPlayer(self, name, sex):
self.players.append( Player(name, sex) )
this method belongs to this class
class Game(object):
"""docstring for Game"""
def __init__(self, rounds, name, mode, numberOfTables):
super(Game, self).__init__()
self.roundGame = 1
self.rounds = rounds
self.name = name
self.mode = mode
self.numberOfTables = numberOfTables
self.tables = []
self.pointsOfTheRound = []
self.players = []
self.ranking = []
def changeName(self, name):
""" Change the Player name or Game name """
self.name = name
def addPlayer(self, name, sex):
self.players.append( Player(name, sex) )
def addPointsToRound(self, points):
self.pointsOfTheRound.append( points )
def nextRound(self, roundGame):
if len(self.tables) == self.numberOfTables:
roundGame = "Ronda " + str(self.roundGame)
pointsOfTheRound = {roundGame : self.tables}
self.addPointsToRound(pointsOfTheRound)
if (self.roundGame == self.rounds):
print("Ultima Ronda")
elif (self.roundGame <= self.rounds ):
self.roundGame += 1
self.tables = []
else:
print("Introduzca los puntos de todas las mesas antes de avanzar de ronda")
def getCountOfPlayers(self):
return len(self.players)
def getRaking(self):
print(self.ranking)
After starting the game and start assigning the points when advancing the round, I want to make a table of players in which, the players will be placed in order higher score to lower, that is why the object player has a points and effectiveness attribute, if there is a player that has the same score as another, it would be to evaluate the effectiveness that this player had against the other during the game, my problem is that when I want to assess who is the best player to go ordering the ranking from highest to lowest, I can determine the player who has more points or better effectiveness with this function
def getBestPlayers(gameClass):
players, mayor = gameClass.players, 1
for i in range(gameClass.getCountOfPlayers() - 1):
if i >= 1:
if players[mayor].points > players[i - 1].points:
mayor = mayor
elif players[mayor].points == players[i - 1].points:
if players[mayor].efectividad > players[i - 1].efectividad:
mayor = mayor
elif players[mayor].efectividad == players[i - 1].efectividad:
print("Empate 1")
else:
mayor = i - 1
else:
mayor = i - 1
return mayor
Effectively return the player with the best score or best effectiveness, but if there are 10 players, I have to perform 10 times the function to get who would be the next player with better score or effectiveness and will always return the same player, which I I thought it was, I have my list called ranking and in this insert the player that throws me the function and I will have my ranking, if they set the object Game
already contains this list as an attribute and towards it the players will return the function, the thing is that for me to throw another player, I came up with the method .pop()
of the lists and effectively returns me the next player with better ranking because it would not be the previous one in the list, when I check my ranking list , I have it empty and if I check the list of players, I also have it empty, since the .pop()
method eliminates the objecto player from both lists and that is my problem.
I want to get the players of self.players
, which is my list of players and assign them to players = gameClass.players
my local list of the function getBestPlayers(gameClass)
and that when I apply the method .pop()
to players
only be removed from this list and not from the list self.players
of the class Game
, how can I achieve this?