1use itertools::Itertools;
4use crate::cats::*;
5use crate::examples::*;
7use crate::grid::*;
8use crate::shape::*;
9pub fn move_only(grid: &Grid, n: &mut usize) -> Grid {
13 let func = [Grid::move_down, Grid::move_up, Grid::move_right, Grid::move_left];
14 if *n == usize::MAX {
15 *n = func.len();
16 }
17 if *n == 0 {
18 Grid::trivial()
19 } else {
20 func[func.len() - *n](grid)
21 }
22}
23
24pub fn gravity_only(grid: &Grid, n: &mut usize) -> Grid {
26 let func = [Grid::stretch_down, Grid::gravity_down, Grid::gravity_up];
27 if *n == usize::MAX {
28 *n = func.len();
29 }
30 if *n == 0 {
31 Grid::trivial()
32 } else {
33 func[func.len() - *n](grid)
34 }
35}
36
37pub fn mirror_only(grid: &Grid, n: &mut usize) -> Grid {
39 let func = [Grid::mirror_right, Grid::mirror_left, Grid::mirror_down, Grid::mirror_up, Grid::dup_right, Grid::dup_left, Grid::dup_down, Grid::dup_up];
40 if *n == usize::MAX {
41 *n = func.len();
42 }
43 if *n == 0 {
44 Grid::trivial()
45 } else {
46 func[func.len() - *n](grid)
47 }
48}
49
50pub fn diff_only(grid: &Grid, colour: Colour, n: &mut usize) -> Grid {
69 let func = [Grid::diff_only_and, Grid::diff_only_or, Grid::diff_only_xor, Grid::diff_black_same, Grid::diff_other_same];
70 if *n == usize::MAX {
71 *n = func.len();
72 }
73 if *n == 0 {
74 Grid::trivial()
75 } else {
76 func[func.len() - *n](grid, colour)
77 }
78}
79
80pub fn transform_only(grid: &Grid, n: &mut usize) -> Grid {
81 let func = [Grid::rot_00, Grid::rot_90, Grid::rot_180, Grid::rot_270, Grid::transposed, Grid::mirrored_rows, Grid::mirrored_cols];
82
83 if *n == usize::MAX {
84 *n = func.len();
85 }
86 if *n == 0 {
87 Grid::trivial()
88 } else {
89 func[func.len() - *n](grid)
90 }
91}
92
93pub fn simple_diffs(exs: &Examples) -> Option<Vec<Grid>> {
110 let mut diffs: Vec<Grid> = Vec::new();
111
112 for e in exs.examples.iter() {
113 if let Some(diff) = e.input.grid.diff(&e.output.grid) {
114 diffs.push(diff);
115 } else {
116 return None;
117 }
118 }
119
120 Some(diffs)
121}
122
123pub fn difference(exs: &Examples) {
124for e in exs.examples.iter() {
126 if let Some(diff) = e.input.grid.diff(&e.output.grid) {
127 diff.show_full();
128}
130 }
136
137 exs.tests.iter().for_each(|tests| tests.input.grid.show());
138}
140
141pub fn permutations(v: &[usize]) -> Vec<Vec<&usize>> {
142 let mut perms: Vec<Vec<&usize>> = Vec::new();
143
144 for perm in v.iter().permutations(v.len()).unique() {
145 perms.push(perm);
146 }
147
148 perms
149}
150
151pub fn difference_shapes(exs: &Examples, coloured: bool) {
152 for shapes in &exs.examples {
153 if let Some(diff) = shapes.input.grid.diff(&shapes.output.grid) {
154 diff.show_full();
155 }
156 let mut used: Vec<Shape> = Vec::new();
157 let inp = if coloured { &shapes.input.coloured_shapes } else { &shapes.input.shapes };
158 let out = if coloured { &shapes.output.coloured_shapes } else { &shapes.output.shapes };
159
160 for si in inp.shapes.iter() {
161 for so in out.shapes.iter() {
162 if si.orow == so.orow && si.ocol == so.ocol {
163 if let Some(diff) = si.diff(so) {
164 println!("Same size");
165 diff.show_full();
166 } else {
167 println!("Different sizes");
168 si.show();
169 so.show();
170 }
171 } else if !used.contains(so) {
172 used.push(so.clone());
173 println!("Other shapes");
174 so.show();
175 }
176 }
177 }
178 }
179
180 println!("Test shapes");
181 for test in exs.tests.iter() {
182 for ex in test.input.shapes.shapes.iter() {
183 ex.show();
184 }
185 }
186}
187
188pub fn repeat_pattern(ex: &Example, colour: Colour) -> Grid {
210 let shape = ex.input.grid.as_shape();
211 let (rs, cs) = ex.input.grid.dimensions();
212
213 if colour == Colour::Black {
214 shape.chequer(rs, cs, &|r,c| ex.input.grid.cells[(r / rs,c / cs)].colour != colour, &|s| s.clone(), true).to_grid()
215 } else {
216 shape.chequer(rs, cs, &|r,c| ex.input.grid.cells[(r / rs,c / cs)].colour == colour, &|s| s.clone(), true).to_grid()
217 }
218}
219
220