(args: Args, w: usize, h: usize)
| 478 | let left = pos + dir_left; |
| 479 | let rand_choice = rand::random::<f32>(); |
| 480 | if self.is_in_bounds(&down) && !self.is_empty(&down) { |
| 481 | if rand_choice < 0.2 && self.is_in_bounds(&left) && self.is_empty(&left) { |
| 482 | self.swap(&left, &down); |
| 483 | } else if rand_choice >= 0.8 && self.is_in_bounds(&right) && self.is_empty(&right) { |
| 484 | self.swap(&right, &down); |
| 485 | } else if self.is_empty(&down) { |
| 486 | self.swap(&pos, &down); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | fn step(&mut self, args: &Args, dir: &Vec2) { |
| 492 | self.flip = (self.flip + 1) % self.flip_rate; |
| 493 | if self.flip != 0 { |
| 494 | return; |
| 495 | } |
| 496 | let yrange: Box<dyn Iterator<Item = usize>> = match dir.y { |
| 497 | -1 => Box::new((1..self.height).rev()), // down (process from bottom up) |
| 498 | _ => Box::new(0..self.height - 1), // up |
| 499 | }; |
| 500 | let xrange: Box<dyn Iterator<Item = usize>> = match dir.x { |
| 501 | -1 => Box::new((1..self.width).rev()), |
| 502 | _ => Box::new(0..self.width - 1), |
| 503 | }; |
| 504 | self.spawn(args, dir); |
| 505 | if dir.x == 0 { |
| 506 | for y in yrange { |
| 507 | for x in 0..self.width { |
| 508 | let pos = Vec2 { |
| 509 | x: x as isize, |
| 510 | y: y as isize, |
| 511 | }; |
| 512 | self.step_fall(pos, *dir); |
| 513 | } |
| 514 | } |
| 515 | } else { |
| 516 | for x in xrange { |
nothing calls this directly
no outgoing calls
no test coverage detected