impl propegation

This commit is contained in:
Simon Gardling 2025-01-24 10:10:37 -05:00
parent 3ab0f4bb5f
commit a64d6b143f
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -50,16 +50,19 @@ impl Board {
for i_range in i_ranges { for i_range in i_ranges {
let mut chain_length: usize = 0; let mut chain_length: usize = 0;
for new_i in i_range { for new_i in i_range.clone() {
match self.get(new_i, j) { match self.get(new_i, j) {
Some(piece) => { Some(piece) => {
if piece == &starting_color { if piece == &starting_color {
if chain_length > 0 { if chain_length > 0 {
todo!("matching end") // fill all opposite colors with this color
i_range.get(..chain_length).unwrap().iter().for_each(|i_o| {
self.place_and_prop_unchecked(*i_o, j, starting_color)
});
} }
break; break;
} else { } else {
todo!("add to the chain"); chain_length += 1;
} }
} }
None => break, None => break,
@ -68,10 +71,26 @@ impl Board {
} }
for j_range in j_ranges { for j_range in j_ranges {
for new_j in j_range {} let mut chain_length: usize = 0;
for new_j in j_range.clone() {
match self.get(i, new_j) {
Some(piece) => {
if piece == &starting_color {
if chain_length > 0 {
// fill all opposite colors with this color
j_range.get(..chain_length).unwrap().iter().for_each(|j_o| {
self.place_and_prop_unchecked(i, *j_o, starting_color)
});
}
break;
} else {
chain_length += 1;
}
}
None => break,
}
}
} }
todo!("propegation is not implemented");
} }
fn place_and_prop_unchecked(&mut self, i: usize, j: usize, piece: Piece) { fn place_and_prop_unchecked(&mut self, i: usize, j: usize, piece: Piece) {