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): net = contestPowersBayesNet.powersBayesNet() leftCapsules = [] rightCapsules = [] width, height = gameState.data.layout.width, gameState.data.layout.height for i in range(len(opponentEvidences)): jointLaserInvisibility = inference.inferenceByVariableElimination( net, ['laser', 'invisibility'], opponentEvidences[i], None) strong_laser_prob = 0 weak_laser_prob = 0 invisible = 0 for assignmentDict in jointLaserInvisibility.getAllPossibleAssignmentDicts( ): if assignmentDict['laser'] == 2: strong_laser_prob += jointLaserInvisibility.getProbability( assignmentDict) if assignmentDict['laser'] == 1: weak_laser_prob += jointLaserInvisibility.getProbability( assignmentDict) if assignmentDict['invisibility'] == 2 or assignmentDict[ 'invisibility'] == 1: invisible += jointLaserInvisibility.getProbability( assignmentDict) if i == 0: if len(leftCapsules) < (capsuleLimit / 2): if strong_laser_prob > weak_laser_prob: x = random.randint(1, (width / 2) - 1) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): leftCapsules.append(ArmourCapsule(x, y)) if len(leftCapsules) < (capsuleLimit / 2): if invisible > 0.5: x = random.randint(1, (width / 2) - 1) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): leftCapsules.append(SonarCapsule(x, y)) while len(leftCapsules) < (capsuleLimit / 2): x = random.randint(1, (width / 2) - 1) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): leftCapsules.append(GrenadeCapsule(x, y)) elif i == 1: if len(rightCapsules) < (capsuleLimit / 2): if strong_laser_prob > weak_laser_prob: x = random.randint((width / 2), width - 2) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): rightCapsules.append(ArmourCapsule(x, y)) if len(rightCapsules) < (capsuleLimit / 2): if invisible > 0.5: x = random.randint((width / 2), width - 2) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): rightCapsules.append(SonarCapsule(x, y)) while len(rightCapsules) < (capsuleLimit / 2): x = random.randint((width / 2), width - 2) y = random.randint(1, height - 2) if gameState.isValidPosition((x, y), self.isRed): rightCapsules.append(GrenadeCapsule(x, y)) return leftCapsules + rightCapsules
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 - 2 else: x = width / 2 + 1 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(SonarCapsule(x, y)) else: defenceCapsules.append(GrenadeCapsule(x, y)) offenseCapsules = [] while len(offenseCapsules) < capsuleLimit / 2: if self.isRed: x = width / 2 else: x = width / 2 - 1 y = random.randint(1, height - 2) if gameState.isValidPosition( (x, y), self.isRed) and (x, y) not in [ c.getPosition for c in offenseCapsules ]: if len(offenseCapsules) == 0: offenseCapsules.append(JuggernautCapsule(x, y)) else: offenseCapsules.append(GrenadeCapsule(x, y)) return defenceCapsules + offenseCapsules