puzzle2D.c
//if the word is found in puzzle, function will return a pointer points to an array contains position and direction; if not, return zero.
if the word is found in puzzle, function will return a pointer points to an array contains position and direction; if not, return zero.
if the word is found in puzzle function will return a pointer points to an array contains position and direction ; if not return zero .
int hash(char puzzletable[][101], char word[], int word_length,FILE *fp3)
{
   double prime=101;
   int i;
   unsigned long long int hashvalue=0;
   int *ptr;
   for(i=0;i<word_length;i++)
   {
       hashvalue += word[i]*(pow(prime, (double)(word_length-i-1)));
   }
   ptr = horizontalright(puzzletable, word_length, hashvalue);
   if (ptr == NULL)
   {
       ptr = horizontalleft(puzzletable, word_length, hashvalue);
       if(ptr == NULL)
       {
           ptr = verticaldown(puzzletable, word_length, hashvalue);
           if (ptr==NULL)
           {
                ptr = verticalup(puzzletable, word_length, hashvalue);
                if (ptr==NULL)
                {
                    ptr = toplefttobottomright(puzzletable, word_length, hashvalue);
                    if (ptr==NULL)
                    {
                        ptr = bottomrightbackwardstotopleft(puzzletable, word_length, hashvalue);
                        if(ptr==NULL)
                        {
                            ptr=bottomlefttotopright(puzzletable, word_length, hashvalue);
                            if(ptr==NULL)
                            {
				ptr = toprightbackwardstobottomleft(puzzletable, word_length, hashvalue);
				if (ptr == NULL)
				    fprintf(fp3,"(0,0);0\n");
				else
				    fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
			    }
                            else
                                fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
                        }
                        else
                            fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
                    }
                    else
                        fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
                }
                else
                    fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
           }
           else
               fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
       }
       else
           fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
   }
   else
       fprintf(fp3,"(%d,%d);%d\n",ptr[0],ptr[1],ptr[2]);
   return 0 ;
}
int hash ( char puzzletable [ ] [ 101 ] , char word [ ] , int word_length , FILE * fp3 ) { double prime = 101 ; int i ; unsigned long long int hashvalue = 0 ; int * ptr ; for ( i = 0 ; i < word_length ; i ++ ) { hashvalue += word [ i ] * ( pow ( prime , ( double ) ( word_length - i - 1 ) ) ) ; } ptr = horizontalright ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = horizontalleft ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = verticaldown ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = verticalup ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = toplefttobottomright ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = bottomrightbackwardstotopleft ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = bottomlefttotopright ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) { ptr = toprightbackwardstobottomleft ( puzzletable , word_length , hashvalue ) ; if ( ptr == NULL ) fprintf ( fp3 , " \n " ) ; else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; } else fprintf ( fp3 , " \n " , ptr [ 0 ] , ptr [ 1 ] , ptr [ 2 ] ) ; return 0 ; }
if the word is found in puzzle, function will return a pointer points to an array contains position and direction; if not, return zero.
if the word is found in puzzle function will return a pointer points to an array contains position and direction ; if not return zero .
//calculate word's hash value //search and compare hash value in 8 different directions