[+] Alignment - Make random0 sequential before re-roll when preset matches slot count (#543)
Some checks failed
Shellcheck / check (push) Has been cancelled

This commit is contained in:
Azalea
2026-10-17 09:01:39 +00:00
parent 63e380ea4f
commit 74be0eaef0
2 changed files with 50 additions and 17 deletions

View File

@@ -1405,6 +1405,7 @@ fn create_config(
// Loop for random rolling
let mut rng = fastrand::Rng::new();
let mut is_first = true;
loop {
clear_screen(Some(&title), color_mode, debug_mode).context("failed to clear screen")?;
@@ -1420,18 +1421,36 @@ fn create_config(
.take(1000)
.collect();
let random_count = (ascii_per_row as usize * ascii_rows as usize).saturating_sub(arrangements.len()).clamp(0, u8::MAX.into()) as u8;
let other_permutations: IndexSet<Vec<PresetIndexedColor>> = preset_index_permutations
.into_iter()
.filter(|p| p != &ordered_p)
.collect();
let mut choices: IndexSet<Vec<PresetIndexedColor>> = IndexSet::new();
choices.insert(ordered_p);
let sample_count = (usize::from(random_count)).saturating_sub(1);
if sample_count >= other_permutations.len() {
choices.extend(other_permutations);
let is_sequential = is_first && color_profile.unique_colors().colors.len() == slots.len();
let choices: IndexSet<Vec<PresetIndexedColor>> = if random_count == 0 {
IndexSet::new()
} else if is_sequential {
let other_permutations: IndexSet<Vec<PresetIndexedColor>> = preset_index_permutations
.into_iter()
.filter(|p| p != &ordered_p)
.collect();
let mut choices: IndexSet<Vec<PresetIndexedColor>> = IndexSet::new();
choices.insert(ordered_p);
let sample_count = usize::from(random_count) - 1;
if sample_count >= other_permutations.len() {
choices.extend(other_permutations);
} else {
choices.extend(rng.choose_multiple(other_permutations.into_iter(), sample_count));
}
choices
} else {
choices.extend(rng.choose_multiple(other_permutations.into_iter(), sample_count));
}
if usize::from(random_count) >= preset_index_permutations.len() {
preset_index_permutations
} else {
rng.choose_multiple(
preset_index_permutations.into_iter(),
usize::from(random_count),
)
.into_iter()
.collect()
}
};
let choices: Vec<IndexMap<NeofetchAsciiIndexedColor, PresetIndexedColor>> = choices
.into_iter()
.map(|c| {
@@ -1482,6 +1501,7 @@ fn create_config(
if choice == "roll" {
arrangements.clear();
is_first = false;
continue;
}

View File

@@ -545,6 +545,7 @@ def create_config(path: Path | None = None) -> Config:
arrangements = hv_arrangements.copy()
# Loop for random rolling
is_first = True
while True:
clear_screen(title)
@@ -554,14 +555,25 @@ def create_config(path: Path | None = None) -> Config:
while len(pis) < len(slots):
pis += pis
perm = {p[:len(slots)] for p in islice(permutations(pis), 1000)}
ordered_p = tuple(pis[:len(slots)])
other_perms = [p for p in perm if p != ordered_p]
random_count = max(0, ascii_per_row * ascii_rows - len(arrangements))
if random_count > len(perm):
choices = [ordered_p] + other_perms
is_sequential = is_first and len(_prs.unique_colors().colors) == len(slots)
if random_count == 0:
choices = []
elif is_sequential:
ordered_p = tuple(pis[:len(slots)])
other_perms = [p for p in perm if p != ordered_p]
sample_count = random_count - 1
if sample_count >= len(other_perms):
choices = [ordered_p] + other_perms
else:
choices = [ordered_p] + random.sample(sorted(other_perms), min(sample_count, len(other_perms)))
else:
sample_count = max(0, random_count - 1)
choices = [ordered_p] + random.sample(sorted(other_perms), min(sample_count, len(other_perms)))
if random_count >= len(perm):
choices = list(perm)
else:
choices = random.sample(sorted(perm), random_count)
choices = [{slots[i]: n for i, n in enumerate(c)} for c in choices]
arrangements += [(f'random{i}', ColorAlignment('custom', r)) for i, r in enumerate(choices)]
asciis = [[*ca.recolor_ascii(asc, _prs).split('\n'), k.center(asc_width)] for k, ca in arrangements]
@@ -581,6 +593,7 @@ def create_config(path: Path | None = None) -> Config:
if choice == 'roll':
arrangements = []
is_first = False
continue
# Save choice