示例#1
0
    def _make_observation(self):
        myself = None
        enemy = None
        for uid, ut in self.state['units_myself'].iteritems():
            myself = ut
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy = ut

        obs = np.zeros(self.observation_space.shape)

        if myself is not None and enemy is not None:
            obs[0] = myself.health
            obs[1] = myself.groundCD
            obs[2] = myself.groundRange / DISTANCE_FACTOR - 1
            obs[3] = 0.0
            obs[4] = utils.get_degree(myself.x, -myself.y, enemy.x,
                                      -enemy.y) / 180
            obs[5] = utils.get_distance(myself.x, -myself.y, enemy.x,
                                        -enemy.y) / DISTANCE_FACTOR - 1
            obs[6] = enemy.health
            obs[7] = enemy.groundCD
            obs[8] = enemy.groundRange / DISTANCE_FACTOR - 1
            obs[9] = 1.0
        else:
            obs[9] = 1.0

        return obs
示例#2
0
    def _make_observation(self):
        myself = None
        enemy = None
        for uid, ut in self.state['units_myself'].iteritems():
            myself = ut
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy = ut

        obs = np.zeros(self.observation_space.shape)

        if myself is not None and enemy is not None:
            obs[0] = myself.health
            obs[1] = myself.groundCD
            obs[2] = myself.groundRange / DISTANCE_FACTOR - 1
            obs[3] = 0.0
            obs[4] = utils.get_degree(myself.x, -myself.y, enemy.x,
                                      -enemy.y) / 180
            obs[5] = utils.get_distance(myself.x, -myself.y, enemy.x,
                                        -enemy.y) / DISTANCE_FACTOR - 1
            obs[6] = enemy.health
            obs[7] = enemy.groundCD
            obs[8] = enemy.groundRange / DISTANCE_FACTOR - 1
            obs[9] = 1.0
        else:
            obs[9] = 1.0

        return obs
    def _make_observation(self):
        myself = None
        enemy = None
        factor_list = ["factor "]
        id_list = ["id "]
        #help(self.state.units[0][0])
        #for command in self.state.unitcommands
        for unit in self.state.units[0]:
            myself = unit
            id_list.append(str(unit.command.targetId))
            factor_list.append(str(unit.attacking))
        for unit in self.state.units[1]:
            enemy = unit
        #print (" ").join(factor_list)
        #print (" ").join(id_list)
        obs = np.zeros(self.observation_space.shape)

        if myself is not None and enemy is not None:
            obs[0] = myself.health
            obs[1] = myself.groundCD
            obs[2] = myself.groundRange / DISTANCE_FACTOR - 1
            obs[3] = 0.0
            obs[4] = utils.get_degree(myself.x, -myself.y, enemy.x,
                                      -enemy.y) / 180
            obs[5] = utils.get_distance(myself.x, -myself.y, enemy.x,
                                        -enemy.y) / DISTANCE_FACTOR - 1
            obs[6] = enemy.health
            obs[7] = enemy.groundCD
            obs[8] = enemy.groundRange / DISTANCE_FACTOR - 1
            obs[9] = 1.0
        else:
            obs[9] = 1.0

        return obs
 def get_distance_degree(self, unit):
     dd = []
     for id in self.id_list:
         t = self.units_dict[id]
         distance = utils.get_distance(unit.x, unit.y, t.x, t.y)
         degree = utils.get_degree(unit.x, unit.y, t.x, t.y) / 180.
         dd += [distance, degree]
     return dd
示例#5
0
 def test_get_degree(self):
     self.assertEquals(utils.get_degree(10, -10, 10, -20), -90)
     self.assertEquals(utils.get_degree(10, -10, 10, -5), 90)
     self.assertEquals(utils.get_degree(10, -10, 5, -10), 180)
     self.assertEquals(utils.get_degree(10, -10, 15, -10), 0)
     self.assertEquals(utils.get_degree(10, -10, 20, -20), -45)