Remove deprecated code
[matilda.git] / src / matrix.c
blob5948569554e715443fcb43b32607784feb7503c9
1 /*
2 Generic matrix transformations
3 */
5 #include "config.h"
7 #include <string.h>
8 #include <stdio.h>
9 #include <assert.h>
11 #include "board.h"
12 #include "matrix.h"
13 #include "move.h"
14 #include "types.h"
18 Rotate square matrix.
20 void matrix_rotate(
21 u8 dst[static TOTAL_BOARD_SIZ],
22 const u8 src[static TOTAL_BOARD_SIZ],
23 u16 side_len,
24 u8 rotations
25 ) {
26 assert(rotations < 4);
28 u8 x;
29 u8 y;
31 switch (rotations) {
32 case 0:
33 memcpy(dst, src, side_len * side_len);
34 break;
35 case 1:
36 --side_len;
38 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
39 move_to_coord(m, &x, &y);
40 dst[m] = src[coord_to_move(side_len - y, x)];
42 break;
43 case 2:
44 --side_len;
46 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
47 dst[m] = src[TOTAL_BOARD_SIZ - 1 - m];
49 break;
50 case 3:
51 --side_len;
53 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
54 move_to_coord(m, &x, &y);
55 dst[m] = src[coord_to_move(y, side_len - x)];
61 Rotate contents of an out_board structure.
63 void matrix_rotate2(
64 out_board * restrict dst,
65 const out_board * restrict src,
66 u8 rotations
67 ) {
68 assert(rotations < 4);
70 u8 x;
71 u8 y;
73 switch (rotations) {
74 case 0:
75 memcpy(dst->value, src->value, TOTAL_BOARD_SIZ * sizeof(double));
76 memcpy(dst->tested, src->tested, TOTAL_BOARD_SIZ);
77 break;
78 case 1:
79 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
80 move_to_coord(m, &x, &y);
81 move n = coord_to_move(BOARD_SIZ - 1 - y, x);
82 dst->value[m] = src->value[n];
83 dst->tested[m] = src->tested[n];
85 break;
86 case 2:
87 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
88 dst->value[m] = src->value[TOTAL_BOARD_SIZ - 1 - m];
89 dst->tested[m] = src->tested[TOTAL_BOARD_SIZ - 1 - m];
91 break;
92 case 3:
93 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
94 move_to_coord(m, &x, &y);
95 move n = coord_to_move(y, BOARD_SIZ - 1 - x);
96 dst->value[m] = src->value[n];
97 dst->tested[m] = src->tested[n];
101 dst->pass = src->pass;
105 Flips a square matrix.
107 void matrix_flip(
108 u8 dst[static TOTAL_BOARD_SIZ],
109 const u8 src[static TOTAL_BOARD_SIZ],
110 u16 side_len
112 u8 x;
113 u8 y;
115 --side_len;
117 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
118 move_to_coord(m, &x, &y);
119 dst[m] = src[coord_to_move(side_len - x, y)];
124 Flips the board contents of an out_board structure.
126 void matrix_flip2(
127 out_board * restrict dst,
128 const out_board * restrict src
130 u8 x;
131 u8 y;
133 for (move m = 0; m < TOTAL_BOARD_SIZ; ++m) {
134 move_to_coord(m, &x, &y);
135 move n = coord_to_move(BOARD_SIZ - 1 - x, y);
136 dst->value[m] = src->value[n];
137 dst->tested[m] = src->tested[n];
140 dst->pass = src->pass;
145 Produces the move correspondent in the transformed matrix.
147 void reduce_coord(
148 u8 * restrict x,
149 u8 * restrict y,
150 u16 side_len,
151 d8 method
153 if (method == NOREDUCE || *x >= BOARD_SIZ) {
154 return;
157 if (method < 0) {
158 method = method * -1;
161 u8 ox = *x;
162 u8 oy = *y;
163 u8 ix;
164 u8 iy;
166 switch (method) {
167 case ROTATE90:
168 ox = *y;
169 oy = side_len - 1 - *x;
170 break;
171 case ROTATE180:
172 ox = side_len - 1 - *x;
173 oy = side_len - 1 - *y;
174 break;
175 case ROTATE270:
176 ox = side_len - 1 - *y;
177 oy = *x;
178 break;
179 case ROTFLIP0:
180 ox = side_len - 1 - *x;
181 oy = *y;
182 break;
183 case ROTFLIP90:
184 ix = *y;
185 iy = side_len - 1 - *x;
187 ox = side_len - 1 - ix;
188 oy = iy;
189 break;
190 case ROTFLIP180:
191 ix = side_len - 1 - *x;
192 iy = side_len - 1 - *y;
194 ox = side_len - 1 - ix;
195 oy = iy;
196 break;
197 case ROTFLIP270:
198 ix = side_len - 1 - *y;
199 iy = *x;
201 ox = side_len - 1 - ix;
202 oy = iy;
205 *x = ox;
206 *y = oy;