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


UCC Code Repository

Diff of /rps/trunk/SampleAgents.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by shmookey, Fri Jul 18 07:47:02 2008 UTC revision 21 by shmookey, Sun Jul 20 16:58:11 2008 UTC
# Line 76  class Frenchie (LearningAgent): Line 76  class Frenchie (LearningAgent):
76                          attack = bluff                          attack = bluff
77                  return attack                  return attack
78    
79  # MrAnderson is always trying to get the upper hand.  # If you want to implement your own Results () callback, you have to call the parent class's first:
80  class MrAnderson (LearningAgent):  class Blank (BaseAgent):
81          def Attack (self, foe):          def Attack (self, foe):
82                  attack = RandomAttack ()                  return Paper, Paper
                 if Loss in LearningAgent.GetWinHistory (self, foe):  
                         if attack == Rock: bluff = Scissors  
                         elif attack == Paper: bluff = Rock  
                         else: bluff = Paper  
                 else:  
                         bluff = attack  
                 return attack, bluff  
83          def Defend (self, foe, bluff):          def Defend (self, foe, bluff):
84                  if Loss in LearningAgent.GetWinHistory (self, foe):                  return bluff
85                          if bluff == Rock: attack = Scissors     # They've fucked us in the past,          def Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta):
86                          elif bluff == Paper: attack = Rock      # so we assume they're lying and                  BaseAgent.Results (self, foeName, wasAttacker, winner, attItem, defItem, bluffItem, pointDelta)
87                          else: attack = Paper                    # hoping we go for a kill.                  # Now you can do your own thing
88                  else:  
                         attack = bluff  
                 return attack  
                   
 # JollyRoger never was the smartest man.  
 class JollyRoger (LearningAgent):  
         def Attack (self, foe):  
                 attack = RandomAttack ()  
                 if Loss in LearningAgent.GetWinHistory (self, foe):  
                         if attack == Rock: bluff = Scissors  
                         elif attack == Paper: bluff = Rock  
                         else: bluff = Paper  
                 else:  
                         bluff = attack  
                 return attack, bluff  
         def Defend (self, foe, bluff):  
                 if Loss in LearningAgent.GetWinHistory (self, foe):  
                         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  

Legend:
Removed from v.20  
changed lines
  Added in v.21

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26