(matches: &BorderMatches, corner: usize)
| 86 | } |
| 87 | |
| 88 | fn build_image(matches: &BorderMatches, corner: usize) -> Vec<Vec<char>> { |
| 89 | let images = IMAGES.iter().copied().collect::<HashMap<_,_>>(); |
| 90 | |
| 91 | // align the corner to fit in the top-left |
| 92 | let mut starting_corner = Tile::from_input(&images[&corner], corner); |
| 93 | while [0,3].iter().any(|&d| starting_corner.get_neighbour(matches, d).is_some()) { |
| 94 | starting_corner.rotate(); |
| 95 | } |
| 96 | |
| 97 | let mut image = vec![vec![Tile::default(); 12]; 12]; |
| 98 | image[0][0] = starting_corner; |
| 99 | // match the first tile in each row to the one above |
| 100 | for i in 1..12 { |
| 101 | image[i][0] = image[i-1][0].match_down(matches, &images); |
| 102 | } |
| 103 | // for all other tiles match to the previous tile in the row |
| 104 | for (i,j) in (0..12).cartesian_product(1..12) { |
| 105 | image[i][j] = image[i][j-1].match_right(matches, &images); |
| 106 | } |
| 107 | |
| 108 | // tiles are placed and rotated correctly, now build the actual image |
| 109 | let mut actual_image = vec![Vec::new(); 8 * 12]; |
| 110 | for (i,j) in (0..12).cartesian_product(0..12) { |
| 111 | let tile = &image[i][j]; |
| 112 | for k in 1..9 { |
| 113 | actual_image[i * 8 + (k-1)].extend(&tile.v[k][1..9]); |
| 114 | } |
| 115 | } |
| 116 | actual_image |
| 117 | } |
| 118 | |
| 119 | fn find_monsters(image: &[Vec<char>], monster_coords: &HashSet<(isize,isize)>) -> usize { |
| 120 | let positions = image.iter() |
no test coverage detected