Skip to content

Commit

Permalink
666 step30 use C for IDA
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalton76 committed Aug 18, 2018
1 parent 3594a24 commit 48e80f7
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 38,881 deletions.
4 changes: 2 additions & 2 deletions Makefile
@@ -1,10 +1,10 @@

all:
sudo python3 setup.py install
gcc -O3 -o ida_search ida_search_core.c ida_search.c rotate_xxx.c ida_search_555.c ida_search_666.c -lm
gcc -o ida_search ida_search_core.c ida_search.c rotate_xxx.c ida_search_555.c ida_search_666.c -lm

ida:
gcc -O3 -o ida_search ida_search_core.c ida_search.c rotate_xxx.c ida_search_555.c ida_search_666.c -lm
gcc -ggdb -o ida_search ida_search_core.c ida_search.c rotate_xxx.c ida_search_555.c ida_search_666.c -lm

clean:
sudo rm -rf build dist rubikscubennnsolver.egg-info
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ I am working on bringing this down but these are the memory requirements for run
| ------ | ------ | ------ |
| 4x4x4 | 500M | 300M |
| 5x5x5 | 200M | 170M |
| 6x6x6 | 1.6G | 1.1G |
| 6x6x6 | 1.0G | 1.0G |
| 7x7x7 | 4.5G | 4.5G |
| NxNxN | 4.5G | 4.5G |

Expand Down
73 changes: 66 additions & 7 deletions ida_search.c
Expand Up @@ -31,13 +31,15 @@ typedef enum {
NONE,
UD_CENTERS_STAGE_555,
UD_OBLIQUE_EDGES_STAGE_666,
LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666,
} lookup_table_type;


struct key_value_pair *ida_explored = NULL;
struct key_value_pair *UD_centers_555 = NULL;
char *pt_t_centers_cost_only = NULL;
char *pt_x_centers_cost_only = NULL;
char *LR_inner_x_centers_666 = NULL;


int
Expand Down Expand Up @@ -288,6 +290,7 @@ str_replace_list_of_chars (char *str, char *old, char new)
void
init_cube(char *cube, int size, lookup_table_type type, char *kociemba)
{
char ones_UD[2] = {'U', 'D'};
int squares_per_side = size * size;
int square_count = squares_per_side * 6;
int U_start = 1;
Expand All @@ -305,7 +308,7 @@ init_cube(char *cube, int size, lookup_table_type type, char *kociemba)
int L_start_kociemba = D_start_kociemba + squares_per_side;
int B_start_kociemba = L_start_kociemba + squares_per_side;

char ones_UD[2] = {'U', 'D'};
char ones_LR[2] = {'L', 'R'};

memset(cube, 0, sizeof(char) * (square_count + 2));
cube[0] = 'x'; // placeholder
Expand All @@ -325,6 +328,12 @@ init_cube(char *cube, int size, lookup_table_type type, char *kociemba)
print_cube(cube, size);
break;

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
// Convert to 1s and 0s
str_replace_for_binary(cube, ones_LR);
print_cube(cube, size);
break;

default:
printf("ERROR: init_cube() does not yet support this --type\n");
exit(1);
Expand Down Expand Up @@ -449,14 +458,16 @@ ida_heuristic (char *cube, lookup_table_type type, int debug)
case UD_OBLIQUE_EDGES_STAGE_666:
return ida_heuristic_UD_oblique_edges_stage_666(cube);

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
return ida_heuristic_LR_inner_x_centers_and_oblique_edges_stage_666(cube, LR_inner_x_centers_666);

default:
printf("ERROR: ida_heuristic() does not yet support this --type\n");
exit(1);
}
}


/* Load the cube state into the scratchpad sp_cube_state */
unsigned long
get_lt_state (char *cube, lookup_table_type type)
{
Expand All @@ -468,6 +479,9 @@ get_lt_state (char *cube, lookup_table_type type)
case UD_OBLIQUE_EDGES_STAGE_666:
return get_UD_oblique_edges_stage_666(cube);

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
return get_LR_inner_x_centers_and_oblique_edges_stage(cube);

default:
printf("ERROR: get_lt_state() does not yet support type %d\n", type);
exit(1);
Expand All @@ -488,6 +502,9 @@ ida_search_complete (char *cube, lookup_table_type type)
case UD_OBLIQUE_EDGES_STAGE_666:
return ida_search_complete_UD_oblique_edges_stage_666(cube);

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
return ida_search_complete_LR_inner_x_centers_and_oblique_edges_stage(cube);

default:
printf("ERROR: ida_search_complete() does not yet support type %d\n", type);
exit(1);
Expand Down Expand Up @@ -566,7 +583,6 @@ moves_cancel_out (move_type move, move_type prev_move)
int
step_allowed_by_ida_search (lookup_table_type type, move_type move)
{
// dwalton
switch (type) {
case UD_CENTERS_STAGE_555:
return 1;
Expand All @@ -586,11 +602,33 @@ step_allowed_by_ida_search (lookup_table_type type, move_type move)
return 1;
}

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
switch (move) {
case threeFw:
case threeFw_PRIME:
case threeBw:
case threeBw_PRIME:
case threeLw:
case threeLw_PRIME:
case threeRw:
case threeRw_PRIME:
case Fw:
case Fw_PRIME:
case Bw:
case Bw_PRIME:
case Lw:
case Lw_PRIME:
case Rw:
case Rw_PRIME:
return 0;
default:
return 1;
}

default:
printf("ERROR: step_allowed_by_ida_search add support for this type\n");
exit(1);
}

}


Expand Down Expand Up @@ -755,7 +793,6 @@ steps_on_same_face_and_layer(move_type move, move_type prev_move)
}
break;

// dwalton
case threeUw:
case threeUw_PRIME:
case threeUw2:
Expand Down Expand Up @@ -924,7 +961,6 @@ ida_search (unsigned int cost_to_here,

for (int i = 0; i < MOVE_COUNT_666; i++) {
move = moves_666[i];
// dwalton

if (steps_on_same_face_and_layer(move, prev_move)) {
continue;
Expand Down Expand Up @@ -962,12 +998,18 @@ ida_solve (char *cube, unsigned int cube_size, lookup_table_type type)

switch (type) {
case UD_CENTERS_STAGE_555:
ida_prune_table_preload(&UD_centers_555, "lookup-table-5x5x5-step10-UD-centers-stage.txt.5-deep");
ida_prune_table_preload(&UD_centers_555, "lookup-table-5x5x5-step10-UD-centers-stage.txt");
pt_t_centers_cost_only = ida_cost_only_preload("lookup-table-5x5x5-step11-UD-centers-stage-t-center-only.cost-only.txt", 16711681);
pt_x_centers_cost_only = ida_cost_only_preload("lookup-table-5x5x5-step12-UD-centers-stage-x-center-only.cost-only.txt", 16711681);
break;

case UD_OBLIQUE_EDGES_STAGE_666:
break;

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
LR_inner_x_centers_666 = ida_cost_only_preload("lookup-table-6x6x6-step32-LR-inner-x-center-stage.cost-only.txt", 65281);
break;

default:
printf("ERROR: ida_solve() does not yet support this --type\n");
exit(1);
Expand All @@ -993,6 +1035,12 @@ ida_solve (char *cube, unsigned int cube_size, lookup_table_type type)
free(pt_x_centers_cost_only);
pt_x_centers_cost_only = NULL;
break;

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
free(LR_inner_x_centers_666);
LR_inner_x_centers_666 = NULL;
break;

default:
break;
}
Expand All @@ -1011,6 +1059,12 @@ ida_solve (char *cube, unsigned int cube_size, lookup_table_type type)
free(pt_x_centers_cost_only);
pt_x_centers_cost_only = NULL;
break;

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
free(LR_inner_x_centers_666);
LR_inner_x_centers_666 = NULL;
break;

default:
break;
}
Expand Down Expand Up @@ -1045,6 +1099,11 @@ main (int argc, char *argv[])
} else if (strmatch(argv[i], "6x6x6-UD-oblique-edges-stage")) {
type = UD_OBLIQUE_EDGES_STAGE_666;
cube_size_type = 6;

} else if (strmatch(argv[i], "6x6x6-LR-inner-x-centers-oblique-edges-stage")) {
type = LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666,
cube_size_type = 6;

} else {
printf("ERROR: %s is an invalid --type\n", argv[i]);
exit(1);
Expand Down

0 comments on commit 48e80f7

Please sign in to comment.