X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2FselectAlgorithms.py;fp=src%2FselectAlgorithms.py;h=41be34612346c82fbd50b18994c0ded708055e26;hb=e9a8105a8f22404f4ac550d79954eaa6b7f5d8ff;hp=0000000000000000000000000000000000000000;hpb=4597b27a44522a5c2785cc23029435f44f60ea55;p=progcomp10.git diff --git a/src/selectAlgorithms.py b/src/selectAlgorithms.py new file mode 100644 index 0000000..41be346 --- /dev/null +++ b/src/selectAlgorithms.py @@ -0,0 +1,23 @@ +# Alternative (obsolete) algorithms for selecting agents for battle. +# They're all a bit crap and only here for comparison purposes. + + +# Selects an opponent and removes it from the list of remaining potential opponents. + # This is just an example, but the fact that the first agent will miss out on having + # a fight picked with it it, and that the last agent won't get to pick a fight, seems + # to not matter very much. Can probably be left as-is. + def ChoosePair (self): + # This approach forces each agent to defend once and attack once per round. + # Keep track of the remaining population. + remaining = self.population[:] + agentID = random.randint (0,len(remaining)-1) + defender = remaining.pop (agentID) # Not really a defender (try to work it out)! + while len (remaining) > 1: + if defender.GetPoints () < 1: # If the agent died before it got a chance to attack + attackerID = random.randint (0,len(remaining)-1) + attacker = remaining.pop (attackerID) + else: attacker = defender + defenderID = random.randint (0,len(remaining)-1) + defender = remaining.pop (defenderID) + yield attacker, defender +