How do I make an easy calculator? In Miracle c

liunx

Guest
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />strcat(goal,gtop);<br />strcat(goal,gmid);<br />strcat(goal,gbot);<br /> <br />for (line=0; line <300; line++)<br />     {   action[line][0] = 0;<br />         opena  [line][0] = 0;   }<br /><br />strcpy(opena[0],initial);<br /><br />for(;;)<br />{<br />strcpy(current,opena[0]);<br />strcpy(closed[close_num++],current);<br />if (strcmp(goal,current) == 0)<br />     { printf("Solution found : %s \n",action[0]);<br />       exit(0); }<br /> <br />strcpy(store,current);<br />s_pos = -1;<br /><br />for(s_loop=0; s_loop<10; s_loop++)<br />{ if(*(current+s_loop) == '.') s_pos = s_loop; }<br /><br />if (s_pos == -1)<br />     { printf("Illegal input.");<br />       exit(0); }<br /> <br />/* Configuration where empty square goes UP. */<br /> <br />if (s_pos > 2) {<br /><br />current[s_pos] = current[s_pos - 3];<br />*(current + s_pos - 3) = '.';<br />got_flag = 0;<br /> <br />for (closed_check=0; closed_check<=close_num; closed_check++)<br />{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }<br /> <br />if (got_flag == 0) { strcpy(opena[++open_num],current);<br />                     strcpy(action[open_num],action[0]);<br />                     strcat(action[open_num],"U"); } }<br /> <br />/* Configuration where empty square goes DOWN. */<br /> <br />strcpy(current,store);<br /> <br />if (s_pos < 6) {<br /> <br />current[s_pos] = current[s_pos+3];<br />*(current + s_pos + 3) = '.';<br />got_flag = 0;<br /> <br />for (closed_check=0; closed_check<=close_num; closed_check++)<br />{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }<br /> <br />if(got_flag == 0) { strcpy(opena[++open_num],current);<br />                    strcpy(action[open_num],action[0]);<br />                    strcat(action[open_num],"D"); } }<br /> <br />/* Configuration where empty square goes LEFT. */<br /> <br />strcpy(current,store);<br /> <br />if((s_pos!=0) && (s_pos!=3) && (s_pos!=6)) {<br /> <br />current[s_pos] = current[s_pos-1];<br />*(current + s_pos - 1) = '.';<br />got_flag = 0;<br /> <br />for (closed_check=0; closed_check<=close_num; closed_check++)<br />{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }<br /> <br />if(got_flag==0) { strcpy(opena[++open_num],current);<br />                  strcpy(action[open_num],action[0]);<br />                  strcat(action[open_num],"L"); } }<br /> <br />/* Configuration where empty square goes RIGHT. */<br /> <br />strcpy(current,store);<br /> <br />if((s_pos!=2) && (s_pos!=5) && (s_pos!=8)) {<br />current[s_pos] = current[s_pos+1];<br />*(current + s_pos + 1) = '.';<br />got_flag=0;<br /> <br />for(closed_check=0; closed_check<=close_num; closed_check++)<br />{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }<br /> <br />if(got_flag == 0) { strcpy(opena[++open_num],current);<br />                    strcpy(action[open_num],action[0]);<br />                    strcat(action[open_num],"R"); } }<br /> <br />for(shift=0; shift<open_num; shift++)<br />{ strcpy(opena[shift], opena[shift+1]);<br />  strcpy(action[shift],action[shift+1]); } } }<br /><!--c2--></div><!--ec2--><br /><br /><span class='edit'>This post has been edited by <b>PsychoCoder</b>: 5 Apr, 2008 - 01:43 PM</span>
</div>
 
Back
Top