-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.py
77 lines (75 loc) · 1.69 KB
/
move.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
# 1 up 2 down 3 left 4 right
# 012
# 345
# 678
#last bit is check if movement is proper 1 if not 0 decode it from other functions if there is deleted here
def main (state,movement):
while len(state)>9:
del state[-1]
board=list(state)
move(board,movement)
if state==board:
board.append(0)
return board
else:
board.append(movement)
return board
#
def move(board,movement):
for x in range(0,3):
#initiation
if movement==1:
a=board[x]
b=board[x+3]
c=board[x+6]
if movement==2:
c=board[x]
b=board[x+3]
a=board[x+6]
if movement==3:
a=board[3*x]
b=board[3*x+1]
c=board[3*x+2]
if movement==4:
c=board[3*x]
b=board[3*x+1]
a=board[3*x+2]
#shift
if a==0:
a=b
b=c
c=0
if a==0:
a=b
b=0
else:
if b==0:
b=c
c=0
#sum
if a!=0:
if a==b:
a=a+b
b=c
c=0
else:
if b==c:
b=b+c
c=0
#reverse initiation
if movement==1:
board[x]=a
board[x+3]=b
board[x+6]=c
if movement==2:
board[x]=c
board[x+3]=b
board[x+6]=a
if movement==3:
board[3*x]=a
board[3*x+1]=b
board[3*x+2]=c
if movement==4:
board[3*x]=c
board[3*x+1]=b
board[3*x+2]=a