improve prop range splitting: 2

This commit is contained in:
Simon Gardling 2025-01-27 14:40:36 -05:00
parent a1373ec338
commit 83d4a9b507
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -78,45 +78,34 @@ impl Board {
return;
};
for range in split(0, BOARD_SIZE - 1, i) {
let mut chains: Vec<Vec<(usize, usize)>> = split(0, BOARD_SIZE - 1, i)
.into_iter()
.map(|range| range.into_iter().map(|i| (i, j)).collect())
.collect();
chains.append(
&mut split(0, BOARD_SIZE - 1, j)
.into_iter()
.map(|range| range.into_iter().map(|j| (i, j)).collect())
.collect::<Vec<Vec<(usize, usize)>>>(),
);
for chain in chains {
let mut chain_length: usize = 0;
for &new_i in &range {
let Some(piece) = self.get(new_i, j) else {
for &(new_i, new_j) in &chain {
let Some(piece) = self.get(new_i, new_j) else {
break;
};
if piece == &starting_color {
if chain_length > 0 {
// fill all opposite colors with this color
let Some(i_o_s) = range.get(..chain_length) else {
let Some(i_o_s) = chain.get(..chain_length) else {
break;
};
// fill all opposite colors with this color
for i_o in i_o_s {
self.place_and_prop_unchecked(*i_o, j, starting_color);
}
}
break;
}
chain_length += 1;
}
}
for range in split(0, BOARD_SIZE - 1, j) {
let mut chain_length: usize = 0;
for &new_j in &range {
let Some(piece) = self.get(i, new_j) else {
break;
};
if piece == &starting_color {
if chain_length > 0 {
let Some(j_o_s) = range.get(..chain_length) else {
break;
};
// fill all opposite colors with this color
for j_o in j_o_s {
self.place_and_prop_unchecked(i, *j_o, starting_color);
for &(i_o, j_o) in i_o_s {
self.place_and_prop_unchecked(i_o, j_o, starting_color);
}
}
break;