This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
forked from mauriciopereira74/Vector-Race
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readFile.py
110 lines (94 loc) · 3.3 KB
/
readFile.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
# from color import style
class readFile:
# global file
# fileOpen = open("circuito.txt", "rt")
# file = fileOpen.readlines()
# fileOpen.close()
#
# global circuito
# circuito = []
# for sub in file:
# circuito.append(sub.replace("\n", ""))
def __init__(self, x):
self.circuito_path = x
global file
global circuito
circuito = []
if self.circuito_path == "":
fileOpen = open(f"Circuitos/circuito0.txt", "rt")
else:
fileOpen = open(f"Circuitos/{self.circuito_path}", "rt")
file = fileOpen.readlines()
fileOpen.close()
for sub in file:
circuito.append(sub.replace("\n", ""))
# Função que lê um ficheiro coloca toda a sua informação numa Lista de Strings
def ler(self):
return circuito
# Determina a CoordenadaX e Y da Posição Inicial
def PInicialXY2(self):
pontos = []
for i in range(len(circuito)):
for j in range(len(circuito[i])):
if circuito[i][j] == "P":
pontos.append(f"({i},{j})")
if len(pontos) == 1:
pontos.append(None)
return pontos
# Determina a CoordenadaX e Y da Posição Inicial
def PInicialXY(self):
for i in range(len(circuito)):
for j in range(len(circuito[i])):
if circuito[i][j] == "P":
return f"({i},{j})"
# Determina a CoordenadaX e Y da Posição Final
def PFinalXY(self):
for i in range(len(circuito)):
for j in range(len(circuito[i])):
if circuito[i][j] == "F":
return f"({i},{j})"
def PCheckXY(self):
for i in range(len(circuito)):
for j in range(len(circuito[i])):
if circuito[i][j] == "C":
return f"({i},{j})"
return None
def demonstra(self):
res = "\n "
i=0
nestedCircuito = []
for lin in circuito:
nestedCircuito.append([c for c in lin])
while i < len(nestedCircuito[0]):
if len(str(i)) == 2: res += "" + f"{i}" + " "
else: res += " " + f"{i}" + " "
i+=1
res += "\n" + "-"*len(res) + "\n"
i=0
for x in nestedCircuito:
if len(str(i)) == 2: res += f"{i}" + "| "
else: res += f"{i}" + " | "
for y in x:
if len(str(y)) == 2: res += "" + f"{y}" + " "
else: res += " " + f"{y}" + " "
res = res + "\n"
i+=1
res = res + "\n"
return res
# x = 'X'
# z = '-'
# p = 'P'
# f = 'F'
# string = ""
# for i in range(len(circuito)):
# string = string + ("\n")
# for j in range(len(circuito[i])):
# if (circuito[i][j] == x):
# string = string + "X"
# if (circuito[i][j] == z):
# string = string + "-"
# if (circuito[i][j] == p):
# string = string + "P"
# if (circuito[i][j] == f):
# string = string + "F"
# return string