I have a Python script that plays Airline Manager 2 (on Facebook) for me. So far it can depart flights and buy fuel when the price is good. I would like the program to also automatically plan maintenance for aircraft. The following code will only be run when a check is due (one of the four checks will have the value 0.)
When an A-Check is due (hours till A-Check == 0,) the A-Check must be performed. Same goes for other checks. The twist is this: B-Checks also cover A, C covers A & B, and a D-Check covers all other checks. If an A-Check is required, I would like a B-Check to be performed if the B would run out before the A is needed again. There is no point in doing a B-Check if 2 hours later a C-Check would need to be done. In that case I might as well just do a C-Check (which also covers the B-Check.)
Examples
- A-Check required; B-Check has 600 hours before another check is required; perform an A-Check.
- The above sentence can be written as
A,B,C,D=0,600,2000,10000
-> A-Check (C & D-Checks are set to their maximum values so they don't affect the result.) - A-Check required; B-Check has 200 hours left; perform a B-Check (because the B-Check would need to be done in another 200 hours anyway, so the A-Check would be covered now, then in another 200 hours with the B-Check, wasting 300 hours of A-Check.)
- The above sentence can be written as
A,B,C,D=0,200,2000,10000
-> B-Check (C & D-Checks are set to their maximum values so they don't affect the result.) A,B,C,D=200,0,1300,9500
-> B-Check, which also covers the A-CheckA,B,C,D=200,0,700,9500
-> C-Check, because the C-Check would need to be done before the next B-Check (if a B-Check was performed.)
Rules
- A-Checks should be performed every 500 hours
- B-Checks should be performed every 1,000 hours and also covers A-Checks
- C-Checks should be performed every 2,000 hours and also covers both A-Checks and B-Checks
- D-Checks should be performed every 10,000 hours and covers all other checks as well
The code I have currently (that works):
The program takes input of the current hours left on each check (a
, b
, c
& d
.) It prints output of what check should be performed (a
, b
, c
& d
.)
# Input (hours till each check)
a = 0
b = 590
c = 400
d = 9900
amax = 500
bmax = 1000
cmax = 2000
dmax = 10000
if a == 0:
if d - amax < 0:
print "d"
elif c - amax < 0:
print "c"
elif b - amax < 0:
print "b"
else:
print "a"
elif b == 0:
if d - bmax < 0:
print "d"
elif c - bmax < 0:
print "c"
else:
print "b"
elif c == 0:
if d - cmax < 0:
print "d"
else:
print "c"
elif d == 0:
print "d"
There is a lot of repetition in this code. I'm looking for a simpler version that does not compromise on readability.