6912c7f138d6b60869fab059a5d670ee81e3a821
[progcomp10.git] / rps / trunk / djaAgents.py
1 from uccProgComp import BaseAgent, LearningAgent, RandomAttack
2 from rpsconst import *
3
4 # BOFH is something of a cross between Frechie and Lucifer
5
6 class BOFH (LearningAgent):
7         def Attack (self, foe):
8                 attack = RandomAttack ()
9                 
10                 return attack, bluff
11         def Defend (self, foe, bluff):
12                 if bluff == Rock: attack = Scissors     # Here we assume that they
13                 elif bluff == Paper: attack = Rock      # are lying, trying to kill us.
14                 else: attack = Paper                    # And we try to kill them.
15                 return attack
16
17         def Attack (self, foe):
18                 attack = RandomAttack ()
19                 if len(LearningAgent.GetWinHistory (self, foe)) > 0:
20                         if attack == Rock: bluff = Paper        # Here we choose the thing
21                         elif attack == Paper: bluff = Scissors  # that will hurt them
22                         else: bluff = Rock                      # if they try to kill us.
23                 else:
24                         if attack == Rock: bluff = Scissors     # Here we choose the thing
25                         elif attack == Paper: bluff = Rock      # that will hurt them
26                         else: bluff = Paper                     # if they go for a tie.
27                 return attack, bluff
28                 
29         def Defend (self, foe, bluff):
30                 if len(LearningAgent.GetWinHistory (self, foe)) > 0:
31                         if bluff == Rock: attack = Scissors     # They've fucked us in the past,
32                         elif bluff == Paper: attack = Rock      # so we assume they're lying and
33                         else: attack = Paper                    # hoping we go for a kill.
34                 else:
35                         if bluff == Rock: attack = Paper        # Here we trust that they
36                         elif bluff == Paper: attack = Scissors  # are telling the truth.
37                         else: attack = Rock                     # And we try to kill them.
38                 return attack
39
40 #Fish is somewhat intelligent; it builds up trust and then stabs you in the back.
41 # If Fish detects that a bot is being predictably nice (tie 2+ times in a row), it will attack.
42 # If Fish detects that a bot has betrayed it (Loss), it will attack.
43 # Otherwise, Fish is nice.
44
45 class Fish (LearningAgent):
46         def Attack (self, foe):
47                 #print "Attacking" , foe
48                 #print LearningAgent.GetWinHistory (self, foe)
49                 attack = RandomAttack ()
50                 
51                 history = LearningAgent.GetWinHistory (self, foe)
52                 
53                 #no history; be nice
54                 if len(history) == 0:
55                         bluff = attack
56                 
57                 #if we just lost to them, try to destroy them.
58                 elif Loss == history[-1] or (len(history)>1 and [Tie,Tie] == history[-2:-1]):
59                         if attack == Rock: bluff = Scissors
60                         elif attack == Paper: bluff = Rock
61                         else: bluff = Paper
62                 else:
63                         bluff = attack
64                 return attack, bluff
65                 
66                 
67         def Defend (self, foe, bluff):
68                 
69                 history = LearningAgent.GetWinHistory (self, foe)
70                 
71                 if len(history) > 0 and Loss == history[-1]:
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

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