# include <stdio.h>
# include <stdlib.h>
# include <time.h>

# include "polyomino_condense.h"

int main ( );
void condense_demo ( int mp, int np, int p[] );

/******************************************************************************/

int main ( )

/******************************************************************************/
/*
  Purpose:

    MAIN is the main program for POLYOMINO_CONDENSE_TEST.

  Discussion:

    POLYOMINO_CONDENSE_TEST tests POLYOMINO_CONDENSE.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    29 April 2018

  Author:

    John Burkardt

  Local parameters:

    Local, int MP, NP, the number of rows and columns in the representation
    of the polyomino P.

    Local, int P[MP*NP], a matrix representing the polyomino.  
*/
{
  int mp;
  int np;
  int p1[] = { 0, 1, 1, 1, 1, 0, 0, 1, 0 };
  int p2[] = { 0, 1, 2, 1, 3, 0, 0, -9, 0 };
  int p3[] = { 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0 };
  int p4[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

  timestamp ( );
  printf ( "\n" );
  printf ( "POLYOMINO_CONDENSE_TEST:\n" );
  printf ( "  C version\n" );
  printf ( "  POLYOMINO_CONDENSE 'cleans up' a matrix that is supposed\n" );
  printf ( "  to represent a polyomino:\n" );
  printf ( "  * nonzero entries are set to 1;\n" );
  printf ( "  * initial and final zero rows and columns are deleted.\n" );
/*
  Nothing happens:
*/
  mp = 3;
  np = 3;
  condense_demo ( mp, np, p1 );
/*
  Nonzero, but non-one entries are set to 1.
*/
  mp = 3;
  np = 3;
  condense_demo ( mp, np, p2 );
/*
  Extraneous zero rows and columns are removed.
*/
  mp = 3;
  np = 4;
  condense_demo ( mp, np, p3 );
/*
  Null matrices are detected.
*/
  mp = 2;
  np = 4;
  condense_demo ( mp, np, p4 );
/*
  Terminate.
*/
  printf ( "\n" );
  printf ( "POLYOMINO_CONDENSE_TEST:\n" );
  printf ( "  Normal end of execution.\n" );
  printf ( "\n" );
  timestamp ( );

  return 0;
}
/******************************************************************************/

void condense_demo ( int mp, int np, int p[] )

/******************************************************************************/
/*
  Purpose:

    CONDENSE_DEMO demonstrates the result of calling POLYOMINO_CONDENSE.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    29 April 2018

  Author:

    John Burkardt

  Parameters:

    Input, int MP, NP, the number of rows and columns in the representation
    of the polyomino P.

    Input, int P[MP*NP], a matrix representing the polyomino.  

    Local, int MQ, NQ, the number of rows and columns in the representation
    of the condensed polyomino Q.

    Local, int Q[MQ*NQ], a matrix representing the condensed polyomino.  
*/
{
  char label[80];
  int mq;
  int nq;
  int *q;

  sprintf ( label, "  The initial (%d,%d) polynomino P:", mp, np );
  polyomino_print ( mp, np, p, label );

  polyomino_condense ( mp, np, p, &mq, &nq, &q );

  sprintf ( label, "  The condensed (%d,%d) polynomino Q:", mq, nq );
  polyomino_print ( mq, nq, q, label );

  if ( *q )
  {
    free ( q );
  }

  return;
}