Pylint disable no member error

This commit is contained in:
Maciej Sobkowiak 2019-04-15 12:54:29 +02:00
parent 56e4194cda
commit bc66661563
2 changed files with 19 additions and 14 deletions

View File

@ -1,8 +1,9 @@
import numpy
from heapq import *
from heapq import * # pylint: disable=unused-wildcard-import
def heuristic(a, b, pathing):
x = abs(a[0]-b[0])
y = abs(a[1]-b[1])
@ -15,21 +16,23 @@ def heuristic(a, b, pathing):
else:
return 10*(x + y)
def astar(array, start, goal, pathing):
if pathing == '+':
neighbors = [(0,1),(0,-1),(1,0),(-1,0)]
neighbors = [(0, 1), (0, -1), (1, 0), (-1, 0)]
else:
neighbors = [(0,1),(0,-1),(1,0),(-1,0),(1,1),(1,-1),(-1,1),(-1,-1)]
neighbors = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
neighbors = [(i, j)for i in range(-1, 2, 1) for j in range(2)]
came_from = {}
gscore = {start:0}
fscore = {start:heuristic(start, goal, pathing)}
gscore = {start: 0}
fscore = {start: heuristic(start, goal, pathing)}
oheap = []
checked = []
heappush(oheap, (fscore[start], start))
while oheap:
current = heappop(oheap)[1]
@ -45,8 +48,11 @@ def astar(array, start, goal, pathing):
array[current[0], current[1]] = 2
for i, j in neighbors:
neighbor = current[0] + i, current[1] + j
neighbor = current[0] + i, current[1] + j
tentative_g_score = gscore[current] + heuristic(current, neighbor, pathing)
if 0 <= neighbor[0] < array.shape[0]:
if 0 <= neighbor[1] < array.shape[1]:
if array.flat[array.shape[1] * neighbor[0]+neighbor[1]] == 1:
@ -57,14 +63,13 @@ def astar(array, start, goal, pathing):
else:
# array bound x walls
continue
if array[neighbor[0]][neighbor[1]] == 2 and tentative_g_score >= gscore.get(neighbor, 0):
continue
if tentative_g_score < gscore.get(neighbor, 0) or neighbor not in [i[1]for i in oheap]:
if tentative_g_score < gscore.get(neighbor, 0) or neighbor not in [i[1]for i in oheap]:
came_from[neighbor] = current
gscore[neighbor] = tentative_g_score
fscore[neighbor] = tentative_g_score + heuristic(neighbor, goal, pathing)
heappush(oheap, (fscore[neighbor], neighbor))
return False

View File

@ -4,7 +4,7 @@ from UI.grid import Grid, Node
class Window():
def __init__(self, grid: Grid):
pg.init()
pg.init() # pylint: disable=no-member
# setup window
pg.display.set_caption('Inteligentna śmieciarka')
@ -35,4 +35,4 @@ class Window():
self.grid.draw_node(self.screen, x - 1, y - 1)
self.grid.draw_node(self.screen, x, y)
pg.time.delay(500)
pg.quit()
pg.quit() # pylint: disable=no-member