import rpstournament import random choices = [] rock = 0 paper = 0 scissors = 0 single_index = 0 tripple_index = 0 match = 0 default_index = 0 choice = "" wins = 0 lose = 0 ties = 0 switch = True #eventually under the if statements set the values to true and then #if the statemtents true execute the code # to make it better instead of 10 just do until the current index probably #wont work on tripple loop and loop but maybe all scissors would perform better # that waty\\y RPS_WIN_LOGIC = {'rock':'scissors', 'paper':'rock', 'scissors':'paper'} RPS_LOSE_LOGIC = {'scissors':'rock', 'paper':'scissors', 'rock':'paper'} what_I_lose = [] #Your class must be called GamePlayer, and it must have these functions class GamePlayer: #Give your AI a name. You can put your name in it or not, depending on whether you want to be anonymous. #You can submit multiple AI's with different names for the tournament name = "Shallow Blue" def make_choice(self): global switch global choice global default_index global single_index global tripple_index global choices global rock global paper global scissors global match match += 1 my_choice = random.choice(['rock', 'paper', 'scissors']) #This function must return 1 of 3 values, 'rock', 'paper', or 'scissors' #If it returns anything else, your AI will forfeit the match try: rock_percentage = (rock/(rock + scissors + paper)) * 100 paper_percentage = (paper/(rock + scissors + paper)) * 100 scissors_percentage = (scissors/(rock + scissors + paper)) * 100 except ZeroDivisionError: return 'rock' #always scissors if rock + scissors + paper > 10 and scissors_percentage == 100: return "rock" # loop loop = ["rock", "paper", "scissors", "rock", "paper", "scissors", "rock", "paper", "scissors", "rock", "paper", "scissors"] if len(choices) > 12 and choices[:12] == loop: initial_list = ['scissors', 'rock', 'paper'] choice = initial_list[single_index] single_index += 1 if single_index > 2: single_index = 0 return choice # triple loop triple_loop = ["rock", "rock", 'rock', 'paper', 'paper', 'paper','scissors','scissors','scissors'] if len(choices) > 9 and choices[:9] == triple_loop: initial_list = ['paper', 'paper', 'paper','scissors','scissors','scissors',"rock", "rock", 'rock'] choice = initial_list[tripple_index] tripple_index += 1 if tripple_index > 8: tripple_index = 0 return choice # Switch every round index = len(choices) - 1 for i in choices: if len(choices) > 1 and choices[index] == choices[index -1]: switch = False if switch == True and len(choices) > 30: return RPS_WIN_LOGIC[choices[-1]] # default what_I_lose.append(RPS_LOSE_LOGIC[my_choice]) #if len(choices) > 10 and what_I_lose[0:10] == oppones initial_list = ['rock', 'scissors', 'paper'] choice = initial_list[default_index] default_index += 1 if default_index > 2: default_index = 0 return choice return my_choice def view_opponent_choice(self, opponent_choice): global rock global paper global scissors global choice global wins global lose global ties #This function doesn't have to do anything #You will be shown your opponent's choice from last round #One of 'rock', 'paper', or 'scissors' #You are not allowed to access win and loss records from the Tournament code #If you want to track your win and loss rate, you will need to compare #Your choice to your opponent's choice here. if opponent_choice == "rock": rock += 1 if opponent_choice == "paper": paper += 1 else: scissors += 1 RPS_WIN_LOGIC = {'rock':'scissors', 'paper':'rock', 'scissors':'paper'} try: if choice == opponent_choice: ties += 1 elif RPS_WIN_LOGIC[choice] == opponent_choice: wins += 1 else: lose += 1 except KeyError: pass choices.append(opponent_choice) #print(opponent_choice) return def new_player(self): global switch global rock global paper global scissors global choices global wins global lose global ties #This function doesn't have to do anything #This will be called when you face a new opponent in a new match #You might want to use this method to reset your AI's strategy print(choices) #print(len (choices)) print(lose, wins, ties) print(switch) switch = True default_index = 0 single_index = 0 tripple_index = 0 what_I_los = [] match = 0 choices = [] rock = 0 paper = 0 scissors = 0 wins = 0 lose = 0 ties = 0 return tournament_manager = rpstournament.TournamentManager() example_game_player = GamePlayer() tournament_manager.run_tournament(example_game_player)