예제 #1
0
    def action(self):
        if self.delay():
            return self.delay_action

        if self.state == 0:
            return ac.turn_left(ac.empty(), arg=90)
        elif self.state == 1:
            return ac.turn_left(ac.empty(), arg=180)
        elif self.state == 2:
            return ac.turn_left(ac.empty(), arg=90)
        else:
            self.position += 1 if self.direction else -1
            return ac.step_aside(ac.empty(), right=self.direction)
예제 #2
0
 def move_to_faceforward(self, next_tile):
     curr = (self.x, self.y)
     delta = (-curr[0] +next_tile[0], -curr[1] +next_tile[1])
     assert (delta[0] < 2 and delta[1] == 0) or (delta[1] < 2 and delta[0] == 0)
     offset = self._decompensate_yaw(delta)
     print 'move offset to delta %s -%3d-> %s' % (delta, self.yaw, offset)
     if offset[0] == 0:
         if offset[1] < 0:
             return ac.turn_left(ac.empty(), arg = 180), next_tile
         self.x, self.y = next_tile
         return self.move_to_action(ac.empty(), offset), None
     else:
         ang = 90 if offset[0] > 1 else 270
         return ac.turn_left(ac.empty(), arg = ang), next_tile
예제 #3
0
    def handle(self, dmap, a):
        min_d = 2
        center_blocked = ac.central_dist(dmap) == min_d
        next_left = ac.column_min_dist(dmap, 0) > min_d
        next_right = ac.column_min_dist(dmap, -1) > min_d

        # save visual data
        self.map.see_offset((0, 1), blocked=center_blocked)
        if next_left:
            self.map.see_offset((-1, 1))
        if next_right:
            self.map.see_offset((1, 1))
        self.map.print_current()
        print self.map.get_view((-1, 1)), self.map.get_view((1, 1)), next_left, next_right, self.map.yaw

        # turn to the next unobserved point
        angle = 0
        current_offset = (0, 1)
        for i in range(4):
            current_offset = mp.MapTracker.compensate_yaw(current_offset, 90)
            angle += 90
            if self.map.get_view(current_offset) == mp.MapTracker.Unknown:
                self.move = ac.turn_left(ac.empty(), arg=angle)
                return
        self.finished = True
        self.move = ac.empty()
예제 #4
0
 def assign_precise_search(self):
     print('current best: %d %f' % (self.bestAngle, self.bestQuality))
     width = 1   # check in *width current steps apart
     move = ac.turn_left(ac.empty(), self.bestAngle + width * self.step - self.currentAngle)
     self.targetAngle = self.bestAngle - width * self.step
     self.step = 1
     self.precise_mode = True
     return move
예제 #5
0
 def action(self):
     if not self.direction_selected:
         self.directions_checked += 1
         if self.directions_checked == self.min_angle + 4:
             self.direction_selected = True
         return ac.turn_left(ac.empty(), arg=90)
     else:
         return self.subturn()
예제 #6
0
 def _turn_action(self):
     t = 5
     if self._turn_count == 0:
         self._turn_turns += 1
         print ('frame: %d \t turn: %d \t angle: %d' % (self._turn_total, self._turn_turns, self.currentAngle))
         self._turn_count = self._turn_cycle - 1
         return ac.turn_left(ac.empty(), t)
     else:
         self._turn_count -= 1
         return ac.empty()
예제 #7
0
    def subturn(self, direction):
        '''Turn by 1 degree and make a step every STEP turns'''
        self.substep = self.substep + 1 if self.substep < STEP else 0
        action = ac.turn_left(ac.empty(), arg=direction)

        # skip a bit once a circle
        if self.turn != 0 and self.turn % 360 == 0 and self.substep == 0:
            action = ac.empty()
            print('SKIPPED A BIT')

        if self.substep == 0:
            action = ac.step(action, forward=True)
        return action
예제 #8
0
    def action(self):
        self.move = ac.empty()
        self._turn_total += 1     # count the frames
        if not self.skipped(): return self.move

        dist = float(self.targetAngle - self.currentAngle)
        if math.fabs(dist/self.step) > 0.5:
            turn = int(self.step * np.sign(dist))
            self.assigned += turn
            self.move = ac.turn_left(self.move, turn)
        else:
            # assign new target
            if self.precise_mode:
                print('current best: %d %f' % (self.bestAngle, self.bestQuality))
                if self.dance_around == 0:
                    self.finished = True
                    self.map.reset_yaw()
                self.dance_around *= -1
                self.targetAngle = self.bestAngle
                self.move = ac.turn_left(ac.empty(), self.bestAngle - self.currentAngle + self.dance_around)
            else:
                self.move = self.assign_precise_search()
        return self.move
예제 #9
0
    def action(self):
        if not self.direction_selected:
            self.angle += 1
            if self.angle == self.min_angle + 4:
                self.direction_selected = True
            return ac.turn_left(ac.empty(), arg=90)

        if self.turn % 360 == 0:
            self.turn_back = 0;

        print(self.turn, self.turn_back)
        if self.turn == TOTAL + 2*STEP:
            exit(0)

        else:
            if (self.turn % 360) != 180 or self.turn_back == 360:
                self.turn += 1
                return self.subturn(1)
            else:
                self.turn_back += 1
                return self.subturn(-1)