option to cap number of agents
[progcomp10.git] / src / selectAlgorithms.py
1 # Alternative (obsolete) algorithms for selecting agents for battle.
2 # They're all a bit crap and only here for comparison purposes.
3
4
5 # Selects an opponent and removes it from the list of remaining potential opponents.
6        # This is just an example, but the fact that the first agent will miss out on having
7        # a fight picked with it it, and that the last agent won't get to pick a fight, seems
8        # to not matter very much. Can probably be left as-is.
9        def ChoosePair (self):
10                # This approach forces each agent to defend once and attack once per round.
11                # Keep track of the remaining population.
12                remaining = self.population[:]
13                agentID = random.randint (0,len(remaining)-1)
14                defender = remaining.pop (agentID) # Not really a defender (try to work it out)!
15                while len (remaining) > 1:
16                        if defender.GetPoints () < 1:   # If the agent died before it got a chance to attack
17                                attackerID = random.randint (0,len(remaining)-1)
18                                attacker = remaining.pop (attackerID)
19                        else: attacker = defender
20                        defenderID = random.randint (0,len(remaining)-1)
21                        defender = remaining.pop (defenderID)
22                        yield attacker, defender
23

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