diff --git a/models/participant.py b/models/participant.py index 7ac702c..468dc33 100644 --- a/models/participant.py +++ b/models/participant.py @@ -3,19 +3,16 @@ import json from models.player import Player -class Participant(UserDict): +class Participants(UserDict): """Dict of players and score attending a tournament takes tournament's name and list of object Player returns dict with player: score""" - def __init__(self, player_list = None): + def __init__(self, player_list): #player_list FOR TEST ; to feed when creating object #self.tournament self.player_list = player_list - self.identifiant = () self.data = {} - self.PLAYERS_FILE = "./data/players/player_list.json" - # initiate list - + self.PLAYERS_FILE = "./data/players/player_list.json" #FOR TEST def create_participant_from_list(self, players): for item in players: diff --git a/models/scorelist.py b/models/scorelist.py deleted file mode 100644 index 010935a..0000000 --- a/models/scorelist.py +++ /dev/null @@ -1,4 +0,0 @@ - -class ScoreList(list): - """Player tuple (name, lastname) and score""" - def __init__(self): diff --git a/models/tournament.py b/models/tournament.py index b104e23..a16a69b 100644 --- a/models/tournament.py +++ b/models/tournament.py @@ -1,4 +1,4 @@ -from models.participant import Participant +from models.participant import Participants from models.turn import Turn @@ -25,7 +25,4 @@ class Tournament: self.description = "Pas encore de description" self.turn_list = [] - def run_turns(self): - pass - #if self.current_turn == "Round 1": diff --git a/models/turn.py b/models/turn.py index 82acf53..a936da4 100644 --- a/models/turn.py +++ b/models/turn.py @@ -1,5 +1,5 @@ from random import choice, shuffle -from models.participant import Participant +from models.participant import Participants from models.match import Match class Turn: @@ -15,35 +15,25 @@ class Turn: self.match_result = [] self.player_list = [] - def create_player_list(self): #not used for now - """name list from dict""" - for player in self.participants: - self.player_list.append([player[0], player[1]]) - def ramble_player_list(self): """shuffle player's list""" return shuffle(self.player_list) - def sort_scores(self, player_list): - """order players on score""" - def score(couple): - return couple[1] - return sorted(player_list, key=score) - def sort_players_by_score(self): + """orders dict on value and returns sorted list""" return sorted(self.participants.items(), key=lambda t: t[1]) - def create_match(self): print("Liste des joueurs: ", self.player_list) j = 0 + k = 0 for i in range(0, len(self.player_list), 2): j += 1 match = Match(self.player_list[i][0], self.player_list[i+1][0]) match.name = "match" + str(j) - - if match in self.match_history: # If match has already been made, choose the next player - match = Match(self.player_list[i][0], self.player_list[i+2][0]) + while match in self.match_history: + k += 1# If match has already been made, choose the next player + match = Match(self.player_list[i][0], self.player_list[i+k][0]) self.match_list.append(match) else: self.match_list.append(match) diff --git a/views/base.py b/views/base.py index c57baae..d86111c 100644 --- a/views/base.py +++ b/views/base.py @@ -6,4 +6,7 @@ class View: def prompt_for_scores(self): print() input("Saisir les scores ?") - return True \ No newline at end of file + return True + + def display_winner(self, participants): + pass diff --git a/vrac.py b/vrac.py index 68d7800..3923e64 100644 --- a/vrac.py +++ b/vrac.py @@ -1,4 +1,4 @@ -from models.participant import Participant +from models.participant import Participants from models.player import Player from models.match import Match from models.turn import Turn @@ -78,7 +78,7 @@ player_list = [joueur1, joueur2, joueur3, joueur4, joueur5, joueur6] #print(name_from_chess_id("JF78739", player_list)) def test2(player_list): # create new participants object (dict from list)... - participants = Participant("Tournoi de cajou", player_list) + participants = Participants("Tournoi de cajou", player_list) # display the dict print("print(participants) : ", participants.create_participant_from_list()) print(participants.data) @@ -117,15 +117,21 @@ def test(player_list): def test3(): # initialization - participants = Participant() + participants = Participants(player_list) participants.get_players_from_file() #load dict from file view = View() - tour = Turn(participants) + turn_nb = 1 + tournoi1 = Tournament("Tournoi de Cajou", participants) def run_turn(turn_nb): tour = Turn(participants.data, name = "Round"+str(turn_nb)) + print("Commençons le", tour.name) + if turn_nb == 1: + tour.player_list = tour.sort_players_by_score() + else: + tour.player_list = tour.sort_players_by_score() tour.create_match() print(f"La liste des matchs pour le {tour.name} est :\n {tour.match_list}") view.prompt_for_scores() @@ -133,11 +139,20 @@ def test3(): print("Save \n", tour.name, tour.match_result) tournoi1.turn_list.append([tour.name, tour.match_result]) - while i < tournoi1.total_turn: - if tounoi1.current_turn == 1: + def display_winner(participants): + base = + for i in participants: + if participants[i] + print("Début du", tournoi1.name, "!") + while turn_nb < tournoi1.total_turn: + tournoi1.current_turn = turn_nb + run_turn(turn_nb) + turn_nb += 1 - run_turn(turn_nb) + print("\nLe", tournoi1.name, "est terminé.\n") + print("Scores finaux:\n", participants.data) + print("liste des tours:\n", tournoi1.turn_list) #for i in range(1, tournoi1.total_turn+1): #tour = Turn(participants, name = "Round"+str(i))