import random RPS_WIN_LOGIC = {'rock':'scissors', 'paper':'rock', 'scissors':'paper'} RPS_LOSE_LOGIC = {'scissors':'rock', 'paper':'scissors', 'rock':'paper'} #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 = "Switch-aroo v2" def __init__(self): self.list_of_make_choices = [self.make_choice1, self.make_choice3, self.make_choice4, self.make_choice7, self.make_choice9] self.current_choice_number_of_turns = 0 self.current_choice = random.choice(self.list_of_make_choices) self.choice_list3 = ['rock', 'paper', 'scissors'] self.choice_list4 = ['rock', 'paper', 'scissors'] self.initial_list5 = ['rock', 'paper', 'scissors'] self.index5 = 0 self.initial_list6 = ['rock', 'rock', 'rock', 'paper', 'paper', 'paper', 'scissors', 'scissors', 'scissors'] self.index6 = 0 self.last_opponent_pick7 = 'scissors' self.last_self_pick8 = random.choice(['rock', 'paper', 'scissors']) self.last_self_pick9 = 'paper' self.won_last_round9 = True def make_choice1(self): return random.choice(['rock', 'paper', 'scissors']) def make_choice3(self): return random.choice(self.choice_list3) def make_choice4(self): rocks = self.choice_list4.count('rock') papers = self.choice_list4.count('paper') scissors = self.choice_list4.count('scissors') if (rocks > papers and rocks > scissors): return 'rock' elif (papers > rocks and papers > scissors): return 'scissors' else: return 'paper' def make_choice5(self): choice = self.initial_list5[self.index5] self.index5 += 1 if self.index5 > 2: self.index5 = 0 return choice def make_choice6(self): choice = self.initial_list6[self.index6] self.index6 += 1 if self.index6 > 8: self.index6 = 0 return choice def make_choice7(self): return RPS_LOSE_LOGIC[self.last_opponent_pick7] def make_choice8(self): new_list = ['rock', 'paper', 'scissors'] new_list.remove(self.last_self_pick8) new_pick = random.choice(new_list) self.last_self_pick8 = new_pick return new_pick def make_choice9(self): if self.won_last_round9: return self.last_self_pick9 else: new_list = ['rock', 'paper', 'scissors'] new_list.remove(self.last_self_pick9) new_pick = random.choice(new_list) self.last_self_pick9 = new_pick return new_pick def make_choice(self): #This function must return 1 of 3 values, 'rock', 'paper', or 'scissors' #If it returns anything else, your AI will forfeit the match if self.current_choice_number_of_turns >= random.randint(78, 84): self.current_choice_number_of_turns = 0 self.current_choice = random.choice(self.list_of_make_choices) else: self.current_choice_number_of_turns += 1 make_choice_runner = self.current_choice return make_choice_runner() def view_opponent_choice(self, opponent_choice): #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. self.choice_list3.append(RPS_LOSE_LOGIC[opponent_choice]) self.choice_list4.append(RPS_WIN_LOGIC[opponent_choice]) self.last_opponent_pick7 = opponent_choice if RPS_WIN_LOGIC[self.last_self_pick9] == opponent_choice: self.won_last_round9 = True else: self.won_last_round9 = False def new_player(self): #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 self.choice_list3 = ['rock', 'paper', 'scissors'] self.choice_list4 = ['rock', 'paper', 'scissors']