-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeUcs.py
63 lines (58 loc) · 1.58 KB
/
NodeUcs.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
import numpy as numpy
class NodeUcs :
def __init__(self,data,parent,weight):
self.data = data
self.parent = parent
self.weight = weight
def getWeight (Node):
return Node.weight
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