void d1s1(int n){
    int vald1s1 = 0;
    int vald1s2 = 0;
    int vald2s1 = 0;
    int vald2s2 = 0;
    int n1 = n-1;
    int ij ;
    int stid1s1[MAX],stjd1s1[MAX],stid1s1_tp=-1;
    int stid1s2[MAX],stjd1s2[MAX],stid1s2_tp=-1;
    int stid2s1[MAX],stjd2s1[MAX],stid2s1_tp=-1;
    int stid2s2[MAX],stjd2s2[MAX],stid2s2_tp=-1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            ij = i-j;
            update(stid1s1,stjd1s1,ij,j,vald1s1,stid1s1_tp);
            if(i<(n1)){
               update(stid1s2,stjd1s2,n1-j,n1-ij,vald1s2,stid1s2_tp);
            }
            update(stid2s1,stjd2s1,j,n1-ij,vald2s1,stid2s1_tp);
            if(i<(n1)){
              update(stid2s2,stjd2s2,n1-ij,j,vald2s2,stid2s2_tp);
            }
        }
        emptyStacks(stid1s1,stjd1s1,vald1s1,stid1s1_tp);
        emptyStacks(stid1s2,stjd1s2,vald1s2,stid1s2_tp);
        emptyStacks(stid2s1,stjd2s1,vald2s1,stid2s1_tp);
        emptyStacks(stid2s2,stjd2s2,vald2s2,stid2s2_tp);
    }
}
示例#2
0
static int
resetProlog(int clear_stacks)
{ GET_LD
  IOSTREAM *in = Suser_input;

  if ( Sferror(in) )
  { Sclearerr(in);
    LD->prompt.next = TRUE;
  }

  Scurin  = in;
  Scurout = Suser_output;

  PL_clear_exception();
  resetTracer();

  if ( clear_stacks )
  { if ( !LD->gvar.nb_vars )		/* we would loose nb_setval/2 vars */
      emptyStacks();

    gc_status.blocked        = 0;
    LD->shift_status.blocked = 0;
    LD->in_arithmetic        = 0;
    LD->in_print_message     = 0;
  }

#ifdef O_LIMIT_DEPTH
  depth_limit   = (uintptr_t)DEPTH_NO_LIMIT;
#endif

  updateAlerted(LD);

  return TRUE;
}
示例#3
0
int main(){
    int ch='X';
//Creates the 3 stacks; initially empty (head points to tail)
    headA=initLLNode(100);
	tailA=initLLNode(100);
	headA->next=tailA;
	headB=initLLNode(101);
	tailB=initLLNode(101);
	headB->next=tailB;
	headC=initLLNode(102);
	tailC=initLLNode(102);
	headC->next=tailC;

//repeat the prompt until the user enters the ESC key.
//(esc corresponds to ASCII value 27, so we repeat while ch is not equal to 27)
	while(ch!=27){
		if(ch==49)play(); //if 1 entered, start play mode
		if(ch==50)Demo(); //if 2 entered, demo mode
		if(ch==51)hof();  //if 3 entered, go to hall of face
		system("cls");    //this clears the screen
		printf("Tower of Hanoi\n"
			"==============================\n"
			"Press 1 to go to Game Mode.\n"
			"Press 2 to go to Demo Mode.\n"
			"Press 3 to go to Hall of Fame.\n"
			"Press ESC to Exit.\n");
        emptyStacks();    //initalizes the stacks (explained at function definition)
		ch = getch();     //gets user input
	}
	return 0;
}