Ejemplo n.º 1
0
def match_up(r):
    """ heuristic which determines the match-up according to units numbers
    naming scheme: "XvY" with P first, then T, then Z """
    s = []
    for p in r.players:
        score = 0
        for (k,v) in utils.unit_distribution(p).iteritems():
            score += v
        s.append((score, p))
    max1 = 0
    max2 = 0
    p1 = r.players[0]
    p2 = r.players[1]
    for e in s:
        if e[0] > max1:
            max2 = max1
            max1 = e[0]
            p2 = p1
            p1 = e[1]
        elif e[0] > max2:
            max2 = e[0]
            p2 = e[1]
    mu_raw = p1.race_name[0] + 'v' + p2.race_name[0]
    if mu_raw[2] == 'P': # P in front
        mu_raw = mu_raw[2] + 'v' + mu_raw[0]
    elif mu_raw[2] == 'T' and mu_raw[0] != 'P': # T in front
        mu_raw = mu_raw[2] + 'v' + mu_raw[0]
    return mu_raw
Ejemplo n.º 2
0
 def test_unit_distribution_hatch(self):
     for unit_id in (0x25, 0x25, 0x25, 0x29, 0x29, 0x26, 0x27, 0x26):
         instance = actions.Hatch(0)
         instance.unit_type_id = unit_id
         self.player.actions.append(instance)
     distribution = utils.unit_distribution(self.player)
     self.assertEquals(len(distribution), 4)
     self.assertEquals(distribution['Zergling'], 3)
     self.assertEquals(distribution['Drone'], 2)
     self.assertEquals(distribution['Hydralisk'], 2)
     self.assertEquals(distribution['Ultralisk'], 1)
Ejemplo n.º 3
0
 def test_unit_distribution_train(self):
     for unit_id in (0x00, 0x00, 0x00, 0x07, 0x07, 0x02, 0x05, 0x02):
         instance = actions.Train(0)
         instance.unit_type_id = unit_id
         self.player.actions.append(instance)
     distribution = utils.unit_distribution(self.player)
     self.assertEquals(len(distribution), 4)
     self.assertEquals(distribution['Marine'], 3)
     self.assertEquals(distribution['SCV'], 2)
     self.assertEquals(distribution['Vulture'], 2)
     self.assertEquals(distribution['Siege Tank'], 1)