-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeA.py
67 lines (61 loc) · 1.66 KB
/
NodeA.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as numpy
class NodeA :
def __init__(self,data,parent,gn,hn):
self.data = data
self.parent = parent
self.gn = gn
self.hn = hn
# def getFn(self):
# return (self.hn + self.gn)
def getFn(NodeA):
return (NodeA.hn + NodeA.gn)
def moveUp(data):
arr = numpy.copy(data)
for i in range(4) :
for j in range(4) :
if arr[i][j] == 0 :
zero_i = i
zero_j = j
break
if zero_i > 0 :
arr[zero_i][zero_j] = arr[zero_i -1][zero_j]
arr[zero_i-1][zero_j] = 0
return arr
return None
def moveDown(data):
arr = numpy.copy(data)
for i in range(4) :
for j in range(4) :
if arr[i][j] == 0 :
zero_i = i
zero_j = j
if zero_i < 3 :
arr[zero_i][zero_j] = arr[zero_i + 1][zero_j]
arr[zero_i +1][zero_j] = 0
arr
return arr
return None
def moveRight(data):
arr = numpy.copy(data)
for i in range(4) :
for j in range(4) :
if arr[i][j] == 0 :
zero_i = i
zero_j = j
if zero_j < 3 :
arr[zero_i][zero_j] = arr[zero_i][zero_j +1]
arr[zero_i][zero_j + 1] = 0
return arr
return None
def moveLeft(data):
arr = numpy.copy(data)
for i in range(4):
for j in range(4):
if arr[i][j] == 0:
zero_i = i
zero_j = j
if zero_j > 0 :
arr[zero_i][zero_j] = arr[zero_i][zero_j - 1]
arr[zero_i][zero_j - 1 ] = 0
return arr
return None