-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (69 loc) · 3.33 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
from tkinter import Tk, Canvas, Frame, BOTH
from src.mars_plateau_UI import Grid_Window
from src.plateau import Plateau
from src.position import Position
from src.rover import Rover
from src.parser_input import parse_input_model_file
import logging
import sys
import os
sys.path.append(os.path.realpath('.'))
logging.basicConfig(filename='marsRovers.log',
level=logging.INFO, format='%(asctime)s %(message)s')
logging.info('Mars rover start')
if (len(sys.argv) is 1):
print ("****************************************************************************************")
print (" Mars Rovers Problem ")
print ("**********************************************************************")
print (" Running the app ")
print ()
print ("To start the app please run main.py from the root project folder using the following ")
print ("flags: ")
print ()
print ("1st FLAG (required) '-f inputFileName' => To provide the input ")
print (" Example ../somelocalpath/MarsRovers/$ python3 main-py -f ./src/inputs/input_example_ok ")
print ()
print ("2nd FLAG (optional) '-g' => If you want to display the GUI")
print (" Example ../somelocalpath/MarsRovers/$ python3 main-py -f ./src/inputs/input_example_ok -g")
print ()
print ("*******************************************************************0*********************")
print ()
print ("After running it, you can analyze the rovers movements in the plateau by looking at ")
print (" the file 'marsRovers.log'. ")
print ()
print ("*****************************************************************************************")
logging.info("Running without flags!")
elif (len(sys.argv) is 3):
if sys.argv[1] == '-f':
try:
logging.info("Running without UI!")
mars = parse_input_model_file(sys.argv[2])
print('The Inicial Position')
mars.print_position_rovers()
mars.run()
print("The Final Position")
mars.print_position_rovers()
except Exception:
logging.info("The Plateau can't be created! Check the input.")
print("Im sorry! something's wrong. Check the input")
elif (len(sys.argv) is 4):
if sys.argv[1] == '-f' and sys.argv[3] == '-g':
logging.info("Running with UI!")
try:
mars = parse_input_model_file(sys.argv[2])
raiz = Tk()
raiz.resizable(True, False)
raiz.title('Rovers in Mars Plateau')
myapp = Grid_Window(raiz)
myapp.draw_grid(mars.width+1, mars.height+1)
for rover in mars.rovers:
myapp.draw_rover(rover.position.x, rover.position.y, mars.height+1,
rover.id_number, rover.position.cardinal, 'Inicial')
mars.run()
for rover in mars.rovers:
myapp.draw_rover(rover.position.x, rover.position.y, mars.height+1,
rover.id_number, rover.position.cardinal, 'Final')
raiz.mainloop()
except Exception:
logging.info("The Plateau can't be created! Check the input.")
print("Im sorry! something's wrong. Check the input")