/[progcomp]/rps/trunk/SampleAgents.py


UCC Code Repository

Contents of /rps/trunk/SampleAgents.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations) (download) (as text)
Sun Jul 20 16:58:11 2008 UTC (11 years, 2 months ago) by shmookey
File MIME type: text/x-python
File size: 3628 byte(s)
added agent that implements Results ()

1 '''SampleAgents.py - A collection of sample agents for playing Rock Paper Scissors.
2 Written by Luke Williams <shmookey@ucc.asn.au> 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 # If you want to implement your own Results () callback, you have to call the parent class's first:
80 class Blank (BaseAgent):
81 def Attack (self, foe):
82 return Paper, Paper
83 def Defend (self, foe, bluff):
84 return bluff
85 def Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta):
86 BaseAgent.Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta)
87 # Now you can do your own thing
88

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26