コード例 #1
0
ファイル: main_window.py プロジェクト: maxnchloebff/Five_star
 def pressed_but_not_select(self, x, y):
     """
     Slot function to receive the pressed_but_nonselect signal
     if a Mylabel cinstance is clicked and also it's blank then
     get into this function
     This function implement these things:
     1.Before clicking this cell, if you have already clicked(selected) a
     colored cell, then this function detect whether there is a valid
     path from the selected loc (self.selected_loc) to this loc(x,y).
     If success then move the colored cell to this loc and then set the
     previous selected_loc to blank(valid), else only set the previous
     selected_loc to valid(only view this action as canceling the seleted cell)
     2. If there is no cell seleted before do nothing
     :param x:  Mylabel x coordinate
     :param y:  Mylabel y coordinate
     :return:
     """
     print('received pressed_but_not_select signal')
     if self.selected_loc is not None:
         astar = AStar()
         converted_map = self.map.get_valid_map() * 10
         converted_map = converted_map.astype(np.float)
         is_success = astar.main(converted_map,
                                 start_loc=self.selected_loc,
                                 end_loc=np.array([x, y]))
         if is_success:
             astar.path_backtrace()
             path = astar.best_path_array
             path = path[:, ::-1]
             self.just_start = False
             self.map.flash_starttoend(path)
             self.grade += self.map.judge_five([x, y])
             # self.cancel_selected()
             self.selected_loc = None
             self.grade += self.map.rand_gen(self.gen_num)
             if self.map.get_valid_num() == 0:
                 self.grade_label.setText('你的分数是: ' + str(self.grade) +
                                          ' 游戏结束')
                 self.GameEndSignal.emit(self.grade)
             else:
                 self.grade_label.setText('你的当前分数是: ' + str(self.grade))
         else:
             self.cancel_selected()
コード例 #2
0
ファイル: robot.py プロジェクト: nicogonza/robo_guide
def map_callback(msg):
		# start = [3,3]
		# goal = [8,6]
		# global robot
		# print msg.info
		# cells = []
		# i=0
		# tmp=[]
		# # rows = msg.info.height
		# rows = 26
		# # cols = msg.info.width
		# cols = 27
		# for row in range(0,rows):
		# 	for col in range (0,cols):
		# 		data= msg.data[i]
		# 		if data == -1 or data == 100:
		# 			wall = True
		# 		else:
		# 			wall = False
		# 		cell = Cell([row,col],wall)
		# 		cells.append(cell)
		# 		i+=1
		# print "done building 2d grid"
		# a = AStar(cells)
		# a.init_world(start,goal,rows,cols)
		# print len(a.cells)
		# print len(msg.data)
		# directions = a.main()
		# print directions

		start = [77, 33]
		goal = [111, 57]
		cells = []
		tmp = []
		# rows = msg.info.height
		cells = []
		cols = 0
		with open('robo_map.txt') as file:
			reader = csv.reader(file, delimiter=' ')
			rows = 0;
			for line in reader:
				if len(line) > cols:
					cols = len(line)
				for col in range(len(line)):
					data = int(line[col])
					if data == -1 or data == 1:
						wall = True
					else:
						wall = False
					cell = Cell([rows, col], wall)
					cells.append(cell)

				rows += 1
		rows -= 1

		print(rows, cols)
		print
		"done building 2d grid"
		print
		time.localtime(time.time()), "started finding path"
		a = AStar(cells)
		a.init_world(start, goal, rows, cols)
		directions = []
		if a.init:
			directions = a.main()
		print(directions)