1 '''SampleAgents.py - A collection of sample agents for playing Rock Paper Scissors.
2 Written by Luke Williams <
[email protected]> for the UCC Programming Competition in 2008.
5 Licensed under an MIT-style license: see the LICENSE file for details.
8 from uccProgComp import BaseAgent, LearningAgent, RandomAttack
11 # Angel is a very simple bot that always tells the truth and expects others to do the same.
12 class Dummy (BaseAgent):
13 def Attack (self, foe):
15 def Defend (self, foe, bluff):
18 class Angel (BaseAgent):
19 def Attack (self, foe):
20 attack = RandomAttack () # Chooses randomly from Rock, Paper, Scissors
21 return attack, attack # Tells the truth for its bluff.
22 def Defend (self, foe, bluff):
23 return bluff # Trusts them to be going for a tie.
25 # Lucifer here is the opposite. He always lies expecting people to be good and always goes for the kill.
26 class Lucifer (BaseAgent):
27 def Attack (self, foe):
28 attack = RandomAttack ()
29 if attack == Rock: bluff = Scissors # Here we choose the thing
30 elif attack == Paper: bluff = Rock # that will hurt them
31 else: bluff = Paper # if they go for a tie.
33 def Defend (self, foe, bluff):
34 if bluff == Rock: attack = Paper # Here we trust that they
35 elif bluff == Paper: attack = Scissors # are telling the truth.
36 else: attack = Rock # And we try to kill them.
38 # def Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta):
39 # BaseAgent.Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta)
40 # print "I just scored " + str(pointDelta) + " points!"
43 # Streetfighter assumes everyone has it in for him.
44 class Streetfighter (BaseAgent):
45 def Attack (self, foe):
46 attack = RandomAttack ()
47 if attack == Rock: bluff = Paper # Here we choose the thing
48 elif attack == Paper: bluff = Scissors # that will hurt them
49 else: bluff = Rock # if they try to kill us.
51 def Defend (self, foe, bluff):
52 if bluff == Rock: attack = Scissors # Here we assume that they
53 elif bluff == Paper: attack = Rock # are lying, trying to kill us.
54 else: attack = Paper # And we try to kill them.
57 # This is our first bot with any sort of learning capability, based on the LearningAgent base.
58 # Experienced programmers might opt to write their own learning code based on BaseAgent, but it's up to you.
59 # Wash is a simple bot that is by default nice but will permanently turn against any agent that betrays it.
60 # "Curse your suddent but inevitable betrayal" - Wash (Firefly)
61 class Wash (LearningAgent):
62 def Attack (self, foe):
63 attack = RandomAttack ()
64 if Loss in LearningAgent.GetWinHistory (self, foe):
65 if attack == Rock: bluff = Scissors
66 elif attack == Paper: bluff = Rock
71 def Defend (self, foe, bluff):
72 if Loss in LearningAgent.GetWinHistory (self, foe):
73 if bluff == Rock: attack = Scissors # They've screwed us in the past,
74 elif bluff == Paper: attack = Rock # so we assume they're lying and
75 else: attack = Paper # hoping we go for a kill.
81 # If you want to implement your own Results () callback, you have to call the parent class's first:
82 class Blank (BaseAgent):
83 def Attack (self, foe):
85 def Defend (self, foe, bluff):
87 def Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta):
88 BaseAgent.Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta)
89 # Now you can do your own thing