-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
47 lines (41 loc) · 1.97 KB
/
board.py
File metadata and controls
47 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 17:20:56 2020
@author: nguye
"""
class Board:
def __init__(self):
self.obstacles = []
'''
Returns list of accessible neighbor nodes.
'''
def getNeighbors(self, Neighbor):
from node import Node
ret = []
i = Neighbor.x
j = Neighbor.y
if (i, j) in self.obstacles:
return
if i - 1 >= 0 and j >= 0 and j < 20 and (i - 1, j) not in self.obstacles:
ret.append(Node(i - 1, j, 0, 0))
if i >= 0 and i < 20 and j - 1 >= 0 and (i, j - 1) not in self.obstacles:
ret.append(Node(i, j - 1, 0, 0))
if i + 1 < 20 and j >= 0 and j < 20 and (i + 1, j) not in self.obstacles:
ret.append(Node(i + 1, j, 0, 0))
if i >= 0 and i < 20 and j + 1 < 20 and (i, j + 1) not in self.obstacles:
ret.append(Node(i, j + 1, 0, 0))
if i - 1 >= 0 and j - 1 >= 0 and (i - 1, j - 1) not in self.obstacles and ((i - 1, j) not in self.obstacles and (i, j - 1) not in self.obstacles):
ret.append(Node(i - 1, j - 1, 0, 0))
if i + 1 < 20 and j - 1 >= 0 and (i + 1, j - 1) not in self.obstacles and ((i + 1, j) not in self.obstacles and (i, j - 1) not in self.obstacles):
ret.append(Node(i + 1, j - 1, 0, 0))
if i - 1 >= 0 and j + 1 < 20 and (i - 1, j + 1) not in self.obstacles and ((i - 1, j) not in self.obstacles and (i, j + 1) not in self.obstacles):
ret.append(Node(i - 1, j + 1, 0, 0))
if i + 1 < 20 and j + 1 < 20 and (i + 1, j + 1) not in self.obstacles and ((i + 1, j) not in self.obstacles and (i, j + 1) not in self.obstacles):
ret.append(Node(i + 1, j + 1, 0, 0))
return ret
'''
Adds (x, y) coordinate pair to obstacles list
'''
def addObstacle(self, coord):
if (coord not in self.obstacles):
self.obstacles.append(coord)