l1 = Flat((18, 13, 7))

gates = []

rows = csv.split("\n")
i = 0
for row in rows:
    # board1 gates: 3 - 29 // board2 gates: 3 - 54
    if i > 3 and i < 29:
        columns = row.split(",")
        gates.append(np.array(columns))
    i += 1
for gate in np.array(gates):
    l1.is_gate((int(gate[1]), int(gate[2]), 0), gate[0])

routes = []
j = 0
for row in rows:
    # board 1 : 1{31 - 62} // 2{64 - 105} // 3{107 - 158}
    # board 2 : 1{56 - 107} // 2{109 - 170} // 3{172 - 243}
    if j > 31 and j < 62:
        columns = row.split(",")
        routes.append(np.array(columns))
    j += 1

gate_1 = l1.find_gate(24)
gate_2 = l1.find_gate(5)

l1.find_route(gate_1, gate_2, '01')
print(l1)
j = 0
for row in rows:
    if j > 31 and j < 62:
        columns = row.split(",")
        routes.append(np.array(columns))
    j += 1

route_number = 1
failed_routes = 0
length = 0
for route in routes:
    if route_number < 31:
        route_num = ''
        if route_number < 10:
            route_num = '0'
        route_num += str(route_number)
        gate1 = l1.find_gate(int(route[0]))
        gate2 = l1.find_gate(int(route[1]))
        made_route = l1.find_route(gate1, gate2, route_num)
        if made_route is None:
            failed_routes += 1
        else:
            length += len(made_route)
    route_number += 1

print(l1)
print(failed_routes)
print(length)
f = open('output.txt', 'w')
print(l1, file=f)