Almost functionnal

This commit is contained in:
Geoffrey Frogeye 2016-02-11 20:48:54 +01:00
parent 0fefade86b
commit c56e442d29

17
main.py
View file

@ -5,8 +5,6 @@ import sys
print("#hashcode2016") print("#hashcode2016")
import read
X = 0 # Nb rows X = 0 # Nb rows
Y = 0 # Nb columns Y = 0 # Nb columns
D = 0 # Nb drones D = 0 # Nb drones
@ -100,6 +98,8 @@ for d in range(D):
Di.append(dict((p, 0) for p in range(P))) Di.append(dict((p, 0) for p in range(P)))
Dd.append(0) Dd.append(0)
Out = [] # Drones commands
# Debug # Debug
assert(len(Dp) == len(Di) == len(Dd) == D) assert(len(Dp) == len(Di) == len(Dd) == D)
@ -165,10 +165,14 @@ def deliver(d, c, p, q):
def wait(d, w=1): def wait(d, w=1):
assert(d in Da) assert(d in Da)
Dd[d] += w Dd[d] += w
Da.remove(d)
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "", Dd[d]) print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "", Dd[d])
Out.append(str(d) + ' W ' + str(w))
# Control # Control
def newTurn(): def newTurn():
global t
t += 1 t += 1
print("--- Turn", t) print("--- Turn", t)
for d in Da: for d in Da:
@ -176,16 +180,17 @@ def newTurn():
assert(len(Da) == 0) assert(len(Da) == 0)
for d in range(D): for d in range(D):
if Dd[d] <= t: if Dd[d] <= t:
Da.push(d) Da.append(d)
print("Drones", ", ".join(Da), "(", len(Da), ")", "are avaible") print("Drones", ", ".join([str(d) for d in Da]), "(", len(Da), ")", "are avaible")
def end(): def end():
print("--- End!") print("--- End!")
Out = '' # Drones commands
# IA # IA
newTurn()
newTurn()
# Output # Output
f = open(sys.argv[1] + 'o', 'w') f = open(sys.argv[1] + 'o', 'w')
f.write(len(Out)/10 + '\n' + Out) f.write(str(len(Out)) + '\n' + '\n'.join(Out))
f.close() f.close()