Skip to content

Commit

Permalink
666 move step60 to IDAViaC
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalton76 committed Feb 7, 2019
1 parent 8832c96 commit b5b382d
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 345 deletions.
98 changes: 91 additions & 7 deletions ida_search.c
Expand Up @@ -54,6 +54,7 @@ typedef enum {
// 6x6x6
UD_OBLIQUE_EDGES_STAGE_666,
LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666,
LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666,

// 7x7x7
UD_OBLIQUE_EDGES_STAGE_777,
Expand Down Expand Up @@ -94,10 +95,14 @@ char *LF_centers_cost_only_555 = NULL;


// 6x6x6
struct key_value_pair *LR_inner_x_centers_and_oblique_edges_666 = NULL;
struct key_value_pair *LR_inner_x_centers_and_oblique_edges_stage_666 = NULL;
char *LR_inner_x_centers_666 = NULL;
char *LR_oblique_edges_666 = NULL;

struct key_value_pair *LFRB_inner_x_centers_and_oblique_edges_solve_666 = NULL;
char *LR_inner_x_centers_and_oblique_edges_solve_666 = NULL;
char *FB_inner_x_centers_and_oblique_edges_solve_666 = NULL;


// 7x7x7
struct key_value_pair *step40_777 = NULL;
Expand Down Expand Up @@ -421,6 +426,12 @@ init_cube(char *cube, int size, lookup_table_type type, char *kociemba)
print_cube(cube, size);
break;

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

case CENTERS_SOLVE_555:
// Remember what the cube looked like so we can restore the edges
memcpy(cube_copy, cube, sizeof(char) * array_size);
Expand Down Expand Up @@ -605,7 +616,8 @@ ida_prune_table_preload (struct key_value_pair **hashtable, char *filename)
}


} else if (strmatch(filename, "lookup-table-6x6x6-step30-LR-inner-x-centers-oblique-edges-stage.txt")) {
} else if (strmatch(filename, "lookup-table-6x6x6-step30-LR-inner-x-centers-oblique-edges-stage.txt") ||
strmatch(filename, "lookup-table-6x6x6-step60-LFRB-solve-inner-x-center-and-oblique-edges.txt.3-deep")) {

while (fgets(buffer, BUFFER_SIZE, fh_read) != NULL) {
// 0..11 are the state
Expand Down Expand Up @@ -769,10 +781,18 @@ ida_heuristic (char *cube, lookup_table_type type, unsigned int max_cost_to_goal
return ida_heuristic_LR_inner_x_centers_and_oblique_edges_stage_666(
cube,
max_cost_to_goal,
&LR_inner_x_centers_and_oblique_edges_666,
&LR_inner_x_centers_and_oblique_edges_stage_666,
LR_inner_x_centers_666,
LR_oblique_edges_666);

case LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666:
return ida_heuristic_LFRB_inner_x_centers_and_oblique_edges_solve_666(
cube,
max_cost_to_goal,
&LFRB_inner_x_centers_and_oblique_edges_solve_666,
LR_inner_x_centers_and_oblique_edges_solve_666,
FB_inner_x_centers_and_oblique_edges_solve_666);

// 7x7x7
case UD_OBLIQUE_EDGES_STAGE_777:
return ida_heuristic_UD_oblique_edges_stage_777(cube, max_cost_to_goal);
Expand Down Expand Up @@ -1091,6 +1111,9 @@ ida_search_complete (
case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
return ida_search_complete_LR_inner_x_centers_and_oblique_edges_stage(cube);

case LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666:
return ida_search_complete_LFRB_inner_x_centers_and_oblique_edges_solve(cube);

// 7x7x7
case UD_OBLIQUE_EDGES_STAGE_777:
return ida_search_complete_UD_oblique_edges_stage_777(cube);
Expand Down Expand Up @@ -1295,6 +1318,53 @@ step_allowed_by_ida_search (lookup_table_type type, move_type move)
return 1;
}

case LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666:
switch (move) {
// do not mess up staged centers
case threeUw:
case threeUw_PRIME:
case threeDw:
case threeDw_PRIME:
case threeLw:
case threeLw_PRIME:
case threeRw:
case threeRw_PRIME:
case threeFw:
case threeFw_PRIME:
case threeBw:
case threeBw_PRIME:
case threeRw2:
case threeLw2:
case threeFw2:
case threeBw2:
case Uw:
case Uw_PRIME:
case Dw:
case Dw_PRIME:
case Lw:
case Lw_PRIME:
case Rw:
case Rw_PRIME:
case Fw:
case Fw_PRIME:
case Bw:
case Bw_PRIME:

// can skip these for 6x6x6 cubes
//case threeLw:
//case threeLw_PRIME:
//case threeLw2:
//case threeDw:
//case threeDw_PRIME:
case threeDw2:
//case threeBw:
//case threeBw_PRIME:
//case threeBw2:
return 0;
default:
return 1;
}

// 7x7x7
case UD_OBLIQUE_EDGES_STAGE_777:
switch (move) {
Expand Down Expand Up @@ -2185,9 +2255,14 @@ free_prune_tables()
ULFRBD_centers_555 = NULL;
}

if (LR_inner_x_centers_and_oblique_edges_666 == NULL) {
free(LR_inner_x_centers_and_oblique_edges_666);
LR_inner_x_centers_and_oblique_edges_666 = NULL;
if (LR_inner_x_centers_and_oblique_edges_stage_666 == NULL) {
free(LR_inner_x_centers_and_oblique_edges_stage_666);
LR_inner_x_centers_and_oblique_edges_stage_666 = NULL;
}

if (LFRB_inner_x_centers_and_oblique_edges_solve_666 == NULL) {
free(LFRB_inner_x_centers_and_oblique_edges_solve_666);
LFRB_inner_x_centers_and_oblique_edges_solve_666 = NULL;
}
}

Expand Down Expand Up @@ -2259,11 +2334,16 @@ ida_solve (
break;

case LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666:
ida_prune_table_preload(&LR_inner_x_centers_and_oblique_edges_666, "lookup-table-6x6x6-step30-LR-inner-x-centers-oblique-edges-stage.txt");
ida_prune_table_preload(&LR_inner_x_centers_and_oblique_edges_stage_666, "lookup-table-6x6x6-step30-LR-inner-x-centers-oblique-edges-stage.txt");
LR_oblique_edges_666 = ida_cost_only_preload("lookup-table-6x6x6-step31-LR-oblique-edges-stage.hash-cost-only.txt", 165636908);
LR_inner_x_centers_666 = ida_cost_only_preload("lookup-table-6x6x6-step32-LR-inner-x-center-stage.cost-only.txt", 65281);
break;

case LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666:
ida_prune_table_preload(&LFRB_inner_x_centers_and_oblique_edges_solve_666, "lookup-table-6x6x6-step60-LFRB-solve-inner-x-center-and-oblique-edges.txt.3-deep");
LR_inner_x_centers_and_oblique_edges_solve_666 = ida_cost_only_preload("lookup-table-6x6x6-step61-LR-solve-inner-x-center-and-oblique-edges.cost-only.txt", 16773121);
FB_inner_x_centers_and_oblique_edges_solve_666 = ida_cost_only_preload("lookup-table-6x6x6-step62-FB-solve-inner-x-center-and-oblique-edges.cost-only.txt", 16773121);

// 7x7x7
case UD_OBLIQUE_EDGES_STAGE_777:
case LR_OBLIQUE_EDGES_STAGE_777:
Expand Down Expand Up @@ -2382,6 +2462,10 @@ main (int argc, char *argv[])
type = LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_STAGE_666,
cube_size_type = 6;

} else if (strmatch(argv[i], "6x6x6-LFRB-solve-inner-x-center-and-oblique-edges")) {
type = LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_SOLVE_666,
cube_size_type = 6;

// 7x7x7
} else if (strmatch(argv[i], "7x7x7-UD-oblique-edges-stage")) {
type = UD_OBLIQUE_EDGES_STAGE_777;
Expand Down
133 changes: 128 additions & 5 deletions ida_search_666.c
Expand Up @@ -65,6 +65,30 @@ unsigned int LFRB_oblique_edges_666[NUM_LFRB_OBLIQUE_EDGES_666] = {
171, 172
};

unsigned int LR_inner_x_centers_and_oblique_edges_666[NUM_LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666] = {
45, 46,
50, 51, 52, 53,
56, 57, 58, 59,
63, 64,

117, 118,
122, 123, 124, 125,
128, 129, 130, 131,
135, 136,
};

unsigned int FB_inner_x_centers_and_oblique_edges_666[NUM_FB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666] = {
81, 82,
86, 87, 88, 89,
92, 93, 94, 95,
99, 100,

153, 154,
158, 159, 160, 161,
164, 165, 166, 167,
171, 172
};

unsigned int LFRB_inner_x_centers_and_oblique_edges_666[NUM_LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666] = {
45, 46,
50, 51, 52, 53,
Expand Down Expand Up @@ -169,7 +193,7 @@ struct ida_heuristic_result
ida_heuristic_LR_inner_x_centers_and_oblique_edges_stage_666 (
char *cube,
unsigned int max_cost_to_goal,
struct key_value_pair **LR_inner_x_centers_and_oblique_edges_666,
struct key_value_pair **LR_inner_x_centers_and_oblique_edges_stage_666,
char *LR_inner_x_centers_cost_666,
char *LR_oblique_edges_cost_666)
{
Expand Down Expand Up @@ -229,7 +253,7 @@ ida_heuristic_LR_inner_x_centers_and_oblique_edges_stage_666 (
int MAX_DEPTH = 2;

struct key_value_pair *hash_entry = NULL;
hash_entry = hash_find(LR_inner_x_centers_and_oblique_edges_666, result.lt_state);
hash_entry = hash_find(LR_inner_x_centers_and_oblique_edges_stage_666, result.lt_state);

if (hash_entry) {
cost_to_goal = hash_entry->value;
Expand All @@ -246,8 +270,7 @@ ida_heuristic_LR_inner_x_centers_and_oblique_edges_stage_666 (
int
ida_search_complete_LR_inner_x_centers_and_oblique_edges_stage (char *cube)
{
if ((
// First check if the inner x-centers are staged
if (( // First check if the inner x-centers are staged
(cube[51] == '1' &&
cube[52] == '1' &&
cube[57] == '1' &&
Expand All @@ -266,7 +289,107 @@ ida_search_complete_LR_inner_x_centers_and_oblique_edges_stage (char *cube)
cube[129] == '0' &&
cube[130] == '0')) &&

// Then check if all LR oblique edges are paired
// Then check if all oblique edges are paired
get_unpaired_obliques_count_666(cube) == 0) {
return 1;
} else {
return 0;
}
}


// ============================================================================
// step60
// ============================================================================
struct ida_heuristic_result
ida_heuristic_LFRB_inner_x_centers_and_oblique_edges_solve_666(
char *cube,
unsigned int max_cost_to_goal,
struct key_value_pair **LFRB_inner_x_centers_and_oblique_edges_solve_666,
char *LR_inner_x_centers_and_oblique_edges_solve_666,
char *FB_inner_x_centers_and_oblique_edges_solve_666)
{
unsigned long long LR_state = 0;
unsigned long long LR_cost = 0;
unsigned long long FB_state = 0;
unsigned long long FB_cost = 0;
unsigned long long cost_to_goal = 0;
unsigned long long state = 0;
int cube_index;
struct ida_heuristic_result result;

// get state of LR inner x-centers and oblique edges
for (int i = 0; i < NUM_LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666; i++) {
if (cube[LR_inner_x_centers_and_oblique_edges_666[i]] == '1') {
LR_state |= 0x1;
}
LR_state <<= 1;
}
LR_state >>= 1;
LR_cost = hex_to_int(LR_inner_x_centers_and_oblique_edges_solve_666[LR_state]);

// get state of FB inner x-centers and oblique edges
for (int i = 0; i < NUM_FB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666; i++) {
if (cube[FB_inner_x_centers_and_oblique_edges_666[i]] == '1') {
FB_state |= 0x1;
}
FB_state <<= 1;
}
FB_state >>= 1;
FB_cost = hex_to_int(FB_inner_x_centers_and_oblique_edges_solve_666[FB_state]);

// get state of LFRB inner x-centers and oblique edges
for (int i = 0; i < NUM_LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666; i++) {
if (cube[LFRB_inner_x_centers_and_oblique_edges_666[i]] == '1') {
state |= 0x1;
}
state <<= 1;
}
state >>= 1;

// 00019b267fff is 12 chars
sprintf(result.lt_state, "%012llx", state);
cost_to_goal = max(LR_cost, FB_cost);

// dwalton
// printf("LR_state %llu, LR_cost %llu, FB_state %llu, FB_cost %llu, state %s, cost_to_goal %llu\n", LR_state, LR_cost, FB_state, FB_cost, result.lt_state, cost_to_goal);
// exit(0);

if (cost_to_goal > 0) {
// The step60 table we loaded is 3-deep
int MAX_DEPTH = 3;

struct key_value_pair *hash_entry = NULL;
hash_entry = hash_find(LFRB_inner_x_centers_and_oblique_edges_solve_666, result.lt_state);

if (hash_entry) {
cost_to_goal = hash_entry->value;
} else {
// Not admissible but much faster
cost_to_goal = max((int) cost_to_goal * 1.2, MAX_DEPTH+1);
//cost_to_goal = max(cost_to_goal, MAX_DEPTH + 1);
}
}

result.cost_to_goal = cost_to_goal;
return result;
}


int
ida_search_complete_LFRB_inner_x_centers_and_oblique_edges_solve (char *cube)
{
if (// First check if the inner x-centers are solved
cube[51] == '1' &&
cube[52] == '1' &&
cube[57] == '1' &&
cube[58] == '1' &&
cube[87] == '1' &&
cube[88] == '1' &&
cube[93] == '1' &&
cube[94] == '1' &&

// Then check if all oblique edges are paired
get_unpaired_obliques_count_666(cube) == 0) {
return 1;
} else {
Expand Down
13 changes: 13 additions & 0 deletions ida_search_666.h
Expand Up @@ -8,6 +8,9 @@

#define NUM_LFRB_INNER_X_CENTERS_666 16
#define NUM_LFRB_OBLIQUE_EDGES_666 32

#define NUM_LR_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666 24
#define NUM_FB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666 24
#define NUM_LFRB_INNER_X_CENTERS_AND_OBLIQUE_EDGES_666 48

struct ida_heuristic_result ida_heuristic_UD_oblique_edges_stage_666(
Expand All @@ -26,4 +29,14 @@ struct ida_heuristic_result ida_heuristic_LR_inner_x_centers_and_oblique_edges_s
);
int ida_search_complete_LR_inner_x_centers_and_oblique_edges_stage(char *cube);


struct ida_heuristic_result ida_heuristic_LFRB_inner_x_centers_and_oblique_edges_solve_666(
char *cube,
unsigned int max_cost_to_goal,
struct key_value_pair **LFRB_inner_x_centers_and_oblique_edges_solve_666,
char *LR_inner_x_centers_and_oblique_edges_solve_666,
char *FB_inner_x_centers_and_oblique_edges_solve_666
);
int ida_search_complete_LFRB_inner_x_centers_and_oblique_edges_solve(char *cube);

#endif /* _IDA_SEARCH_666_H */

0 comments on commit b5b382d

Please sign in to comment.