d307214ac53e8e7e3a4677cd6b3126cec7980ae2
[progcomp10.git] / src / SampleAgents.py.old
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.
3 Requires Python 2.5.
4
5 Licensed under an MIT-style license: see the LICENSE file for details.
6 '''
7
8 from uccProgComp import BaseAgent, LearningAgent, RandomAttack
9 from rpsconst import *
10
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):
14                 return Paper, Paper
15         def Defend (self, foe, bluff):
16                 return bluff
17
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.
24
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.
32                 return attack, bluff
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.
37                 return attack
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!"
41
42
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 go for a tie.
50                 return attack, bluff
51         def Defend (self, foe, bluff):
52                 if bluff == Rock: attack = Paper        # Here we trust that they
53                 elif bluff == Paper: attack = Scissors  # are telling the truth.
54                 else: attack = Rock                     # And we try to kill them.
55                 return attack
56
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 # Frenchie is a simple bot that is by default nice but will permanently turn against any agent that betrays it.
60 class Frenchie (LearningAgent):
61         def Attack (self, foe):
62                 attack = RandomAttack ()
63                 if Loss in LearningAgent.GetWinHistory (self, foe):
64                         if attack == Rock: bluff = Scissors
65                         elif attack == Paper: bluff = Rock
66                         else: bluff = Paper
67                 else:
68                         bluff = attack
69                 return attack, bluff
70         def Defend (self, foe, bluff):
71                 if Loss in LearningAgent.GetWinHistory (self, foe):
72                         if bluff == Rock: attack = Scissors     # They've fucked us in the past,
73                         elif bluff == Paper: attack = Rock      # so we assume they're lying and
74                         else: attack = Paper                    # hoping we go for a kill.
75                 else:
76                         attack = bluff
77                 return attack
78
79
80 # If you want to implement your own Results () callback, you have to call the parent class's first:
81 class Blank (BaseAgent):
82         def Attack (self, foe):
83                 return Paper, Paper
84         def Defend (self, foe, bluff):
85                 return bluff
86         def Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta):
87                 BaseAgent.Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta)
88                 # Now you can do your own thing
89

UCC git Repository :: git.ucc.asn.au