diff options
Diffstat (limited to 'src/cube.c')
| -rw-r--r-- | src/cube.c | 32 |
1 files changed, 32 insertions, 0 deletions
| @@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | #include "cube.h" | 3 | #include "cube.h" |
| 4 | 4 | ||
| 5 | static int where_is_piece(int piece, int *arr, int n); | ||
| 6 | |||
| 5 | void | 7 | void |
| 6 | compose(Cube *c2, Cube *c1) | 8 | compose(Cube *c2, Cube *c1) |
| 7 | { | 9 | { |
| @@ -154,3 +156,33 @@ print_cube(Cube *cube) | |||
| 154 | printf(" %s ", center_string[cube->xp[i]]); | 156 | printf(" %s ", center_string[cube->xp[i]]); |
| 155 | printf("\n"); | 157 | printf("\n"); |
| 156 | } | 158 | } |
| 159 | |||
| 160 | int | ||
| 161 | where_is_center(Center x, Cube *c) | ||
| 162 | { | ||
| 163 | return where_is_piece(x, c->xp, 6); | ||
| 164 | } | ||
| 165 | |||
| 166 | int | ||
| 167 | where_is_corner(Corner k, Cube *c) | ||
| 168 | { | ||
| 169 | return where_is_piece(k, c->cp, 8); | ||
| 170 | } | ||
| 171 | |||
| 172 | int | ||
| 173 | where_is_edge(Edge e, Cube *c) | ||
| 174 | { | ||
| 175 | return where_is_piece(e, c->ep, 12); | ||
| 176 | } | ||
| 177 | |||
| 178 | static int | ||
| 179 | where_is_piece(int piece, int *arr, int n) | ||
| 180 | { | ||
| 181 | int i; | ||
| 182 | |||
| 183 | for (i = 0; i < n; i++) | ||
| 184 | if (arr[i] == piece) | ||
| 185 | return i; | ||
| 186 | |||
| 187 | return -1; | ||
| 188 | } | ||
