-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
146 lines (121 loc) · 4.2 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import numpy as np
import re
def print_board(board):
for row in board:
print("".join(row))
def move(player,move,board):
board_o = np.copy(board)
mr=np.array([0,0])
if "d" in move:
mr+=np.array([2,0])
if "u" in move:
mr += np.array([-2, 0])
if "r" in move :
mr += np.array([0, 2])
if "l" in move:
mr += np.array([0, -2])
if move[0] in "vh":
place_block=list(re.search(r'\d+', move).group())
if move[0]=="v":
right_place=int(place_block[0])*2+2,int(place_block[1])*2
board[right_place[0]:right_place[0]+3,right_place[1]] = "|"
if move[0]=="h":
right_place = int(place_block[0]) * 2 + 1, int(place_block[1]) * 2+1
board[right_place[0],right_place[1]:right_place[1]+3] = "-"
print("add block")
print(place_block)
if player in ("1","p1"):
p="1"
if move[0] in "vh":
solutions = np.argwhere(board[0] == "|")[-1]
board[0,solutions]=" "
elif player in ("2", "p2"):
p = "2"
if move[0] in "vh":
solutions = np.argwhere(board[-1] == "|")[-1]
board[-1,solutions]=" "
elif player in ("3", "p3"):
p = "3"
elif player in ("4", "p4"):
p = "4"
print("pawn move")
solutions = np.argwhere(board == p)[0]
board[solutions[0]][solutions[1]]=0
final_move=solutions+mr
check_move=solutions+mr/2
if board[int(check_move[0])][int(check_move[1])] in ("|","-"):
print("invalid move")
print_board(board_o)
return board_o
board[final_move[0]][final_move[1]]=p
#print(board)
print_board(board)
return board
def min_path_to_success(maze,player,start_pt):
''' Maze Properties'''
num_rows = int((len(maze)-1)/2)
num_cols = int((len(maze[0])-1)/2)
#end_pt = (num_cols -1 , 0)
#start_pt = (0, num_rows-1)
'''BFS'''
visited = {start_pt: None}
queue = [start_pt]
while queue:
#print(queue)
current = queue.pop(0)
if (player=="1" and current[1] == num_rows-1) or (player=="2" and current[1] == -1):
shortest_path = []
while current:
shortest_path.append(current)
current = visited[current]
return shortest_path
adj_points = []
'''FIND ADJACENT POINTS'''
current_col, current_row = current
#UP
if current_row > -1:
if maze[current_row*2+2 - 1,current_col*2+1] == " ":
adj_points.append((current_col, current_row - 1))
#RIGHT
if current_col < (int((len(maze[0])-1)/2)-1):
if maze[current_row*2+2,current_col*2+1 + 1] == " ":
adj_points.append((current_col + 1, current_row))
#DOWN
if current_row < (int((len(maze)-3)/2) - 1)+1:
if maze[current_row*2+2 + 1,current_col*2+1] == " ":
adj_points.append((current_col, current_row + 1))
#LEFT
if current_col > 0:
if maze[current_row*2+2,current_col*2+1 - 1] == " ":
adj_points.append((current_col - 1, current_row))
'''LOOP THROUGH ADJACENT PTS'''
for point in adj_points:
if point not in visited:
visited[point] = current
queue.append(point)
start_board = np.array([list("| | | | | | | | | |"),
list(" "),
list(" 0 0 0 0 1 0 0 0 0 "),
list(" "),
list(" 0 0 0 0 0 0 0 0 0 "),
list(" "),
list(" 0 0 0 0 0 0 0 0 0 "),
list(" "),
list(" 0 0 0 0 2 0 0 0 0 "),
list(" "),
list("| | | | | | | | | |")
]
)
start_board=move("1","h13",start_board)
start_board=move("2","h33",start_board)
start_board=move("1","d",start_board)
print(min_path_to_success(start_board,"1",(4,0)))
print(min_path_to_success(start_board,"2",(4,3)))
#move("1","h13",start_board)
#move("1","d",array)
n=5
n1,n2=0,1
for aa in range(n):
n1,n2=n2,n1+n2
print(n2)
FibArray = [0, 1]