X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2FdjaAgents.py;fp=src%2FdjaAgents.py;h=6912c7f138d6b60869fab059a5d670ee81e3a821;hb=e9a8105a8f22404f4ac550d79954eaa6b7f5d8ff;hp=0000000000000000000000000000000000000000;hpb=4597b27a44522a5c2785cc23029435f44f60ea55;p=progcomp10.git diff --git a/src/djaAgents.py b/src/djaAgents.py new file mode 100644 index 0000000..6912c7f --- /dev/null +++ b/src/djaAgents.py @@ -0,0 +1,77 @@ +from uccProgComp import BaseAgent, LearningAgent, RandomAttack +from rpsconst import * + +# BOFH is something of a cross between Frechie and Lucifer + +class BOFH (LearningAgent): + def Attack (self, foe): + attack = RandomAttack () + + return attack, bluff + def Defend (self, foe, bluff): + if bluff == Rock: attack = Scissors # Here we assume that they + elif bluff == Paper: attack = Rock # are lying, trying to kill us. + else: attack = Paper # And we try to kill them. + return attack + + def Attack (self, foe): + attack = RandomAttack () + if len(LearningAgent.GetWinHistory (self, foe)) > 0: + if attack == Rock: bluff = Paper # Here we choose the thing + elif attack == Paper: bluff = Scissors # that will hurt them + else: bluff = Rock # if they try to kill us. + else: + if attack == Rock: bluff = Scissors # Here we choose the thing + elif attack == Paper: bluff = Rock # that will hurt them + else: bluff = Paper # if they go for a tie. + return attack, bluff + + def Defend (self, foe, bluff): + if len(LearningAgent.GetWinHistory (self, foe)) > 0: + if bluff == Rock: attack = Scissors # They've fucked us in the past, + elif bluff == Paper: attack = Rock # so we assume they're lying and + else: attack = Paper # hoping we go for a kill. + else: + if bluff == Rock: attack = Paper # Here we trust that they + elif bluff == Paper: attack = Scissors # are telling the truth. + else: attack = Rock # And we try to kill them. + return attack + +#Fish is somewhat intelligent; it builds up trust and then stabs you in the back. +# If Fish detects that a bot is being predictably nice (tie 2+ times in a row), it will attack. +# If Fish detects that a bot has betrayed it (Loss), it will attack. +# Otherwise, Fish is nice. + +class Fish (LearningAgent): + def Attack (self, foe): + #print "Attacking" , foe + #print LearningAgent.GetWinHistory (self, foe) + attack = RandomAttack () + + history = LearningAgent.GetWinHistory (self, foe) + + #no history; be nice + if len(history) == 0: + bluff = attack + + #if we just lost to them, try to destroy them. + elif Loss == history[-1] or (len(history)>1 and [Tie,Tie] == history[-2:-1]): + if attack == Rock: bluff = Scissors + elif attack == Paper: bluff = Rock + else: bluff = Paper + else: + bluff = attack + return attack, bluff + + + def Defend (self, foe, bluff): + + history = LearningAgent.GetWinHistory (self, foe) + + if len(history) > 0 and Loss == history[-1]: + if bluff == Rock: attack = Scissors # They've fucked us in the past, + elif bluff == Paper: attack = Rock # so we assume they're lying and + else: attack = Paper # hoping we go for a kill. + else: + attack = bluff + return attack \ No newline at end of file