-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeDisjoint.py
77 lines (70 loc) · 2 KB
/
NodeDisjoint.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
68
69
70
71
72
73
74
75
76
77
import numpy as numpy
class Node :
def __init__(self,data,parent,cost):
self.data = data
self.parent = parent
self.cost = cost
def getCost(self):
return (self.cost)
def moveUp(data):
notValue = True
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 :
if arr[zero_i - 1][zero_j] == -1:
notValue = False
arr[zero_i][zero_j] = arr[zero_i -1][zero_j]
arr[zero_i-1][zero_j] = 0
return [arr,notValue]
return [None]
def moveDown(data):
notValue = True
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 :
if arr[zero_i + 1][zero_j] == -1:
notValue = False
arr[zero_i][zero_j] = arr[zero_i + 1][zero_j]
arr[zero_i +1][zero_j] = 0
arr
return [arr,notValue]
return [None]
def moveRight(data):
notValue = True
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 :
if arr[zero_i][zero_j + 1] == -1:
notValue = False
arr[zero_i][zero_j] = arr[zero_i][zero_j +1]
arr[zero_i][zero_j + 1] = 0
return [arr,notValue]
return [None]
def moveLeft(data):
notValue = True
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 :
if arr[zero_i][zero_j - 1] == -1:
notValue = False
arr[zero_i][zero_j] = arr[zero_i][zero_j - 1]
arr[zero_i][zero_j - 1 ] = 0
return [arr,notValue]
return [None]