Example #1
0
//static void updateBlockMasks ( PUZZLE *puzzle, int row, int column, int entry )
static void updateBlockMasks ( PUZZLE *puzzle, int row, int column, short *pentry )

{
   int	rowMax = row + 3 - ( row % 3 );
   int	columnMax = column + 3 - ( column % 3 );
   //int	mask = ~digit2bit ( entry );
   short	mask = ~digit2bit ( star(pentry) );
   short	*pmask = &mask;
   IFT(pmask, pentry);

#if	defined(DEBUG)
   //fprintf ( logFile, "updateBlockMasks ( %p, %d, %d, %d ) {\n", puzzle, row,
   fprintf ( logFile, "updateBlockMasks ( %p, %d, %d, %p ) {\n", puzzle, row,
								column, pentry );
   fflush ( logFile );
#endif

   for ( row = rowMax - 3; row < rowMax; ++row ) {

	for ( column = columnMax - 3; column < columnMax; ++column ) {

		puzzle->masks [row][column] &= mask;
		IFT(puzzle->pmasks [row][column], pmask);
	}
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} /* updateBlockMasks () */\n" );
   fflush ( logFile );
#endif
}
Example #2
0
//static void updateColumnMasks ( PUZZLE *puzzle, int column, int entry )
static void updateColumnMasks ( PUZZLE *puzzle, int column, short *pentry )

{
   int	row;
   //int	mask = ~digit2bit ( entry );
   short	mask = ~digit2bit ( star(pentry) );
   short	*pmask = &mask;
   IFT(pmask, pentry);

#if	defined(DEBUG)
   //fprintf ( logFile, "updateColumnMasks ( %p, %d, %d ) {\n", puzzle, column,
   fprintf ( logFile, "updateColumnMasks ( %p, %d, %p ) {\n", puzzle, column,
									pentry );
   fflush ( logFile );
#endif

   for ( row = 0; row < 9; ++row ) {

	puzzle->masks [row][column] &= mask;
	IFT(puzzle->pmasks [row][column], pmask);
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} /* updateColumnMasks () */\n" );
   fflush ( logFile );
#endif
}
Example #3
0
//static int crossHatch ( int *masks )
static int crossHatch ( short **pmasks )

{
   int	progress = 0;
   //int	solutions [9];
   short	solutions [9];
   short	*psolutions [9];
   int	k;
   for ( k = 0; k < 9; k++ ) {
   	psolutions [k] = &solutions[k];
   }
   int	i;

#if	defined(DEBUG)
   //fprintf ( logFile, "crossHatch ( %04X ) {\n", (unsigned int)masks );
   fprintf ( logFile, "crossHatch ( %p ) {\n", pmasks );
   fflush ( logFile );
#endif

   for ( i = 0; i < 9; ++i ) {

	int	j;

	//solutions [i] = masks [i];
	solutions [i] = star(pmasks [i]);
	IFT(psolutions [i], pmasks [i]);

	//for ( j = 0; j < 9; ++j ) if ( j != i ) solutions [i] &= ~masks [j];
	for ( j = 0; j < 9; ++j ) {
		if ( j != i ) {
			solutions [i] &= ~(star(pmasks [j]));
			IFT(psolutions [i], pmasks [j]);
		}
	}
		
   }

   for ( i = 0; i < 9; ++i ) {

	//if ( masks [i] = bit2digit ( solutions [i] ) ) ++progress;
	if ( STAR(pmasks [i]) = bit2digit ( solutions [i] ) ) ++progress;
	IFT(pmasks [i], psolutions [i]);
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* crossHatch () */\n", progress );
   fflush ( logFile );
#endif

   return ( progress );
}
Example #4
0
//static int makeEntry ( PUZZLE *puzzle, int i, int j, int entry )
static int makeEntry ( PUZZLE *puzzle, int i, int j, short *pentry )

{
   int	status = 0;
   //int	bit = digit2bit ( entry );
   short	bit = digit2bit ( star(pentry) );
   short	*pbit = &bit;
   IFT(pbit, pentry);

#if	defined(DEBUG)
   //fprintf ( logFile, "makeEntry ( %p, %d, %d, %d ) {\n", puzzle, i, j, entry );
   fprintf ( logFile, "makeEntry ( %p, %d, %d, %p ) {\n", puzzle, i, j, pentry );
   fflush ( logFile );
#endif

   /* Is this a legal entry? */
   if ( puzzle->rowMasks [i] & puzzle->columnMasks [j]
				& puzzle->blockMasks [i/3][j/3] & bit ) {
	status = 1;
	puzzle->rowMasks [i] ^= bit;
	puzzle->columnMasks [j] ^= bit;
	puzzle->blockMasks [i/3][j/3] ^= bit;
	//puzzle->grid [i][j] = entry;
	puzzle->grid [i][j] = star(pentry);
	puzzle->masks [i][j] = 0;

	IFT(puzzle->prowMasks [i], pbit);
	IFT(puzzle->pcolumnMasks [j], pbit);
	IFT(puzzle->pblockMasks [i/3][j/3], pbit);
	IFT(puzzle->pgrid [i][j], pentry);

	if ( puzzle->history ) pushHistory ( puzzle->history, i, j );
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* makeEntry () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #5
0
//static int getBlockMasks ( PUZZLE *puzzle, int row, int column, int *masks )
static int getBlockMasks ( PUZZLE *puzzle, int row, int column, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getBlockMasks ( %p, %d, %d, %p ) {\n", puzzle, row,
								//column, masks );
   fprintf ( logFile, "getBlockMasks ( %p, %d, %d, %p ) {\n", puzzle, row,
								column, pmasks );
   fflush ( logFile );
#endif

   /* Make sure the 3x3 block is not already full. */
   if ( puzzle->blockMasks [row][column] ) {

	int	rowMax = ( row + 1 ) * 3;
	int	columnMax = ( column + 1 ) * 3;
	int	k = 0;
	//int	mask = 0;
	short	mask = 0;
	int	i;

	status = 1;

	/* Make masks for the 3x3 block. */
	for ( i = rowMax - 3; i < rowMax; ++i ) {

		int	j;

		for ( j = columnMax - 3; j < columnMax; ++j ) {

			//masks [k] = puzzle->masks [i][j];
			STAR(pmasks [k]) = puzzle->masks [i][j];
			IFT(pmasks [k], puzzle->pmasks [i][j]);
			//mask |= masks [k];
			mask |= star(pmasks [k]);

			++k;
		}
	}

	if ( mask != puzzle->blockMasks [row][column] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getBlockMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #6
0
//static int getColumnMasks ( PUZZLE *puzzle, int column, int *masks )
static int getColumnMasks ( PUZZLE *puzzle, int column, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getColumnMasks ( %p, %d, %p ) {\n", puzzle, column,
									//masks );
   fprintf ( logFile, "getColumnMasks ( %p, %d, %p ) {\n", puzzle, column,
									pmasks );
   fflush ( logFile );
#endif

   /* Make sure the column is not already filled. */
   if ( puzzle->columnMasks [column] ) {

	//int	mask = 0;
	short	mask = 0;
	int	row;

	status = 1;

	/* Make masks for the column. */
	for ( row = 0; row < 9; ++row ) {

		//masks [row] = puzzle->masks [row][column];
		STAR(pmasks [row]) = puzzle->masks [row][column];
		IFT(pmasks [row], puzzle->pmasks [row][column]);
		//mask |= masks [row];
		mask |= star(pmasks [row]);
	}

	if ( mask != puzzle->columnMasks [column] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getColumnMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #7
0
//static int getRowMasks ( PUZZLE *puzzle, int row, int *masks )
static int getRowMasks ( PUZZLE *puzzle, int row, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getRowMasks ( %p, %d, %p ) {\n", puzzle, row, masks );
   fprintf ( logFile, "getRowMasks ( %p, %d, %p ) {\n", puzzle, row, pmasks );
   fflush ( logFile );
#endif

   if ( puzzle->rowMasks [row] ) {

	//int	mask = 0;
	short	mask = 0;
	int	column;

	status = 1;

	/* Make masks for the row. */
	for ( column = 0; column < 9; ++column ) {

		//masks [column] = puzzle->masks [row][column];
		STAR(pmasks [column]) = puzzle->masks [row][column];
		IFT(pmasks [column], puzzle->pmasks [row][column]);
		//mask |= masks [column];
		mask |= star(pmasks [column]);
	}

	if ( mask != puzzle->rowMasks [row] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getRowMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #8
0
//============================================================
void im_complex::SlowIFT()
{
   // Calculate Slow 1D IFT
   int ydim = Re.Ydim;
   int xdim = Re.Xdim;
   if ((ydim == 1) && (xdim > 1))
   {
      IFT();
   }

   // Calculate Slow 2D IFT
   else if ((ydim > 1) && (xdim > 1))
   {
      // Copy input image
      im_complex image(xdim, ydim);
      Swap(image);
      for (int v = 0; v < ydim; v++)
	 for (int u = 0; u < xdim; u++)
	 {
	    Re.Data2D[v][u] = 0;
	    Im.Data2D[v][u] = 0;
	    double u_angle = u * 2 * M_PI / xdim;
	    double v_angle = v * 2 * M_PI / ydim;
	    for (int y = 0; y < ydim; y++)
	       for (int x = 0; x < xdim; x++)
	       {
		  // Negative angle for IFT
		  double angle = -(x * u_angle + y * v_angle);
		  double cos_angle = cos(angle);
		  double sin_angle = sin(angle);
		  Re.Data2D[v][u] += image.Re.Data2D[y][x] * cos_angle
		     - image.Im.Data2D[y][x] * sin_angle;
		  Im.Data2D[v][u] += image.Re.Data2D[y][x] * sin_angle
		     + image.Im.Data2D[y][x] * cos_angle;
	       }
	 }
   }
}
Example #9
0
//static int enterClues ( PUZZLE *puzzle, char *clues )
static int enterClues ( PUZZLE *puzzle, short **pclues )

{
   int	status = 0;
   int	row = 0;
   int	column = 0;

#if	defined(DEBUG)
   //fprintf (  logFile, "enterClues ( %p, \"%s\" ) {\n", puzzle, clues );
   fprintf (  logFile, "enterClues ( %p, %p ) {\n", puzzle, pclues );
   fflush ( logFile );
#endif

   //while ( *clues ) {
   while ( star(*pclues) ) {

	//if ( isdigit ( *clues ) ) {
	if ( isdigit ( star(*pclues) ) ) {

		//int	clue = *clues - '0';
		short	clue = star(*pclues) - '0';
		short	*pclue = &clue;
		IFT(pclue, *pclues);
		//if (TEST(*pclues)) pclue = TAINT(pclue);
#if	defined(DEBUG)
   fprintf (  logFile, "EEE: %p, %p\n", pclue, *pclues );
   fflush ( logFile );
#endif

		if ( column > 8 ) {

			column = 0;
			if ( ++row > 8 ) break;
		}

		if ( clue > 0 ) {

			if ( ! ( status
				//= makeEntry ( puzzle, row, column, clue ) ) )
				= makeEntry ( puzzle, row, column, pclue ) ) )
									break;
		}

		++column;
	}

	++pclues;
   }

   if ( status ) {

	for ( row = 0; row < 9; ++row ) {

		for ( column = 0; column < 9; ++column ) {

			if ( puzzle->grid [row][column] == 0 ) {
				puzzle->masks [row][column]
				= ( puzzle->rowMasks [row]
				& puzzle->columnMasks [column]
				& puzzle->blockMasks [row/3][column/3] );
				
				IFT(puzzle->pmasks [row][column], puzzle->prowMasks [row]);			
				IFT(puzzle->pmasks [row][column], puzzle->pcolumnMasks [column]);			
				IFT(puzzle->pmasks [row][column], puzzle->pblockMasks [row/3][column/3]);			
			}
		}
	}
   }

#if	defined(DEBUG)
   fprintf (  logFile, "} = %d /* enterClues () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #10
0
//============================================================
void im_complex::FastIFT()
{
   // Calculate Fast 1D IFT
   int ydim = Re.Ydim;
   int xdim = Re.Xdim;
   int half_x = xdim / 2;
   if ((ydim == 1) && (xdim > 1) && (xdim % 2 == 0))
   {
      // Make even and odd images
      im_complex even(half_x);
      im_complex odd(half_x);
      for (int x = 0; x < half_x; x++)
      {
	 even.Re.Data1D[x] = Re.Data1D[x + x];
	 even.Im.Data1D[x] = Im.Data1D[x + x];
	 odd.Re.Data1D[x] = Re.Data1D[x + x + 1];
	 odd.Im.Data1D[x] = Im.Data1D[x + x + 1];
      }

      // Calculate even and odd FTs
      even.FastIFT();
      odd.FastIFT();

      // Combine even and odd FTs
      for (int x = 0; x < half_x; x++)
      {
	 double angle = (-2 * M_PI * x) / xdim;
	 double cos_angle = cos(angle);
	 double sin_angle = sin(angle);
	 double odd_re = odd.Re.Data1D[x] * cos_angle
	    - odd.Im.Data1D[x] * sin_angle;
	 double odd_im = odd.Im.Data1D[x] * cos_angle
	    + odd.Re.Data1D[x] * sin_angle;
	 Re.Data1D[x] = (even.Re.Data1D[x] + odd_re);
	 Im.Data1D[x] = (even.Im.Data1D[x] + odd_im);
	 Re.Data1D[x + half_x] = (even.Re.Data1D[x] - odd_re);
	 Im.Data1D[x + half_x] = (even.Im.Data1D[x] - odd_im);
      }
   }

   // Calculate Slow 1D IFT
   else if ((ydim == 1) && (xdim > 1) && (xdim % 2 == 1))
   {
      IFT();
   }

   // Calculate Fast 2D IFT
   else if ((ydim > 1) && (xdim > 1))
   {
      // Perform 1D IFT on each column
      im_complex column(ydim);
      for (int x = 0; x < xdim; x++)
      {
	 for (int y = 0; y < ydim; y++)
	 {
	    column.Re.Data1D[y] = Re.Data2D[y][x];
	    column.Im.Data1D[y] = Im.Data2D[y][x];
	 }
	 column.FastIFT();
	 for (int y = 0; y < ydim; y++)
	 {
	    Re.Data2D[y][x] = column.Re.Data1D[y];
	    Im.Data2D[y][x] = column.Im.Data1D[y];
	 }
      }

      // Perform 1D IFT on each row
      im_complex row(xdim);
      for (int y = 0; y < ydim; y++)
      {
	 for (int x = 0; x < xdim; x++)
	 {
	    row.Re.Data1D[x] = Re.Data2D[y][x];
	    row.Im.Data1D[x] = Im.Data2D[y][x];
	 }
	 row.FastIFT();
	 for (int x = 0; x < xdim; x++)
	 {
	    Re.Data2D[y][x] = row.Re.Data1D[x];
	    Im.Data2D[y][x] = row.Im.Data1D[x];
	 }
      }
   }
}