/*前の記事のさらに続き*/
/*まだまだ続く*/
void heuristic(struct node *cube) { char i,j,k,p=1,q; unsigned int color[6], cornor=0, edge=0, hash, buff=0; struct node *node; if(cube->surface[0][0][0]!=goal.surface[0][0][0] || /*コーナーキューブの位置,向きが違ってる個数を数える*/ cube->surface[2][2][0]!=goal.surface[2][2][0] || cube->surface[1][2][2]!=goal.surface[1][2][2]) cornor++; if(cube->surface[0][0][2]!=goal.surface[0][0][2] || cube->surface[2][2][2]!=goal.surface[2][2][2] || cube->surface[4][2][0]!=goal.surface[4][2][0]) cornor++; if(cube->surface[0][2][0]!=goal.surface[0][2][0] || cube->surface[1][2][0]!=goal.surface[1][2][0] || cube->surface[3][0][0]!=goal.surface[3][0][0]) cornor++; if(cube->surface[0][2][2]!=goal.surface[0][2][2] || cube->surface[4][2][2]!=goal.surface[4][2][2] || cube->surface[3][0][2]!=goal.surface[3][0][2]) cornor++; if(cube->surface[5][0][0]!=goal.surface[5][0][0] || cube->surface[3][2][0]!=goal.surface[3][2][0] || cube->surface[1][0][0]!=goal.surface[1][0][0]) cornor++; if(cube->surface[5][0][2]!=goal.surface[5][0][2] || cube->surface[3][2][2]!=goal.surface[3][2][2] || cube->surface[4][0][2]!=goal.surface[4][0][2]) cornor++; if(cube->surface[5][2][0]!=goal.surface[5][2][0] || cube->surface[2][0][0]!=goal.surface[2][0][0] || cube->surface[1][0][2]!=goal.surface[1][0][2]) cornor++; if(cube->surface[5][2][2]!=goal.surface[5][2][2] || cube->surface[2][0][2]!=goal.surface[2][0][2] || cube->surface[4][0][0]!=goal.surface[4][0][0]) cornor++; if(cube->surface[0][1][0]!=goal.surface[0][1][0] || /*エッジキューブの向き,位置が違ってるものを数える*/ cube->surface[1][2][1]!=goal.surface[1][2][1]) edge++; if(cube->surface[0][2][1]!=goal.surface[0][2][1] || cube->surface[3][0][1]!=goal.surface[3][0][1]) edge++; if(cube->surface[0][1][2]!=goal.surface[0][1][2] || cube->surface[4][2][1]!=goal.surface[4][2][1]) edge++; if(cube->surface[0][0][1]!=goal.surface[0][0][1] || cube->surface[2][2][1]!=goal.surface[2][2][1]) edge++; if(cube->surface[2][1][0]!=goal.surface[2][1][0] || cube->surface[1][1][2]!=goal.surface[1][1][2]) edge++; if(cube->surface[2][1][2]!=goal.surface[2][1][2] || cube->surface[4][1][0]!=goal.surface[4][1][0]) edge++; if(cube->surface[3][1][0]!=goal.surface[3][1][0] || cube->surface[1][1][0]!=goal.surface[1][1][0]) edge++; if(cube->surface[3][1][2]!=goal.surface[3][1][2] || cube->surface[4][1][2]!=goal.surface[4][1][2]) edge++; if(cube->surface[5][1][0]!=goal.surface[5][1][0] || cube->surface[1][0][1]!=goal.surface[1][0][1]) edge++; if(cube->surface[5][2][1]!=goal.surface[5][2][1] || cube->surface[2][0][1]!=goal.surface[2][0][1]) edge++; if(cube->surface[5][1][2]!=goal.surface[5][1][2] || cube->surface[4][0][1]!=goal.surface[4][0][1]) edge++; if(cube->surface[5][0][1]!=goal.surface[5][0][1] || cube->surface[3][2][1]!=goal.surface[3][2][1]) edge++; for(i=0;i<6;i++)
surface[k][i][j]) color[k]++; /*色が違ってる数を数える*/ for(i=0;i<6;i++)
heuristic=0; else if(hash==212) /*212だったらあと1手*/ cube->heuristic=1; else if(hash==1576 || hash==959 || hash==873) /*あと2手*/ cube->heuristic=2; else if(hash==2610 || hash==2448 || hash==1045 || hash==280 || hash==2529 || hash==1808 || hash==1680 || hash==2000 || hash==1088 || hash==1002 || hash==314 || hash==2205 || hash==2367 || hash==2124 || hash==1936 || hash==2286 || hash==1552 || hash==246 || hash==1335) /*あと3手*/ cube->heuristic=3; else if(hash==2691 || hash==3900 || hash==3312 || hash==3134 || hash==3401 || hash==3223 || hash==3706 || hash==2956 || hash==3512 || hash==2514 || hash==1131 || hash==530 || hash==1872 || hash==1174 || hash==556 || hash==2064 || hash==504 || hash==163 || hash==1554 || hash==631 || hash==410 || hash==1364 || hash==3609 || hash==3045 || hash==2772 || hash==1611 || hash==3318 || hash==1440 || hash==2280 || hash==2934 || hash==2096 || hash==2689 || hash==3579 || hash==3015 || hash==2853 || hash==2226 || hash==3124 || hash==3490 || hash==693 || hash==2867 || hash==1217 || hash==724 || hash==2778 || hash==2128 || hash==2192 || hash==1260 || hash==1414 || hash==1214 || hash==662 || hash==1500 || hash==248 || hash==600 || hash==732 || hash==2739 || hash==3027 || hash==916 || hash==3221 || hash==1541 || hash==3096 || hash==2356 || hash==2930 || hash==2736 || hash==1665 || hash==2358 || hash==2511 || hash==189 || hash==1497 || hash==485) /*あと4手*/ cube->heuristic=4; else if(hash==2207 || hash==1164 || hash==2360 || hash==1337 || hash==738 || hash==2353 || hash==4094 || hash==3803 || hash==3997 || hash==4191 || hash==2426 || hash==1744 || hash==3164 || hash==1383 || hash==2909 || hash==2218 || hash==2147 || hash==1288 || hash==591 || hash==4288 || hash==3415 || hash==2431 || hash==2289 || hash==1386 || hash==997 || hash==1901 || hash==1256 || hash==2134 || hash==2436 || hash==3249 || hash==2994 || hash==2228 || hash==1771 || hash==1826 || hash==1435 || hash==1190 || hash==2499 || hash==2824 || hash==2592 || hash==1239 || hash==1555 || hash==1390 || hash==1706 || hash==2500 || hash==2161 || hash==1602 || hash==1668 || hash==1038 || hash==1641 || hash==1663 || hash==715 || hash==1785 || hash==2572 || hash==2645 || hash==608 || hash==582 || hash==1445 || hash==202 || hash==263 || hash==1725 || hash==1314 || hash==1782 || hash==755 || hash==3177 || hash==2718 || hash==786 || hash==817 || hash==804 || hash==1720 || hash==2320 || hash==1839 || hash==1303 || hash==2256 || hash==1896 || hash==1079 || hash==2076 || hash==639 || hash==876 || hash==452 || hash==478 || hash==752 || hash==569 || hash==789 || hash==1616 || hash==705 || hash==956 || hash==1072 || hash==2904 || hash==2748 || hash==1210 || hash==1118 || hash==3668 || hash==3757 || hash==1464 || hash==672 || hash==3846 || hash==3258 || hash==2791 || hash==1934 || hash==2654 || hash==2094 || hash==2826 || hash==3060 || hash==3079 || hash==1484 || hash==974 || hash==297 || hash==1011 || hash==900 || hash==348 || hash==1846 || hash==3339 || hash==2864 || hash==840 || hash==948 || hash==2384 || hash==1953 || hash==1830 || hash==2031 || hash==634 || hash==264 || hash==229 || hash==1092 || hash==1614 || hash==1419 || hash==2484 || hash==408 || hash==2833 || hash==1759 || hash==707 || hash==863 || hash==1863 || hash==2005 || hash==475 || hash==538 || hash==826 || hash==937 || hash==1141 || hash==1043 || hash==2061 || hash==938 || hash==1960 || hash==830 || hash==696 || hash==1188 || hash==1514 || hash==753 || hash==1225 || hash==2362 || hash==2281 || hash==331 || hash==3334 || hash==2569 || hash==562 || hash==1775 || hash==3504 || hash==1564 || hash==984 || hash==1120 || hash==660 || hash==3419 || hash==2354 || hash==606 || hash==1388 || hash==1114 || hash==864 || hash==1488 || hash==1968 || hash==2062 || hash==2208 || hash==2027 || hash==1885 || hash==1326 || hash==2046 || hash==540 || hash==998 || hash==1094 || hash==834) cube->heuristic=5; /*あと5手*/ else cube->heuristic=6; cube->expectation=cube->heuristic+cube->cost; cube->hash=1.0; for(i=0;i<6;i++)
hash*=sin(color[i]+i*0.5); /*前と同じノードを展開しないためのハッシュ値を計算*/ cube->hash*=edge*cornor; node=root.nodelist; /*ノードリストをたどる*/ while(node!=cube && p){ if(node->hash==cube->hash){ /*同じハッシュ値をもつノードがあったら*/ q=0; for(k=0;k<5;k++)
surface[k][i][j]!=node->surface[k][i][j]) /*状態を詳しく比較して*/ q++; if(!q){ p=0; cube->revleaf->nextleaf=cube->nextleaf; /*全く同じなら,このノードをリーフリストからはずす*/ cube->nextleaf->revleaf=cube->revleaf; } } node=node->nodelist; } }
/*まだまだ続く*/
※コメント投稿者のブログIDはブログ作成者のみに通知されます