-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.py
45 lines (39 loc) · 1.24 KB
/
Helper.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
import pygame
def cut_subsurface(image_link, size_x, size_y):
image = pygame.image.load(image_link)
frame_num = int(image.get_width() / size_x)
frames = []
for i in range(frame_num):
frames.append(image.subsurface(i * size_x, 0, size_x, size_y))
return frames
def readFile(file):
f = open(file, 'r')
mes = f.read()
row_num = mes.split('\n')
board = []
for i in row_num:
row = i.split(' ')
board.append(row)
for r in range(len(board)):
for c in range(len(board[r])):
board[r][c] = int(board[r][c])
return board
def print_map(map):
for r in range(len(map)):
row = ""
for c in range(len(map[r])):
row += ("" + str(map[r][c]))
print(row)
print("" * len(map[0]))
def print_best_move_map(shortest_path_tree, map):
board = [["A" for c in range(len(map[r]))] for r in range(len(map))]
for tile in shortest_path_tree:
board[tile[1]][tile[0]] = shortest_path_tree[tile]
for r in range(len(board)):
row = ""
for c in range(len(board[r])):
length = len(str(board[r][c]))
row += (5-length) * " " + str(board[r][c])
row += " "
print(row)
print("*" * len(board))