-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_incomplete.py
More file actions
131 lines (108 loc) · 4.58 KB
/
main_incomplete.py
File metadata and controls
131 lines (108 loc) · 4.58 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/pyton
file_name = "00-example.txt"
#file_name = "01-the-cloud-abyss.txt"
# file_name = "02-iot-island-of-terror.txt"
# file_name = "03-etheryum.txt" # da fare in up
# file_name = "04-the-desert-of-autonomous-machines.txt"
# file_name = "05-androids-armageddon.txt"
f = open(file_name, "r")
firstline = f.readline().strip().split()
stamina = int(firstline[0])
max_stamina = int(firstline[1])
TURNS = int(firstline[2])
numb_demons = int(firstline[3])
stamina_timeline = [0]*TURNS
# Demon Stamina i
D_idx = 0
DS_dwn_idx = D_idx+1
DS_delay_idx = DS_dwn_idx+1
DS_up_idx = DS_delay_idx+1
DF_turns_idx = DS_up_idx + 1 # demon fragments
demons = []
for i in range(0, numb_demons):
# this block must be copied
demons.append(list(map(int, f.readline().strip().split())))
demons[i].insert(0, i)
tmp_fragment_position_weight = []
for j in range(0, demons[i][DF_turns_idx]):
demons[i][j +
DF_turns_idx+1] = float(float(demons[i][j+DF_turns_idx+1])/(j+1))
# remove unusable fragments
if(demons[i][DF_turns_idx] > TURNS):
# demons[i] = list(demons[i][DF_turns_idx:DF_turns_idx+TURNS-1])
list_of_obtainable_fragments = list(
demons[i][DF_turns_idx+1:DF_turns_idx+1+TURNS])
# the number of fragments obtainable by this demon is not its default but turns
demons[i][DF_turns_idx] = TURNS
else:
list_of_obtainable_fragments = demons[i][DF_turns_idx+1:]
# tot_obtainable_fragments = sum(demons[DF_turns_idx:])
tot_obtainable_fragments = sum(list_of_obtainable_fragments)
weight = float(float(tot_obtainable_fragments)/demons[i][DS_up_idx])
demons[i].append(weight)
demons[i].append(tot_obtainable_fragments)
# demons = sorted(demons, key=lambda x: (x[DS_dwn_idx]))
# demons = sorted(demons, key=lambda x: (x[DS_up_idx]))
for i in demons:
print(i)
# sort by total obtainable fragments
demons = list(sorted(demons, key=lambda x: (x[-2])))
demons.reverse()
take_demon_order = []
print("here")
for i in demons:
print(i)
exit()
for turn in range(0, TURNS):
print(f"{turn}/{TURNS}\n")
# Increment stamina
stamina = min(max_stamina, stamina+stamina_timeline[turn])
# print(f"[{turn}] stamina: {stamina} stamina_timeline: {stamina_timeline}")
for dem in range(0, len(demons)):
if(stamina > demons[dem][DS_dwn_idx]):
# ok I take the demon
# where to put the next stamina power up
next_stamina_up_idx = turn+demons[dem][DS_delay_idx]
# schedule stamina increase
# can I insert a new stamina power up
if(next_stamina_up_idx < TURNS):
stamina_timeline[next_stamina_up_idx] += demons[dem][DS_up_idx]
stamina -= demons[dem][DS_dwn_idx]
# take monster
take_demon_order.append(demons[dem][D_idx])
del demons[dem]
# Max gettable fragments of all demons get reduced
for upd_demon in demons:
# the number of truns obtainable fragments of this demon is decremented
number_of_turns_to_collect_fragments = upd_demon[DF_turns_idx]
# If number of turns to collect fragments of this demon is greater to the number of remaining turns, then we need to decrease it
if(number_of_turns_to_collect_fragments > TURNS-turn-1):
# tot_obtainable_fragments
# |
# V
# [3 . . . ] but we have 10 turns
tot_obtainable_fragments = upd_demon[DF_turns_idx +
number_of_turns_to_collect_fragments]
upd_demon[-1] -= tot_obtainable_fragments
weight = float(
float(tot_obtainable_fragments)/upd_demon[DS_dwn_idx])
# decrease the number of ubtainable fragments (turns) from this demon
upd_demon[DF_turns_idx] -= 1
# sort another time for the total obtainable fragments
demons = list(sorted(demons, key=lambda x: (x[-2])))
demons.reverse()
# print("updated demons after take")
# for i in demons:
# print(i)
break
break
else:
if(stamina < 2):
break
# print(
# f"demon {dem} with stamina {demons[dem][DS_dwn_idx]} too strong current stamina {stamina}")
pass
print(take_demon_order)
with open(file_name+"_result.txt", "w") as f:
for demon in take_demon_order:
f.write(str(demon)+"\n")