Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

class Node(object): 

 

def __init__(self, graph, move, parent): 

""" 

Initialize AStarNode class 

 

@type graph: Map 

@param graph: Map that moves can be made on  

@type move: Move 

@param move: Move that resulted in the above graph 

@type parent: Node 

@param parent: Parent node of this. Contains previous moves to get 

the current board. 

""" 

self.graph = graph 

self.move = move 

self.parent = parent 

 

def reconstructPath(self): 

""" 

Construct the path from here that it took to make it here. 

 

@rtype: [Move] 

@return: array of moves to get to this point from the root node 

""" 

# initialize variables 

parent = self 

path = [self.move] 

 

# loop through parents 

while parent != None: 

if parent.move != None: 

path.append(parent.move) 

 

parent = parent.parent 

 

# reverse list and return result. Remove the first as it will be None 

return list(reversed(path[1:]))