Пример #1
0
    def setSource ( self, value ):
        if self._cap:
            if self._cap._capture.isOpened(): #ugly access to VideoCapture object from managers
                self._cap._capture.release()
        
        self._cap = CaptureManager( cv2.VideoCapture(int(value)) )
        #self.indWindow = cv2.namedWindow("Camera Display")
        self.showImage = True
        self.actualRes = self._cap.getResolution()


        # Set to default resolution from camera (640x480)
        #res = "%d x %d" % (int(self.actualRes[0]), int(self.actualRes[1]) )
        #index = self.ui.comboBox.findText(res) #Sets picker to default resolution
        #self.ui.comboBox.setCurrentIndex(index)

        # Set to Hoky desired default res (1280x960)
        res = "%d x %d" % (int(self.idealRes[0]), int(self.idealRes[1]) )
        index = self.ui.comboBox.findText(res) #Sets picker to default resolution
        self.ui.comboBox.setCurrentIndex(index)
        self.resolutionSelect()
        




        self.p = Point(200,300)
        self.c = Point(self.actualRes[0] // 2, self.actualRes[1] // 2)
        self.setAble('settings', True)
Пример #2
0
def addpoints(xk, fxk, D, Y2, krig, index, theta, delta, pmax, opt_theta):
    points = krig.points
    # index(find(index=-1,1)) = length(fvals) + 1
    # hard code WARNING
    point = Point(2)
    point.x = xk.x
    point.fval = fxk
    points.append(point)
    Y2_0 = Y2
    index_0 = index
    
    if opt_theta:
        raise AssertionError("Optimization of hyperparameters not implemented.")

    else:
        ntest = 0
        psi = 1.0
        thetagauss = krig.params[0]


    L = []
    Y2 = Y2_0
    index = index_0

    return krig
Пример #3
0
    def find_path_to(self, target):
        blocks = [Point(point, target) for point in self.body]
        head = Point(self.head, target)

        neighbors = head.detect_neighbors_except(blocks)
        selected = min(neighbors)

        return selected
Пример #4
0
def nav():
    r = Robot()
    pose = utils.home_pose
    destination = Point(x=0, y=0)
    destination_x = raw_input('enter destination x')
    destination.x = int(destination_x)
    destination_y = raw_input('enter destination y')
    destination.y = int(destination_y)
    distance = utils.wu_to_point(destination, pose)
    angle = utils.rotation_to_point(destination, pose)

    '''go to point from pose'''
    r.r.rotate(angle)
    time.sleep(2)
    r.r.travel(distance)
    def __init__(self, x, y, grid):
        from World import World
        p = World().get_parameters()

        Point.__init__(self, x, y)
        self._grid = grid
        self._car_stack = []
        self._neighbours = None
        self._streets = None

        # self.model_params = {'cars_in_node': 2, 'street_length': 1}
        # self._max_car_stack = self.model_params['cars_in_node']
        # self._max_cars_on_street = self.model_params['street_length']
        self._max_car_stack = p.junction_capacity
        self._max_cars_on_street = p.street_capacity
        self._junction_throughput = p.junction_throughput  # was MAX_ROAD_PUSHES before
        self._street_throughput = p.street_throughput  # was MAX_MOVES before
Пример #6
0
def rbfmodel(objective, fid, xk, fxk, krig, theta_1, theta_2, theta_3, theta_4, \
                 delta, deltamax, pmax, optTheta):
    deltamax = delta
    D = krig.points
    Y2, linear, Z, index = affpoints(xk, D, theta_1, theta_3*delta)
    if not linear:
        Z = Z*delta
        for i in range(len(Z[0,:])):
            # Hard code alert
            point = Point(2)
            point.x = xk.x + Z.view(np.ndarray)[:,i]
            Y2.append(point)
            D.append(point)
            f_high = objective(point, fid[1])
            point.fval = f_high - objective(point, fid[0])
            krig.points.append(point)
            index.append(len(krig.points)-1)
        linear = True

    krig = addpoints(xk, fxk[1]-fxk[0], D, Y2, krig, index, theta_2, theta_4*deltamax, pmax, optTheta)

    return krig, linear
Пример #7
0
    def init_models(self):
        if self.LHS == 0:
            point = Point(self.n)
            point.x = np.array([-2.0, 2.0])
            f_low = self.objective(point, self.fid[0])
            f_high = self.objective(point, self.fid[1])
            point.fval = f_high - f_low
            self.low_fid_eval += 1
        elif self.LHS == 1:
            raise AssertionError("Latin hypercube not implemented. Set LHS = 0")
        else:
            raise AssertionError("LHS can be either 1 or 0")

        krig = Kriging(self.corr, self.params, [point])
        print point.fval
        xk = point
        fk = f_high
        f_low = f_low
        mk = f_high
        delta = self.delta_0
        krig, linear = rbfmodel(self.objective, self.fid, xk, [f_low, fk], krig,\
                                    self.theta_1, self.theta_2, self.theta_3, self.theta_4,\
                                    delta, self.delta_max, self.pmax, self.optTheta)
Пример #8
0
def affpoints(xk, D, theta, delta):
    m = len(D)
    n = len(D[0].x)
    Y = [Point(n)]
    Y2 = [xk]
    index = [-1]
    Z = np.matrix(np.identity(n))
    p = int(round(m*random()+0.5))
    if p > 1.0:
        ## indexes check properly
        vec = range(p, m)
        vec.extend(range(0, p-1))
    else:
        vec = range(m)
    if DEBUG:
        print vec
    
    for i in vec:
        if np.linalg.norm(D[i].x - xk.x) <= delta:
            Z = np.matrix(Z)
            proj_z = Z*np.linalg.inv(Z.transpose()*Z)*Z.transpose()*np.matrix(D[i].x-xk.x).transpose()
            if np.linalg.norm(proj_z) >= delta*theta:
                point = Point(n)
                point.x = D[i].x - xk.x
                Y.append(point) 
                Y_matrix = array([])
                for j in range(len(Y)):
                    Y_matrix = np.concatenate((Y_matrix, Y[j].x), 1)
                Z = null(Y_matrix)
                Y2.append(D[i])
                index.append(i)
                print "here"
    if len(Y) == n + 1:
        linear = True
    else:
        linear = False
    return Y2, linear, Z, index
Пример #9
0
    def resolutionSelect ( self ):
        # Get desired resolution from the user: 
        self.idealRes = self.ui.comboBox.currentText().split('x')
        self.idealRes = map(lambda x: int(x), self.idealRes)

        logger.debug("User input res: %d %d" % (self.idealRes[0], self.idealRes[1])  )
            
        # Attempt to change the resolution:
        self._cap.setProp('width', self.idealRes[0])
        self._cap.setProp('height', self.idealRes[1])
        self.actualRes = self._cap.getResolution()

        # Something went wrong with resolution assignment -- possible need for shut down if resolution can't even be queried
        self.c = Point(self.actualRes[0] // 2, self.actualRes[1] // 2)
        if not ( self.actualRes == self.idealRes ):
            QtWidgets.QMessageBox.information( self, "Resolution",
                                              "That resolution isn't supported by the camera. Instead, your actual resolution is: %d x %d" % (self.actualRes[0], self.actualRes[1] ) )
            res = "%d x %d" % (int(self.actualRes[0]), int(self.actualRes[1]) )
            index = self.ui.comboBox.findText(res)
            self.ui.comboBox.setCurrentIndex(index)
Пример #10
0
    def generate_starting_area(self,
                               random,
                               player,
                               lower,
                               upper,
                               num_creatures=2,
                               start_gold=100,
                               num_resources=1,
                               gold_amount_func=lambda i: 100 / (i + 1),
                               gold_flux_func=lambda i: 10 * (i + 1)):
        """
        Randomically place fortresses, starting creatures and resources.

        Keyword arguments:
        random         -- Python's random module.
        player         -- The player's name.
        lower          -- 
        upper          -- 
        num_creatures  -- The number of starting creatures for each player.
        start_gold     -- The amount of starting gold for each player.
        num_resources  -- The number of starting resources scattered around
                           the map, one of which is a large resource
                           that is created near each player's fortress.
        """
        random_points = Point.generate(random,
                                       lower=lower,
                                       upper=upper,
                                       count=(1 + num_creatures + num_resources))

        self.insert_fortress(Fortress(player, start_gold, position=random_points.pop()))

        for i in range(num_creatures):
            self.insert_creature(Creature('Peon', player, position=random_points.pop()))

        for i in range(num_resources):
            self.insert_resource(Resource('Gold Mine', gold_amount_func(i), gold_flux_func(i), position=random_points.pop()))
Пример #11
0
def combat_move_to_button_left():
    point = random_point(Point(257, 247-22), Point(327, 289-22))
    point.moveTo()
Пример #12
0
def sortie_select_area_3():
    point = random_point(Point(280, 447-22), Point(336, 480-22))
    point.click()
Пример #13
0
def sortie_select_area_2():
    point = random_point(Point(215, 425), Point(250, 458))
    point.click()
Пример #14
0
def expedition_select_map_5():
    random_click(Point(352, 422), Point(387, 450))
Пример #15
0
def sortie_select_area_5():
    point = random_point(Point(435, 425), Point(468, 448))
    point.click()
Пример #16
0
def expedition_select_map_1():
    random_click(Point(119, 422), Point(156, 450))
Пример #17
0
def expedition_select_map_3():
    random_click(Point(240, 422), Point(274, 450))
Пример #18
0
def combat_formation_diamond():
    print("combat_formation_diamond")
    point = random_point(Point(667, 200-22), Point(755, 216-22))
    point.click()
Пример #19
0
def combat_formation_combined_antisub():
    print("combat_formation_combined_antisub")
    random_click(Point(435, 187-22), Point(563, 208-22))
Пример #20
0
def combat_formation_double():
    print("combat_formation_double")
    point = random_point(Point(538, 200-22), Point(616, 216-22))
    point.click()
Пример #21
0
def combat_formation_abreast():
    print("combat_formation_abreast")
    point = random_point(Point(607, 355-22), Point(685, 374-22))
    point.click()
Пример #22
0
def combat_formation_line():
    print("combat_formation_line")
    point = random_point(Point(403, 200-22), Point(492, 216-22))
    point.click()
Пример #23
0
def combat_compass():
    print("combat_compass")
    random_sleep(1.6)
    point = random_point(Point(500, 400-22), Point(750, 450-22))
    point.click()
    random_sleep(4.2)   # 动画时间
Пример #24
0
def sortie_select_area_ex():
    random_click(Point(670, 450-22), Point(750, 480-22))
Пример #25
0
def combat_move_to_button_right():
    point = random_point(Point(473, 238-22), Point(551, 289-22))
    point.moveTo()
Пример #26
0
def combat_formation_combined_forward():
    print("combat_formation_combined_forward")
    random_click(Point(602, 187-22), Point(728, 208-22))
Пример #27
0
def port_open_panel_supply():
    print("port_open_panel_supply")
    point = random_point(Point(48, 211-22), Point(102, 274-22))
    point.click()
    random_sleep(1.2)
Пример #28
0
class Gui(QtWidgets.QMainWindow):

    ## Signals
    #closeGui = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        
        
        ## Instantiate classes
        self.ui = Ui_CalibrationUI()
        self.ui.setupUi(self)

        self._cap = None
        self.ebb = None
        ## Stuff you can change in the UI
        self.width = None
        self.idealRes = [1280, 960]
        self.colSteps = 0
        self.rowSteps = 0
        self.multFactor = 1
        self.motorsAble = False
        self.showImage = False

        ## Stuff that doesn't change
        #self._cap = CaptureManager( cv2.VideoCapture(0) )
        
        
        

        ## Video stuff
        self._timer = QtCore.QTimer( self )
        self._timer.timeout.connect( self.play )
        self._timer.start(27)
        self.update()

        source = [0, 1, 2,3, 'led_move1.avi', 
                  'screencast.avi',
                  'screencast 1.avi',
                  'shortNoBox.avi',
                  'longNoBox.avi',
                  'H299.avi',
                  'testRec.avi',
                  'longDemo.avi']
        for s in source:
            self.ui.sourceCombo.addItem(str(s))


        ## Register button actions
        self.ui.buttonSet.clicked.connect( self.set )
        self.ui.buttonCenter.clicked.connect( self.center )
        self.ui.buttonReset.clicked.connect( self.reset )
        self.ui.buttonSave.clicked.connect( self.save )
        self.ui.buttonRight.clicked.connect( partial( self.motors, 'right' ) )
        self.ui.buttonLeft.clicked.connect( partial( self.motors, 'left' ) )
        self.ui.buttonUp.clicked.connect( partial( self.motors, 'up' ) )
        self.ui.buttonDown.clicked.connect( partial( self.motors, 'down' ) )
        self.ui.scalingSlider.valueChanged[int].connect( self.setMultFactor )
        self.ui.scalingSlider.setValue(10)
        self.ui.scaling.setText( 'Motor scaling is %d' % self.ui.scalingSlider.value() ) 
        self.ui.sourceCombo.activated[int].connect( self.setSource )
        self.ui.comboBox.activated.connect ( self.resolutionSelect )
                


        self.setAble('settings', False)
        self.setAble('motors', False)
        self.setAble('center', False)
        self.setAble('reset', False)
        self.setAble('save', False)
    
    def setSource ( self, value ):
        if self._cap:
            if self._cap._capture.isOpened(): #ugly access to VideoCapture object from managers
                self._cap._capture.release()
        
        self._cap = CaptureManager( cv2.VideoCapture(int(value)) )
        #self.indWindow = cv2.namedWindow("Camera Display")
        self.showImage = True
        self.actualRes = self._cap.getResolution()


        # Set to default resolution from camera (640x480)
        #res = "%d x %d" % (int(self.actualRes[0]), int(self.actualRes[1]) )
        #index = self.ui.comboBox.findText(res) #Sets picker to default resolution
        #self.ui.comboBox.setCurrentIndex(index)

        # Set to Hoky desired default res (1280x960)
        res = "%d x %d" % (int(self.idealRes[0]), int(self.idealRes[1]) )
        index = self.ui.comboBox.findText(res) #Sets picker to default resolution
        self.ui.comboBox.setCurrentIndex(index)
        self.resolutionSelect()
        




        self.p = Point(200,300)
        self.c = Point(self.actualRes[0] // 2, self.actualRes[1] // 2)
        self.setAble('settings', True)

    def resolutionSelect ( self ):
        # Get desired resolution from the user: 
        self.idealRes = self.ui.comboBox.currentText().split('x')
        self.idealRes = map(lambda x: int(x), self.idealRes)

        logger.debug("User input res: %d %d" % (self.idealRes[0], self.idealRes[1])  )
            
        # Attempt to change the resolution:
        self._cap.setProp('width', self.idealRes[0])
        self._cap.setProp('height', self.idealRes[1])
        self.actualRes = self._cap.getResolution()

        # Something went wrong with resolution assignment -- possible need for shut down if resolution can't even be queried
        self.c = Point(self.actualRes[0] // 2, self.actualRes[1] // 2)
        if not ( self.actualRes == self.idealRes ):
            QtWidgets.QMessageBox.information( self, "Resolution",
                                              "That resolution isn't supported by the camera. Instead, your actual resolution is: %d x %d" % (self.actualRes[0], self.actualRes[1] ) )
            res = "%d x %d" % (int(self.actualRes[0]), int(self.actualRes[1]) )
            index = self.ui.comboBox.findText(res)
            self.ui.comboBox.setCurrentIndex(index)


    def save( self ):
        c = os.path.dirname(os.getcwd())
        cc = os.path.dirname(c)
        f = open( ("%s/config.txt" % cc) , "w")
        f.write('%d|%d|%s|%s\n' % ( self.actualRes[0], self.actualRes[1], self.ui.widthLine.text(), self.ui.sourceCombo.currentText() ))
        f.close()
        
         
        

    def setMultFactor ( self, value ):
        self.multFactor = value
        self.ui.scaling.setText( 'Step scaling is %d' % value)
    
    def setAble( self, group, ability ):
        groups = { 'motors' : [self.ui.buttonLeft, 
                               self.ui.buttonRight,
                               self.ui.buttonUp, 
                               self.ui.buttonDown, 
                               self.ui.scalingSlider, 
                               self.ui.scaling],
                  'center' : [self.ui.buttonCenter], 
                  'reset' : [self.ui.buttonReset],
                  
                  'settings': [self.ui.resDesc,
                               self.ui.framewDesc,
                               self.ui.buttonSet, 
                               self.ui.widthLine,
                               self.ui.comboBox],
                  'save': [self.ui.buttonSave]
                  }
        
        for g in groups[group]:
            g.setEnabled(ability)

            



    def motors( self, direction):
        xdir = 1
        ydir = 1 #comp up is down
        t = 300

        dir ={ 'left': (t, xdir * self.multFactor * (-1), 0 ) ,
              'right': ( t, xdir * self.multFactor * (1), 0 ),
              'up': (t, 0, ydir * self.multFactor * (1) ),
              'down': (t, 0, ydir * self.multFactor * (-1) )
              }

        #print dir[direction]
        th = threading.Thread(target  = self.ebb.move , args = dir[direction] )
        try:
            #partial(self.ebb.move, dir[direction]) 
            th.start()
            #th.join()
        except Exception as e:
            logger.exception( str(e) )


    def reset ( self ):
        
        self.ebb.move(300, -self.colSteps, -self.rowSteps)
        if self.ebb.connected:
            self.ebb.closeSerial()
        self.setAble('motors', False)
        self.setAble('settings', True)

    def center ( self ):
        #th = threading.Thread(target  = self.ebb.move , args = (100,200,300) )
        try:
            #partial(self.ebb.move, dir[direction]) 
            self.colSteps, self.rowSteps = self.ebb.centerWorm(300,200,300)
            #th.join()
        except Exception as e:
            logger.exception( str(e) )

        
        self.setAble('reset', True)
        self.setAble('save', True)
        

    def set( self ):
        if self.ui.widthLine.text():
            try:
                float( self.ui.widthLine.text() )
            except ValueError as e:
                QtWidgets.QMessageBox.information( self, "Invalid Width", "Cannot convert that width to a float! Make sure you enter a number (decimals accepted)")
                return
       
        if self.ui.widthLine.text() and self.ui.comboBox.currentText():
            self.resolutionSelect()
            # Instantiate motors    
            try:
                self.ebb = EasyEBB( resolution = self.actualRes, sizeMM = float(self.ui.widthLine.text() ) )
                  

                self.setAble('settings', False)
                self.setAble('motors', True)
                self.setAble('center', True)
            except serial.SerialException as e:
                logger.exception(e)
                QtWidgets.QMessageBox.information( self, "Motors Issue",
                                                "Please connect motors or restart them, having issues connecting now")
        else:
            QtWidgets.QMessageBox.information( self, "Validation",
                                                  "Please enter a measurement for the width and double-check your resolution choice") 

        

    def closeEvent ( self, event):
        logger.debug("closing")
        if self._cap._capture.isOpened():
            self._cap._capture.release()
        #if self._cap:
        #    cv2.destroyWindow("Camera Display")
        #    cv2.destroyAllWindows()
        if self.ebb:
            self.ebb.closeSerial()
    
    def isColor( self, imgIn ):
        s = np.shape(imgIn)
        if  np.size(s) == 3:
            try:
                ncolor = np.shape(imgIn)[2]
                boolt = int(ncolor) > 2
                return boolt
            except IndexError:
                QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                logger.error("Something wrong with camera input")
                self.showImage = False
        else:
            return False
         
        
    def play( self ):
        if self.showImage:
            self._cap.enterFrame()
            self.currentFrame = self._cap.frame
        
            self.color = self.isColor(self.currentFrame)
            t1 = time.time()
            if self.color:
                try:
                    self.currentFrame = cv2.cvtColor(self.currentFrame, cv2.COLOR_BGR2GRAY)
                    if self.currentFrame is not None:
                        self.currentFrame = self.p.draw(self.currentFrame, 'black-1')
                        self.currentFrame = self.c.draw(self.currentFrame, 'black-1')
                   
                        self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                        self.ui.videoFrame.setScaledContents(True)
                    else:
                        QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                        logger.error("Something wrong with camera input")
                
                    #cv2.imshow( "Camera Display",self.currentFrame)
                except TypeError:
                    logger.exception("No Frame")
                    QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")

                finally:
                    self._cap.exitFrame()
            else:
                try:
                    if self.currentFrame is not None:
                        self.currentFrame = self.p.draw(self.currentFrame, 'black-1')
                        self.currentFrame = self.c.draw(self.currentFrame, 'black-1')
                        self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                        self.ui.videoFrame.setScaledContents(True)
                    else:
                        QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                        logger.error("Something wrong with camera input")
                        logger.exception("No Frame")
                        self.showImage = False

                        #cv2.imshow( "Camera Display",self.currentFrame)
                except TypeError:
                    logger.exception("No Frame")
                finally:
                    self._cap.exitFrame()

            self._cap.exitFrame()
Пример #29
0
def expedition_select_map_2():
    random_click(Point(178, 422), Point(216, 450))
Пример #30
0
def set_foremost():
    print("set_foremost")
    point = random_point(Point(500, 10), Point(500, 10))
    point.click()
    random_sleep(0.4)
Пример #31
0
def expedition_select_map_4():
    random_click(Point(290, 422), Point(326, 450))
Пример #32
0
    def Position(self,pos,scale,colour = None,ignore_height = False):
        """Draw the text at the given location and size. Maybe colour too"""
        #set up the position for the characters. Note that we do everything here in size relative
        #to our text box (so (0,0) is bottom_left, (1,1) is top_right. 
        self.pos = pos
        self.absolute.bottom_left = self.GetAbsoluteInParent(pos)
        self.scale = scale
        self.lowest_y = 0
        row_height = (float(self.text_manager.font_height*self.scale*texture.global_scale)/self.absolute.size.y)
        #Do this without any kerning or padding for now, and see what it looks like
        cursor = Point(self.margin.x,-self.viewpos + 1 - row_height-self.margin.y)
        letter_sizes = [Point(float(quad.width *self.scale*texture.global_scale)/self.absolute.size.x,
                              float(quad.height*self.scale*texture.global_scale)/self.absolute.size.y) for quad in self.quads]
        #for (i,(quad,letter_size)) in enumerate(zip(self.quads,letter_sizes)):
        i = 0
        while i < len(self.quads):
            quad,letter_size = self.quads[i],letter_sizes[i]
            if cursor.x + letter_size.x > (1-self.margin.x)*1.001:
                #This would take us over a line. If we're in the middle of a word, we need to go back to the start of the 
                #word and start the new line there
                restart = False
                if quad.letter in ' \t':
                    #It's whitespace, so ok to start a new line, but do it after the whitespace
                    try:
                        while self.quads[i].letter in ' \t':
                            i += 1
                    except IndexError:
                        break
                    restart = True
                else:
                    #look for the start of the word
                    while i >= 0 and self.quads[i].letter not in ' \t':
                        i -= 1
                    if i <= 0:
                        #This single word is too big for the line. Shit, er, lets just bail
                        break
                    #skip the space
                    i += 1
                    restart = True
                        
                cursor.x = self.margin.x
                cursor.y -= row_height
                if restart:
                    continue
            
            if cursor.x == self.margin.x and self.alignment == texture.TextAlignments.CENTRE:
                #If we're at the start of a row, and we're trying to centre the text, then check to see how full this row is
                #and if it's not full, offset so that it becomes centred
                width = 0
                for size in letter_sizes[i:]:
                    width += size.x
                    if width > 1-self.margin.x:
                        width -= size.x
                        break
                if width > 0:
                    cursor.x += float(1-(self.margin.x*2)-width)/2

            target_bl = cursor
            target_tr = target_bl + letter_size
            if target_bl.y < self.lowest_y:
                self.lowest_y = target_bl.y
            if target_bl.y < 0 and not ignore_height:
                #We've gone too far, no more room to write!
                break
            absolute_bl = self.GetAbsolute(target_bl)
            absolute_tr = self.GetAbsolute(target_tr)
            self.SetLetterVertices(i,absolute_bl,
                                   absolute_tr,
                                   texture.TextTypes.LEVELS[self.text_type])
            if colour:
                quad.SetColour(colour)
            cursor.x += letter_size.x
            i += 1
        #For the quads that we're not using right now, set them to display nothing
        for quad in self.quads[i:]:
            quad.SetVertices(Point(0,0),Point(0,0),-10)
        height = max([q.height for q in self.quads])
        super(TextBox,self).UpdatePosition()
Пример #33
0
def combat_formation_combined_ring():
    print("combat_formation_combined_ring")
    random_click(Point(435, 324-22), Point(563, 345-22))
Пример #34
0
def sortie_select_area_4():
    point = random_point(Point(355, 425), Point(390, 448))
    point.click()
Пример #35
0
def sortie_select_map_1():
    point = random_point(Point(139, 171-22), Point(421, 277-22))
    point.click()
Пример #36
0
def sortie_select_map_3():
    point = random_point(Point(138, 311-22), Point(425, 423-22))
    point.click()
Пример #37
0
def sortie_select_map_2():
    point = random_point(Point(464, 163-22), Point(659, 282-22))
    point.click()
Пример #38
0
def combat_button_left():
    point = random_point(Point(257, 247-22), Point(327, 289-22))
    point.click()
Пример #39
0
 def __init__(self, x, y):
     Point.__init__(self, x, y)
     self.edges = set([])
     self.triangles = set([])
Пример #40
0
def combat_button_right():
    point = random_point(Point(473, 238-22), Point(551, 289-22))
    point.click()
Пример #41
0
def combat_formation_combined_battle():
    print("combat_formation_combined_battle")
    random_click(Point(602, 324-22), Point(728, 345-22))
Пример #42
0
def sortie_select_map_5():
    point = random_point(Point(682, 236-22), Point(777, 290-22))
    point.click()
    random_sleep(1)
    point.click()
Пример #43
0
    def PathTo(self,start,end):
        #A noddy my-first implementation of A* in python
        #update the map items with current positions of the sprites
        #they're not used normally so we can do what we like with them
        try:
            return self.pathcache[start,end]
        except KeyError:
            #oh well, it was worth a try
            pass
        if start == None or end == None:
            return None
        
        cell = self.GetCell(end)
        if cell == None:
            return None
        if cell.Impassable():
            #if we can't move into the last tile, there's no point
            return None
        if start == end:
            return None

        Closed = set()
        #open is sorted by 'F' value
        Open   = [start]
        Opend  = {start:start}
        start.g = 0
        start.h = start.DistanceHeuristic(end)
        start.f = start.h
        start.parent = None
        #get the object we're going from so we can ignore it in terms of being passable
        start_object = self.map[start.x][start.y].GetActor()
        end_object   = self.map[end.x][end.y].GetActor()
        while True:
            if len(Open) == 0: #no path, boo
                return None
            current = Open.pop(0)
            del Opend[current]
            if current == end:# or len(Open) > 100:
                #yay, we're finished
                path = utils.Path(current,self.tex_coords,len(self.map))
                self.pathcache[start,end] = path
                #self.pathcache[end,start] = path.Reversed()
                return path
            elif current != start:
                #FIXME: put the path in the other way
                p = start,current
                path = utils.Path(current,self.tex_coords,len(self.map))
                if (p in self.pathcache and path.cost < self.pathcache[p]) or p not in self.pathcache:
                    self.pathcache[p] = path
            #        self.pathcache[current,start] = path.Reversed()
            #elif (current,end) in self.pathcache:
                #FIXME: handle this case
            #    print 'jim'
                
                
            Closed.add(current)
            for x in xrange(current.x-1,current.x+2):
                x %= len(self.map)
                for y in xrange(current.y-1,current.y+2):
                    if y < 0 or y >= len(self.map[x]):
                        continue

                    target = Point(x,y)
                    
                    if target in Closed:
                        continue
                    if target == current:
                        continue

                    cost = 0
                    for tile in (target,):
                        cell = self.map[tile.x][tile.y]
                        this_cost = cell.MovementCost(ignore = (start_object,end_object))
                        if this_cost == TileData.IMPASSABLE:
                            cost = this_cost
                            break
                        cost += this_cost

                    if cost == TileData.IMPASSABLE:
                        if target == end:
                            return None
                        continue

                    #if target != current.x and target.y != current.y:
                        #it's diagonal. It still costs the same, but pretend
                        #otherwise so that h/v movement is preferred as it looks
                        #nicer
                    #    cost *= 1.41

                    newg = current.g + cost
                    try:
                        target_new = Opend[target]
                    except KeyError:
                        target_new = None
                    
                    if target_new == None:
                        target.g    = newg
                        #Open is sorted by g+h, so find the position this goes with a binary search
                        #and put it in the right place

                        target.h = target.DistanceHeuristic(end)
                        target.f = target.g + target.h
                        target.parent = current
                        i = utils.fbisect_left(Open,target)

                        Open.insert(i,target)
                        Opend[target] = target
                    else: #target's already in open
                        target = target_new
                        if newg < target.g:
                            target.g = newg
                            target.f = target.g + target.h
                            target.parent = current
Пример #44
0
def combat_button_retreat_flagship_damaged():
    point = random_point(Point(535, 220), Point(605, 260))
    point.click()