diff --git a/src/repr.rs b/src/repr.rs index bf12bed..96632b0 100644 --- a/src/repr.rs +++ b/src/repr.rs @@ -50,16 +50,19 @@ impl Board { for i_range in i_ranges { 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) { Some(piece) => { if piece == &starting_color { 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; } else { - todo!("add to the chain"); + chain_length += 1; } } None => break, @@ -68,10 +71,26 @@ impl Board { } 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) {