コード例 #1
0
 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
コード例 #2
0
 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