Exemplo n.º 1
0
int main(int argc, char **argv)
{

	//int nums[N] = {1, 5, 1, 15 ,15 ,6 ,7 ,8 ,4 ,9};
	int succ_buf[BF][N+1][N];

	start = init(argc, argv);

	expand_a_node(start->loc, succ_buf);

	printf("intial:\n");
	print_a_node(start);
	print_array("after down move", succ_buf[0]);
	print_array("after right move", succ_buf[1]);
	print_array("after up move", succ_buf[2]);
	print_array("after left move", succ_buf[3]);
	/*
	int nums[N][N], len;
	init_2D(nums);
	print_array(nums);

	//find elem in 2D array
	int i,j, found = 0;
	for(i = 0; (i < N) && !found; i++)
	{
		for(j = 0; (j < N) && !found; j++)
		{
			if(nums[i][j] == 2)
			{
				printf("i:%d j:%d\n", i, j);
				found = 1;
			}
		}
	}
	i--;
	j--;

	//perform dn move
	int temp = nums[i][j];
	nums[i][j] = nums[i+1][j];
	nums[i+1][j] = temp;

	printf("After swap:\n");
	print_array(nums);
	*/

	/*
	len = length(goal);
	printf("len: %d\n", len);
	*/

	return 0;
}
Exemplo n.º 2
0
Arquivo: fifteen.c Projeto: dnlzz/hw7
/* fifteen 0 1 2 4 5 6 3 8 9 10 7 12 13 14 11 15 astar */
struct node *initialize(int argc, char **argv){
  int i,j,k,npe,n,idx,gidx,inv;
   struct node *tp;

   tp=(struct node *) malloc(sizeof(struct node));
   idx = 1;
   for (j=0;j<N;j++)
     for (k=0;k<N;k++) tp->board[j][k]=atoi(argv[idx++]);
   for (k=0;k<N;k++) tp->board[N][k]=0;	/* set f,g,h of initial state to 0 */
   tp->next=NULL;
   start=tp;

   printf("init state: \n");
   print_a_node(start);

   tp=(struct node *) malloc(sizeof(struct node));
   gidx = 1;
   for (j=0;j<N;j++)
     for (k=0;k<N;k++) tp->board[j][k] = gidx++;
   tp->board[N-1][N-1] = 0;		/* empty tile=0 */
   for (k=0;k<N;k++) tp->board[N][k]=0;	/* set f,g,h of goal state to 0 */
   tp->next=NULL;
   goal=tp;

   printf("goal state: \n");
   print_a_node(goal);

   strcpy(strategy_s,argv[idx]);
   if (strcmp(strategy_s,"dfs")==0) strategy=DFS;
   else if (strcmp(strategy_s,"bfs")==0) strategy = BFS;
   else if (strcmp(strategy_s,"best")==0) strategy=BEST;
   else if (strcmp(strategy_s,"bb")==0) strategy=BB;
   else if (strcmp(strategy_s,"astar")==0) strategy=ASTAR;
   else strategy=UNKNOWN;
   printf("strategy=%s\n",strategy_s);

   printf("strategy=%d\n",strategy);
   
   return start;
}
Exemplo n.º 3
0
Arquivo: fifteen.c Projeto: dnlzz/hw7
void print_nodes(struct node *cp/*,char name[20]*/) {
  int i;
  //printf("%s:\n",name);
  while (cp) { print_a_node(cp); cp=cp->next; }
}