def _make_commands(self, action):
        cmds = []
        if self.state is None or action is None:
            return cmds

        myself_id = None
        myself = None
        enemy_id = None
        enemy = None
        for unit in self.state.units[0]:
            myself = unit
            myself_id = unit.id

# ut means what in original code.

        for unit in self.state.units[1]:
            enemy = unit
            enemy_id = unit.id

        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            # cmds.append(proto.concat_cmd(
            #     proto.commands['command_unit_protected'], myself_id,
            #     proto.unit_command_types['Attack_Unit'], enemy_id))
            cmds.append([
                tcc.command_unit_protected, myself_id,
                tcc.unitcommandtypes.Attack_Unit, enemy_id
            ])
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            degree = action[1] * 180
            distance = (action[2] + 1) * DISTANCE_FACTOR
            x2, y2 = utils.get_position(degree, distance, myself.x, -myself.y)
            # cmds.append(proto.concat_cmd(
            #     proto.commands['command_unit_protected'], myself_id,
            #     proto.unit_command_types['Move'], -1, x2, -y2))
            cmds.append([
                tcc.command_unit_protected, myself_id,
                tcc.unitcommandtypes.Move, -1,
                int(x2),
                int(-y2)
            ])
        return cmds
Beispiel #2
0
    def _make_commands(self, action):
        cmds = []
        if self.state is None or not action.any():
            return cmds

        myself_id = None
        myself = None
        enemy_id = None
        enemy = None
        for uid, ut in self.state['units_myself'].iteritems():
            myself_id = uid
            myself = ut
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy_id = uid
            enemy = ut

        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            cmds.append(
                proto.concat_cmd(proto.commands['command_unit_protected'],
                                 myself_id,
                                 proto.unit_command_types['Attack_Unit'],
                                 enemy_id))
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            degree = action[1] * 180
            distance = (action[2] + 1) * DISTANCE_FACTOR
            x2, y2 = utils.get_position(degree, distance, myself.x, -myself.y)
            cmds.append(
                proto.concat_cmd(proto.commands['command_unit_protected'],
                                 myself_id, proto.unit_command_types['Move'],
                                 -1, x2, -y2))

        return cmds
    def _make_commands(self, action):
        cmds = []
        if self.state is None or action is None:
            return cmds

        myself_id = None
        myself = None
        enemy_id = None
        enemy = None
        for uid, ut in self.state['units_myself'].iteritems():
            myself_id = uid
            myself = ut
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy_id = uid
            enemy = ut

        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Attack_Unit'], enemy_id))
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            degree = action[1] * 180
            distance = (action[2] + 1) * DISTANCE_FACTOR
            x2, y2 = utils.get_position(degree, distance, myself.x, -myself.y)
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Move'], -1, x2, -y2))

        return cmds
    def _make_commands(self, action):
        cmds = []
        if self.state is None or action is None:
            return cmds
        '''
        myself_id = None
        myself = None
        enemy_id = None
        enemy = None
        for uid, ut in self.state['units_myself'].iteritems():
            myself_id = uid
            myself = ut
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy_id = uid
            enemy = ut

        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Attack_Unit'], enemy_id))
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            degree = action[1] * 180
            distance = (action[2] + 1) * DISTANCE_FACTOR
            x2, y2 = utils.get_position(degree, distance, myself.x, -myself.y)
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Move'], -1, x2, -y2))
        '''
        for i in range(len(action)):
            uid = int(action[i][0])
            attacking = self.state['units_myself'][uid]
            if action[i][1] > 0:
                # Attack action
                if action[i][4] < 0:
                    continue
                attacked_uid = int(action[i][4])
                attacked = self.state['units_enemy'][attacked_uid]
                if attacking is None or attacked is None:
                    print('attacking or attacked is emety! Please check!')
                    continue
                cmds.append(proto.concat_cmd(proto.commands['command_unit_protected'], uid, 
                    proto.unit_command_types['Attack_Unit'], attacked_uid))
            else:
                # Move action
                if attacking is None:
                    print('The unit to move is empty, please chaeck!')
                    continue
                degree = action[i][2] * 180
                distance = (action[i][3] + 1) * DISTANCE_FACTOR
                x2, y2 = utils.get_position(degree, distance, attacking.x, -attacking.y)
                cmds.append(proto.concat_cmd(proto.commands['command_unit_protected'], uid,
                    proto.unit_command_types['Move'], -1, x2, -y2))


        return cmds
Beispiel #5
0
 def test_get_position(self):
     self.assertEquals(utils.get_position(90, 10, 10, -10), (10, 0))
     self.assertEquals(utils.get_position(0, 10, 10, -10), (20, -10))
     self.assertEquals(utils.get_position(180, 10, 10, -10), (0, -10))
Beispiel #6
0
        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Attack_Unit'], enemy_id))
		print myself_id
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            degree = action[1] * 180
            distance = (action[2] + 1) * DISTANCE_FACTOR
            x2, y2 = utils.get_position(degree, distance, myself.x, -myself.y)
            print myself_id	
            cmds.append(proto.concat_cmd(
                proto.commands['command_unit_protected'], myself_id,
                proto.unit_command_types['Move'], -1, x2, -y2))

        return cmds

    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
Beispiel #7
0
    def _make_commands(self, action):
        cmds = []
        #if self.state is None or not action:
        #    return cmds

        myself_id = []
        myself = []
        enemy_id = []
        enemy = []
        i = 0
        j = 0
        for uid, ut in self.state['units_myself'].iteritems():
            myself_id.append(uid)
            myself.append(ut)
            #print "uid:" + str(uid) + ' ut: ' + str(ut)
            i += 1
        for uid, ut in self.state['units_enemy'].iteritems():
            enemy_id.append(uid)
            enemy.append(ut)
            j += 1
        if action[0] > 0:
            # Attack action
            if myself is None or enemy is None:
                return cmds
            # TODO: compute the enemy id based on its position
            for a in range(0, i, 2):
                for b in range(j):
                    cmds.append(
                        proto.concat_cmd(
                            proto.commands['command_unit_protected'],
                            myself_id[a],
                            proto.unit_command_types['Attack_Unit'],
                            enemy_id[b]))
                    if a < i - 1:
                        cmds.append(
                            proto.concat_cmd(
                                proto.commands['command_unit_protected'],
                                myself_id[a + 1],
                                proto.unit_command_types['Attack_Unit'],
                                enemy_id[b]))
                    j -= 1
        else:
            # Move action
            if myself is None or enemy is None:
                return cmds
            for a in range(0, i, 2):
                degree = action[1] * 180
                distance = (action[2] + 1) * DISTANCE_FACTOR
                x2, y2 = utils.get_position(degree, distance, myself[a].x,
                                            -myself[a].y)
                cmds.append(
                    proto.concat_cmd(proto.commands['command_unit_protected'],
                                     myself_id[a],
                                     proto.unit_command_types['Move'], -1, x2,
                                     -y2))
                if a < i - 1:
                    degree = action[1] * 180
                    distance = (action[2] + 1) * DISTANCE_FACTOR
                    x2, y2 = utils.get_position(degree, distance,
                                                myself[a + 1].x,
                                                -myself[a + 1].y)
                    cmds.append(
                        proto.concat_cmd(
                            proto.commands['command_unit_protected'],
                            myself_id[a + 1], proto.unit_command_types['Move'],
                            -1, x2, -y2))
                j -= 1
        print cmds
        return cmds