From 9725570d740041b51d6bdfbc8416498ddad77666 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 11 Dec 2021 11:44:44 +0100 Subject: Improved where_is_edge --- src/cube.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/cube.c b/src/cube.c index 4e038c7..24cca4d 100644 --- a/src/cube.c +++ b/src/cube.c @@ -641,23 +641,22 @@ where_is_corner(Cube cube, Corner c) } Edge -where_is_edge(Cube cube, Edge e) +where_is_edge(Cube c, Edge e) { - /* TODO: when I wrote this code I forgot to add the final - part, and now I can't remember how it was supposed to - work (i.e. how to recover the location of the edge - from these tables. I think it is either very easy or - wrong, in any case it is not a priority now. - Future Seba can deal with it. + int r0, r1, r2; static bool initialized = false; - static Edge aux[3][FACTORIAL12/FACTORIAL8][12]; - static int i; + static int aux[3][BINOM12ON4*FACTORIAL4][12]; + static int i, j; static unsigned int ui; static CubeArray *arr; if (!initialized) { - for (ui = 0; ui < FACTORIAL12/FACTORIAL8; ui++) { + for (ui = 0; ui < BINOM12ON4*FACTORIAL4; ui++) { + for (i = 0; i < 3; i++) + for (j = 0; j < 12; j++) + aux[i][ui][j] = -1; + arr = new_cubearray((Cube){.epose = ui}, pf_e); for (i = 0; i < 12; i++) if (edge_slice(arr->ep[i]) == 0) @@ -679,14 +678,9 @@ where_is_edge(Cube cube, Edge e) initialized = true; } - */ - - int i; - CubeArray *arr = new_cubearray(cube, pf_ep); - for (i = 0; i < 12; i++) - if ((Edge)arr->ep[i] == e) - return i; - - return -1; + r0 = aux[0][c.epose][e]; + r1 = aux[1][c.eposs][e]; + r2 = aux[2][c.eposm][e]; + return MAX(r0, MAX(r1, r2)); } -- cgit v1.3