import math import random class AI(): def __init__(self): self.name = "No name!" self.go_option = 1 def move(self,options,sensors): return 0 def win(self): print self.name + ": I won!" def lose(self): print self.name + ": Somebody else won..." def enemy(self): print self.name + ": Ouch. I encountered the enemy." class AI0(AI): pass class AI1(AI): def __init__(self): self.name = "Random" def move(self,options,sensors): return options[random.randint(0,len(options)-1)] class AI2(AI): def __init__(self): self.count=0 self.name = "Freddie2" self.option = 1 def move(self,options,sensors): if self.count==0 or self.option not in options: self.option=options[random.randint(1,len(options)-1)] self.count = random.randint(2,5) self.count = self.count - 1 return self.option def win(self): pass class AI3(AI): def __init__(self): self.option = 1 self.name = "Heather" def move(self,options,sensors): if self.option not in options: self.option=options[random.randint(1,len(options)-1)] return self.option class AI4(AI): def __init__(self): self.name = "Dexter" self.options = [1,4,2,3] self.option = 0 def move(self,options,sensors): if self.options[(self.option-1)%4] in options: self.option = self.option -1 if not self.options[self.option%4] in options: self.option = self.option +1 return self.options[self.option%4] class AI5(AI): def __init__(self): self.name = "Mortadelo" self.lastmove = 1 self.lastturn = 3 self.lastdir = 1 def move(self,options,sensors): if self.lastmove in [1,2]: self.lastturn = 4 if (self.lastturn == 3) else 3 self.lastmove = self.lastturn else: if self.lastdir not in options: self.lastdir = options[1] self.lastmove = self.lastdir return self.lastmove class AI6(AI): def __init__(self): self.name = "Escombra3" self.sequence = [1,1,3,3,2,2,3,3] self.sequence2 = [2,2,2,4,1,1,1,4] self.option = 0 def move(self,options,sensors): m = self.sequence[self.option%8] if not m in options: temp = self.sequence self.sequence = self.sequence2 self.sequence2 = temp self.option = self.option -1 m = options[random.randint(1,len(options)-1)] self.option = self.option +1 return m class AI7(AI): def __init__(self): self.name = "2Faces" self.lastgoal = 10000 self.options = [1,4,2,3] self.optionsrev = [2,3,1,4] self.option = 30 self.hits = 3 self.lastm = 0 self.lastm2 = 0 def move(self,options,sensors): if self.hits <= 0: if sensors[1] < self.lastgoal: hits = 3 self.hits = self.hits + 2 self.name = "2Faces/Heather" if not self.options[self.option%4] in options: self.option = self.option - random.randint(1,3) self.hits = self.hits - 1 return self.options[self.option%4] else: self.name = "2Faces/Midas" #if self.lastm in (1,2) and self.lastm2 in (1,2) and self.lastm!=self.lastm2 or self.lastm in (3,4) and self.lastm2 in (3,4) and self.lastm!=self.lastm2: self.hits = self.hits -1 if sensors[1] < self.lastgoal: while 1: m = self.options[self.option % 4] if m in options: break self.option = self.option + 1 self.hits = self.hits -1 else: m = self.optionsrev[self.option % 4] self.option = self.option + 1 self.lastm2 = self.lastm self.lastm = m self.lastgoal = sensors[1] if self.hits == 0: self.hits = -10 return m class AI8(AI): def __init__(self): self.name = "Midas2" self.lastgoal = 10000 self.option = 0 self.options = [1,3,2,4] self.optionsrev = [2,4,1,3] def move(self,options,sensors): if sensors[1] < self.lastgoal: while 1: m = self.options[self.option % 4] if m in options: break self.option = self.option + 1 else: m = self.optionsrev[self.option % 4] self.option = self.option + 1 self.lastgoal = sensors[1] return m class AI9(AI): def __init__(self): #self.__init__() self.name = "Go" self.option = 1 self.dir = 1 def turn(self,dir): if dir ==1: self.option = [0,4,3,1,2][([0,1,2,3,4].index(self.option))] elif dir ==-1: self.option = [0,3,4,2,1][([0,1,2,3,4].index(self.option))] else: self.option = [0,2,1,4,3][([0,1,2,3,4].index(self.option))] def move(self,options,sensors): if len(options)==5: return self.option self.turn(self.dir) if not self.option in options: self.turn(self.dir*(-1)) while self.option not in options: self.turn(self.dir) self.dir = self.dir * -1 return self.option