improve prop range splitting: 2
This commit is contained in:
parent
a1373ec338
commit
83d4a9b507
47
src/repr.rs
47
src/repr.rs
@ -78,45 +78,34 @@ impl Board {
|
|||||||
return;
|
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;
|
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;
|
break;
|
||||||
};
|
};
|
||||||
if piece == &starting_color {
|
if piece == &starting_color {
|
||||||
if chain_length > 0 {
|
if chain_length > 0 {
|
||||||
// fill all opposite colors with this color
|
// 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;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
// fill all opposite colors with this color
|
// fill all opposite colors with this color
|
||||||
for i_o in i_o_s {
|
for &(i_o, j_o) in i_o_s {
|
||||||
self.place_and_prop_unchecked(*i_o, j, starting_color);
|
self.place_and_prop_unchecked(i_o, j_o, 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user