added class constants.py with class Constants

and bfs.py with class Node
This commit is contained in:
michalnowak18 2022-04-03 18:35:24 +02:00
parent 888e555c09
commit b94c1bf5ad
2 changed files with 75 additions and 0 deletions

11
src/constants.py Normal file
View File

@ -0,0 +1,11 @@
class Constants:
""" Class to represent all constants for the app """
def __init__(self):
self.move = "move"
self.up = "up"
self.down = "down"
self.right = "right"
self.left = "left"
self.rotate_right = "rotate_right"
self.rotate_left = "rotate_left"

64
src/utils/bfs.py Normal file
View File

@ -0,0 +1,64 @@
from constants import Constants as c
class Node:
def __init__(self, current_x, current_y, agent_direction, action=None, parent=None):
self.current_x = current_x
self.current_y = current_y
self.action = action
self.parent = parent
self.agent_direction = agent_direction
def successor(self):
x = self.current_x
y = self.current_y
neighbours = []
if x < 9: # right neighbour
if self.agent_direction == c.right:
actions = c.move
elif self.agent_direction == c.left:
actions = [c.rotate_right, c.rotate_right, c.move]
elif self.agent_direction == c.up:
actions = [c.rotate_right, c.move]
elif self.agent_direction == c.down:
actions = [c.rotate_left, c.move]
neighbours.append((actions, (x + 1, y), c.right))
if x > 0: # left neighbour
if self.agent_direction == c.right:
actions = [c.rotate_left, c.rotate_left, c.move]
elif self.agent_direction == c.left:
actions = c.move
elif self.agent_direction == c.up:
actions = [c.rotate_left, c.move]
elif self.agent_direction == c.down:
actions = [c.rotate_right, c.move]
neighbours.append((actions, (x - 1, y), c.left))
if y > 0: # upper neighbour
if self.agent_direction == c.right:
actions = [c.rotate_left, c.move]
elif self.agent_direction == c.left:
actions = [c.rotate_right, c.move]
elif self.agent_direction == c.up:
actions = c.move
elif self.agent_direction == c.down:
actions = [c.rotate_left, c.rotate_left, c.move]
neighbours.append((actions, (x, y - 1), c.up))
if y < 9: # down neighbour
if self.agent_direction == c.right:
actions = [c.rotate_right, c.move]
elif self.agent_direction == c.left:
actions = [c.rotate_left, c.move]
elif self.agent_direction == c.up:
actions = [c.rotate_left, c.rotate_left, c.move]
elif self.agent_direction == c.down:
actions = c.move
neighbours.append((actions, (x, y + 1), c.down))
return neighbours