import * from zerolife class ConflictResolutionPolicy(): '''This resolves conflicts on the board.''' def __init__ (self): self.strengthDict = None '''StrengthDict has tuples for keys and stronger/weaker for values. These tuples are of the form (species1, species2). If species1 is stronger the dictionary will return 1 given this tuple. If species1 is equal the dictionary will return 0 given this tuple. If species1 is weaker the dictionary will return -1 given this tuple.''' def makeMagicalStrengthDictionary(self, parameters): ''''nuff said''' pass def victor(self, instrucList): '''Determines the VICTOR!!!! The first step is to unpack the instruction list provided into a more useful form. We have decided to use the form of a dictionary, where the keys are species, and the each value is the number of the corresponding species present.''' self.speDict = {} self.vicDict = {} for instruc in instrucList: if speDict.keys.contains(instruc.species) speDict[instruc.species] += 1 else: speDict[instruc.species] = 1 '''Now we need to actually decide who wins.''' '''Our conflict resolution policy is as follows: Each species starts with a score of 0. For each other species present that is stronger, 1 is subtracted. For each other species present that is weaker, 1 is added. The species with the highest score is then declared the victor. If there are two or more of the victor species, nothing happens. (MUTUAL DESTRUCTION!!!)''' '''This is a naive implementation of the conflict resolution policy. There are still many ways to optimize this, but we wrote this because it was simple and we wanted to get something down that would work.''' for spe in speDict: vicDict[spe] = 0 for spe1 in vicDict: for spe2 in vicDict: if spe1 != spe2 if self.strengthDict[(spe1, spe2)] == 1 vicDict[spe1] += 1 else if self.strengthDict[(spe1, spe2)] == -1 vicDict[spe1] -= 1 '''Test for victor ties''' self.highScore = [] for spe in vicDict: if vicDict[spe] > self.highScore[0][1] highScore = [] highScore.append((spe, vicDict[spe])) else if vicDict[spe] == self.highScore[0][1] highScore.append((spe, vicDict[spe])) if highScore.len > 1: return None else return highScore[0][0]