def tournament(self): for p1 in range(len(self.players)): for p2 in range(len(self.players)): # Fokus ligger bara på resultat för player1 self.players[p1].new_game() self.players[p2].reset_rounds() for i in range(self.number_of_rounds): #resultatvariabel self.res = 0 # Ny runda self.players[p1].new_round() self.players[p2].new_round() if not p1 == p2: # Spelarna väljer self.players[p1].choose() self.players[p2].choose() # Spelarna memorerar alla val self.players[p1].save_choice(self.players[p1].choice, self.players[p2].choice) self.players[p2].save_choice(self.players[p2].choice, self.players[p1].choice) # Spela dem mot varandra och spara resultaten # Funktionen "test" gör det den långa vägen self.res = test(self.players[p1].choice, self.players[p2].choice) # Player1 memorerar resultaten if self.res == 1: self.players[p1].won() elif self.res == 2: self.players[p1].lost() else: self.players[p1].drawn() if self.print_choices: print(self.players[p1].num2rps(), self.players[p2].num2rps()) # Print av matchresultat print(" ") print(self.players[p1].name) if self.print_games: print("Won ", self.players[p1].victories) print("Lost", self.players[p1].losses) print("Draw", self.players[p1].draws) print("W,L,D", sum(self.players[p1].victories), sum(self.players[p1].losses), sum(self.players[p1].draws)) # Återställ player1 så de andra kan utmana den sen self.players[p1].reset()
def choose(self): if self.round == 0: self.choice = random.randint(1, 3) else: t = test(self.mychoices[self.round - 1], self.otherchoices[self.round - 1]) if t == 1: if random.random() < 0.8: self.choice = self.mychoices[self.round - 1] else: self.choice = random.randint(1, 3) else: self.choice = random.randint(1, 3)
def choose(self): # Random första rundan if self.round == 0: self.choice = random.randint(1, 3) else: r = self.round x = test(self.mychoices[r - 1], self.otherchoices[r - 1]) # Behåll samma val ifall den vann if x == 1: self.choice = self.mychoices[r - 1] # Byt ifall den blir lika eller den förlorar else: c = random.randint(1, 3) while c == self.mychoices[r - 1]: c = random.randint(1, 3) self.choice = c
def choose(self): # Random första rundan if self.round == 0: self.choice = random.randint(1, 3) else: r = self.round x = test(self.mychoices[r - 1], self.otherchoices[r - 1]) # Behåll samma val ifall den vann if x == 1: self.choice = self.mychoices[r - 1] # Byt ifall den blir lika eller den förlorar # Välj det som skulle vinna förra matchen else: o = self.otherchoices[r - 1] if o == 1: self.choice = 1 elif o == 2: self.choice = 2 else: self.choice = 3