Skip to content

Commit

Permalink
style: beautify Python code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 11, 2020
1 parent ebdeb8a commit 184889a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions pathfinder/server/dijkstra.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from heapdict import heapdict

from pathfinder.server.node import Node
from pathfinder.motion import motions
from pathfinder.server.node import Node


class Dijkstra:
Expand Down Expand Up @@ -50,8 +50,9 @@ def find_path(self, client_connection):
if node.key in self._closed_nodes:
continue

new_distance = (current_distance +
current_node.motion_weight(node.came_by_motion))
new_distance = current_distance + current_node.motion_weight(
node.came_by_motion
)
if (
node.key not in self._open_nodes
or new_distance < self._open_queue[node.key]
Expand Down
12 changes: 6 additions & 6 deletions pathfinder/server/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def __init__(self, dijkstra, view, came_by_motion):
def get_neighbours(self):
"""Yield all neighbours of this node."""
for motion, view in child_views(
self.view, self.dijkstra.available_motions,
self.dijkstra.min_line, self.dijkstra.max_line
self.view,
self.dijkstra.available_motions,
self.dijkstra.min_line,
self.dijkstra.max_line,
):
yield Node(self.dijkstra, view, motion)

Expand All @@ -35,9 +37,8 @@ def motion_weight(self, motion):
# Difference in length of current and future count
# 2j -> 3j = 0
# 9j -> 10j = 1
return (
len(str(self.came_by_motion_repetitions + 1)) -
len(str(self.came_by_motion_repetitions))
return len(str(self.came_by_motion_repetitions + 1)) - len(
str(self.came_by_motion_repetitions)
)

def set_came_from(self, node):
Expand All @@ -60,4 +61,3 @@ def reconstruct_path(self):
motions.insert(0, node.came_by_motion)
node = node.came_from
return motions

4 changes: 3 additions & 1 deletion pathfinder/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def do_action(self, data):

def pathfind(self):
"""Run the pathfinder, then send the result back to the client."""
dijkstra = Dijkstra(self.start_view, self.target_view, self.min_line, self.max_line)
dijkstra = Dijkstra(
self.start_view, self.target_view, self.min_line, self.max_line
)
motions = dijkstra.find_path(self.client_connection)

# If motions is None, that means we cancelled pathfinding because a new
Expand Down

0 comments on commit 184889a

Please sign in to comment.