def chooseCapsules(self, gameState, capsule_limit, opponent_evidences): width, height = gameState.data.layout.width, gameState.data.layout.height left_caps, right_caps = [], [] while len(left_caps) < (capsule_limit / 2): x = random.randint(1, (width / 2) - 1) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): if self.isRed: if len(left_caps) % 2 == 0: left_caps.append(ArmourCapsule(x, y)) else: left_caps.append(JuggernautCapsule(x, y)) else: if len(left_caps) % 2 == 0: left_caps.append(SonarCapsule(x, y)) else: left_caps.append(ScareCapsule(x, y)) while len(right_caps) < (capsule_limit / 2): x = random.randint(1, (width / 2) - 1) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): if self.isRed: if len(right_caps) % 2 == 0: right_caps.append(SonarCapsule(x, y)) else: right_caps.append(ScareCapsule(x, y)) else: if len(left_caps) % 2 == 0: right_caps.append(ArmourCapsule(x, y)) else: right_caps.append(JuggernautCapsule(x, y)) return left_caps + right_caps
def chooseCapsules(self, gameState, capsuleLimit, opponentEvidences): # Do custom processing on the opponent's power evidence in order to # effectively choose your capsules. net = contestPowersBayesNet.powersBayesNet() # for instance to calculate the joint distribution of the # enemy agent 0 choosing invisibility and speed: # from inference import inferenceByVariableElimination jointSpeedInvisibility = inference.inferenceByVariableElimination( net, ['invisibility', 'speed'], opponentEvidences[0], None) # or compute the marginal factors of the enemy powers, given the # evidenceAssignmentDict of the sum variables in the enemy powersBayesNet enemyAgentMarginals = [] for evidence in opponentEvidences: marginals = contestPowersBayesNet.computeMarginals(evidence) enemyAgentMarginals.append(marginals) # now perform other inference for other factors or use these marginals to # choose your capsules # these are not good choices, this is just to show you how to choose capsules width, height = gameState.data.layout.width, gameState.data.layout.height defenceCapsules = [] while len(defenceCapsules) < (capsuleLimit / 2): if self.isRed: x = (width / 2) + 1 else: x = (width / 2) - 2 y = random.randint(1, height - 2) if gameState.isValidPosition( (x, y), self.isRed) and (x, y) not in [ c.getPosition for c in defenceCapsules ]: if len(defenceCapsules) == 0: defenceCapsules.append(JuggernautCapsule(x, y)) else: defenceCapsules.append(GrenadeCapsule(x, y)) offenseCapsules = [] i = 4 while len(offenseCapsules) < capsuleLimit / 2: if self.isRed: x = 1 y = i else: x = width - 2 y = height - i if gameState.isValidPosition( (x, y), self.isRed) and (x, y) not in [ c.getPosition for c in offenseCapsules ]: offenseCapsules.append(GrenadeCapsule(x, y)) i += 1 return defenceCapsules + offenseCapsules