#! heuristic = 0]: self.item = itemself . . . self, node]: x, y = node.itemreturn0#-*-mã hóa: utf-8-*-# intert = 0, heuristic = 0]: self.item = itemself.parent = pargeforelf.gscore = gscoreself.heuristic = heuristicdef__eq __ [tự, khác] .heuristicNode.gscore: left = bisect.b isect_left [hàng đợi, trùng lặp] phải = bisect.bisect_right [hàng đợi, trùng lặp] Queue.pop [Queue.index [trùng lặp, trái, phải]] nodeBisect.insort_left [hàng đợi, nút] returnPathClassd2 [astarpathfinding]: def__init __ [self, ma trận, hàng, cols]: self.matrix = matrixelf. .Itemx2, y2 = des.itemreturnabs [x1-x2] +abs [y1-y2] refgetchildren [self, node]: x, y = node.itemreturn [self.node [[x +1, y] , gscore = node.gscore+1], self.node [[x-1, y], Parent = node, gscore = node.gscore+1], self.node [[x, y+1], Parent = node , gscore = node.gscore+1], self.node [[x, y-1], Parent = node, gscore = node.gscore+1],] defavailable [self, node]: x, y = node.itemreturn0 # -*- coding: utf-8 -*- # import bisect class AStarPathfinding[object]: class Node[object]: # item must be hashable def __init__[self, item, parent=None, gscore=0, heuristic=0]: self.item = item self.parent = parent self.gscore = gscore self.heuristic = heuristic def __eq__[self, other]: return other.item == self.item def __lt__[self, other]: return self.gscore + self.heuristic node.gscore: left = bisect.bisect_left[queue, duplicated] right = bisect.bisect_right[queue, duplicated] queue.pop[queue.index[duplicated, left, right]] node.heuristic = self.heuristic[node, target] openpath[node.item] = node bisect.insort_left[queue, node] return path class D2[AStarPathfinding]: def __init__[self, matrix, rows, cols]: self.matrix = matrix self.rows = rows self.cols = cols def heuristic[self, src, des]: x1, y1 = src.item x2, y2 = des.item return abs[x1 - x2] + abs[y1 - y2] def getchildren[self, node]: x, y = node.item return [ self.Node[[x + 1, y], parent=node, gscore=node.gscore + 1], self.Node[[x - 1, y], parent=node, gscore=node.gscore + 1], self.Node[[x, y + 1], parent=node, gscore=node.gscore + 1], self.Node[[x, y - 1], parent=node, gscore=node.gscore + 1], ] def available[self, node]: x, y = node.item return 0
Hướng dẫn a-star python - trăn một ngôi sao
Bài Viết Liên Quan
Toplist mới
#2
#3
#4
Top 6 thử thách thần chết thuyết minh phần 2 2023
5 tháng trước#5
#6
Top 5 áo khoác nam quảng châu cao cấp 2023
5 tháng trước#8
Top 9 mẫu đồng phục công sở đẹp 2022 2023
5 tháng trước#9
Top 5 ốp lưng iphone 13 pro bảo vệ camera 2023
5 tháng trướcBài mới nhất
Chủ Đề
programming
Hỏi Đáp
Là gì
Mẹo Hay
Toplist
Địa Điểm Hay
Học Tốt
mẹo hay
Công Nghệ
Nghĩa của từ
Bao nhiêu
Khỏe Đẹp
đánh giá
Tiếng anh
Top List
bao nhieu
bao nhiêu
hướng dẫn
Món Ngon
So Sánh
So sánh
Bài tập
Xây Đựng
Sản phẩm tốt
Ngôn ngữ
Bài Tập
javascript
Ở đâu
Thế nào
Hướng dẫn
Dịch
Tại sao
Máy tính
Đại học