Skip to content

Commit 5f72e0d

Browse files
committed
recoded scatter, much better now
1 parent b8e702c commit 5f72e0d

File tree

1 file changed

+61
-72
lines changed

1 file changed

+61
-72
lines changed

src/mania.py

Lines changed: 61 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def randosu(path, content):
3737
if content_split[6] == '1':
3838
bpms.append({
3939
# {ms, mpb}
40-
'ms': content_split[0],
40+
'ms': float(content_split[0]),
4141
'mpb': float(content_split[1])
4242
})
4343

@@ -46,16 +46,14 @@ def randosu(path, content):
4646
# Ignore comments and blanks
4747
if c.startswith('//') or c == '\n':
4848
continue
49-
49+
5050
# Regular Note: col,192,ms,1,0,0:0:0:0:
5151
# Long Note: col,192,startms,128,0,endms:0:0:0:0:
5252
content_split = c.split(',')
5353
note_colvalue = int(content_split[0])
54-
print(note_colvalue, end=' ')
5554
for i in range(keys):
5655
if colrange[i] < note_colvalue <= colrange[i+1]:
5756
note_col = i
58-
print(note_col)
5957
break
6058
if note_colvalue == 0:
6159
note_col = 0
@@ -89,24 +87,6 @@ def randosu(path, content):
8987

9088
randnotes = []
9189

92-
# Boolean List for checking if the column is occupied or not
93-
# Defaults to [False, False, ..., False]
94-
Occupied = keys * [False]
95-
96-
# Int, Boolean List for checking the previous occupation (used for Scatter)
97-
# Defaults to [False, False, ..., False]
98-
LastOccupied = keys * [False]
99-
100-
# Int, Boolean List for checking the previous occupation for the last 16th beat (used for Scatter)
101-
# Defaults to [False, False, ..., False]
102-
Last16Occupied = keys * [False]
103-
104-
# Tracking LastOccupied's ms
105-
lastms = 0
106-
107-
# Checking if not placing jacks is impossible
108-
Impossible = False
109-
11090
# Dictionary List tracking the end time of occupation
11191
# {col, endms}
11292
occtime = []
@@ -162,83 +142,94 @@ def randosu(path, content):
162142
filename = f'{os.path.dirname(path)}\\{rand}({switch})_{randseed}_{sanitize_filename(diffname)}.osu'
163143

164144
i=0
145+
146+
f = open('test.log',mode='w',encoding='utf-8')
147+
148+
# Int, Boolean List for checking the previous occupation (used for Scatter)
149+
# Defaults to [False, False, ..., False]
150+
LastOccupied = keys * [False]
151+
152+
# Tracking LastOccupied's ms
153+
lastms = 0
165154

166155
# Randomize position of the notes
167156
for n in notes:
157+
# Boolean List for checking if the column is occupied or not
158+
# Defaults to [False, False, ..., False]
159+
Occupied = keys * [False]
160+
161+
# Int, Boolean List for checking the previous occupation for the last 16th beat (used for Scatter)
162+
# Defaults to [False, False, ..., False]
163+
Last16Occupied = keys * [False]
164+
168165
# Get current ms per beat
169166
mpb = -1
170167

171168
for b in bpms:
172169
if n['ms'] < b['ms']:
173170
mpb = bpms[bpms.index(b)-1]['mpb']
171+
break
174172

175173
if mpb == -1:
176174
mpb = bpms[-1]['mpb']
177175

178176
# Copy Occupied if Scatter and it's the next notes
179177
if (i != 0) and Scatter:
180-
if n['ms'] > lastms:
178+
# +5 just in case of unsnapped notes
179+
if n['ms'] > lastms + 5:
181180
lastms = n['ms']
182-
k = 0
183-
for lo in Occupied:
184-
LastOccupied[k] = lo
185-
k += 1
181+
LastOccupied = keys * [False]
182+
for o in occtime[:]:
183+
LastOccupied[o['col']] = True
186184

187185
# If current ms > endms, Unoccupy the column
188186
# Doing this the first because the program gets stuck often
187+
# Also occupy the column meanwhile
189188
for o in occtime[:]:
190189
if n['ms'] > o['endms']:
191190
occtime.remove(o)
192-
Occupied[o['col']] = False
191+
for o in occtime[:]:
192+
Occupied[o['col']] = True
193193

194194
for o in occ16time[:]:
195195
if n['ms'] > o['endms']:
196196
occ16time.remove(o)
197-
Last16Occupied[o['col']] = False
197+
for o in occ16time[:]:
198+
Last16Occupied[o['col']] = True
198199

199200
# If no switch, (and if scatter, if not last16occupied,) keep the column
200201
if not Switch[i] and not Occupied[n['col']] and (not Scatter or not Last16Occupied[n['col']]):
201202
randcol = n['col']
202203
# If switch, Get an unoccupied column
203204
else:
204-
while True:
205-
randcol = randint(0, keys-1)
206-
if not Occupied[randcol]:
207-
if Scatter:
208-
if not Last16Occupied[randcol]:
209-
break
210-
211-
# Checking if ignoring 16th jack is impossible
212-
# Keep Impossible True if all Occupied and Last16Occupied is True
213-
Impossible = True
214-
for j in range(keys):
215-
if not Occupied[j] or not Last16Occupied[j]:
216-
Impossible = False
205+
# leftcol: not Occupied, possible columns
206+
# goodcol: not Occupied AND not LastOccupied, desired columns
207+
# bestcol: not Occupied AND not Last16Occupied, most desired columns
208+
bestcol = []
209+
goodcol = []
210+
leftcol = []
217211

218-
# If it is not impossible, just try again
219-
# If impossible however, prioritize not LastOccupied column
220-
if Impossible:
221-
# Check if every column is LastOccupied (e.g. Chords with all keys)
222-
# leftcol: not Occupied, possible columns
223-
# goodcol: not Occupied AND not LastOccupied, desired columns
224-
leftcol = []
225-
goodcol = []
226-
for j in range(keys):
227-
if not Occupied[j]:
228-
leftcol.append(j)
229-
if not LastOccupied[j]:
230-
goodcol.append(j)
231-
Impossible = False
212+
for j in range(keys):
213+
if not Occupied[j]:
214+
leftcol.append(j)
215+
if not Last16Occupied[j]:
216+
bestcol.append(j)
217+
if not LastOccupied[j]:
218+
goodcol.append(j)
232219

233-
if not Impossible:
234-
randcol = choice(goodcol)
235-
236-
else:
237-
randcol = choice(leftcol)
238-
239-
break
220+
if len(bestcol) > 0:
221+
randcol = choice(bestcol)
222+
223+
else:
224+
if len(goodcol) > 0:
225+
randcol = choice(goodcol)
226+
227+
else:
228+
if len(leftcol) > 0:
229+
randcol = choice(leftcol)
230+
240231
else:
241-
break
232+
randcol = randint(0, keys-1)
242233

243234
# if LN:
244235
if 'endms' in n:
@@ -253,8 +244,8 @@ def randosu(path, content):
253244
})
254245
occ16time.append({
255246
'col': randcol,
256-
# Getting the ceil value just in case
257-
'endms': n['endms'] + ceil(mpb / 4)
247+
# Getting the ceil value just in case of an unsnapped note
248+
'endms': n['ms'] + ceil(mpb / 4)
258249
})
259250

260251
# if regular note:
@@ -269,17 +260,15 @@ def randosu(path, content):
269260
})
270261
occ16time.append({
271262
'col': randcol,
272-
# Getting the ceil value just in case
263+
# Getting the ceil value just in case of an unsnapped note
273264
'endms': n['ms'] + ceil(mpb / 4)
274265
})
275-
276-
# Occupy the column
277-
Occupied[randcol] = True
278-
Last16Occupied[randcol] = True
279266

280267
i += 1
281-
282268

269+
f.write(f'{randcol} | {n["ms"]}, {ceil(mpb/4)}, {bestcol}, {goodcol}, {leftcol}\n')
270+
271+
f.close()
283272
with open(filename,'w',encoding='utf-8') as osu:
284273
col = [int(512*(2*column+1)/(2*keys)) for column in range(keys)]
285274

0 commit comments

Comments
 (0)