My ultimate goal with this program I'm making is to use the A Star algorithm to let a robot find its goal in the grid. I'm not at the A star stage quite yet and I'm trying to figure out how to move the robot, but I'm not sure how to move the robot from it's current position to its next position (north, south, east, west).
Note: I have not taken into consideration the grid boundaries or walls when moving quite yet. If anyone has a good idea on how I could tackle that, feel free to share your knowledge.
Also, I can't seem to print out my grid, I don't use python often and I'm not entirely sure how to print out the grid. How would I print out the grid with certain characters representing a robot, walls, traps or paths?
Thanks in advance.
class robot:
def __init__ (self, name, grid, position):
self.name = name
self.position = position
self.grid = grid
def robot_position(position):
position = (x,y)
return robot.position
def robot_neighbours(self, position):
position = (x,y)
results = [(x+1, y), (x, y-1), (x-1, y), (x, y+1)]
return results
def move_north():
north = (x,y+1)
robot.robot_position = north
return robot.robot_position
class game_board:
def boundary(self, point): #defines the grids boundaries
point = (x,y)
return 0 <= x < self.width and 0 <=y < self.height
def node_neighbours(self, point): #defines the current nodes neighbours
point = (x,y)
results = [(x+1, y), (x, y-1), (x-1, y), (x, y+1)]
results = filter(self.grid_boundary, results) #filters out the boundary results
results = filter(self.can_pass_through, results) #filters out the coordinates that you can pass through from those you can't
return results
def can_pass_through(self, point):
return point not in self.walls
return point not in self.traps
#constructsthe2Dgrid
def __init__(self, width, height):
self.width = width
self.height = height
self.name = " . "
self.walls = []
self.traps = []
def build_grid(grid):
for x in range(grid.width):
for y in range (grid.height):
print(x, y)
return "grid created" + width + " " + height