Guest User

Untitled

a guest
Jun 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. public boolean blackHasWon()
  2.     {
  3.         boolean touch = false;
  4.         for ( int i = 0; i < numRows(); i++ )
  5.         {
  6.             areaFill( i, 0 );
  7. //            if ( won )
  8. //            {
  9. //                touch = true;
  10. //                break;
  11. //            }
  12.         }
  13.         System.out.println( toString() );
  14.         for ( int i = 0; i < numRows(); i++ )
  15.         {
  16.             if ( isGray( i, numCols() - 1 ) )
  17.             {
  18.                 touch = true;
  19.             }
  20.  
  21.         }
  22.         for ( int r = 0; r < numRows(); r++ )
  23.         {
  24.             for ( int c = 0; c < numCols(); c++ )
  25.             {
  26.                 if ( isGray( r, c ) )
  27.                 {
  28.                     setBlack( r, c );
  29.                 }
  30.             }
  31.         }
  32.         //won = false;
  33.         return touch;
  34.     }
  35.  
  36.     /**
  37.      * Fills the contiguous area that contains r,c with gray color. Does nothing
  38.      * if r, c is out of bounds or is not black.
  39.      */
  40.     public void areaFill( int r, int c )
  41.     {
  42.         if ( isInBounds( r, c ) && isBlack( r, c ) && c == numCols() - 1 )
  43.         {
  44.             return;
  45.         }
  46.         if ( isInBounds( r, c ) && isBlack( r, c ) )
  47.         {
  48.             setGray( r, c );
  49.  
  50.             //if ( !won )
  51.                 areaFill( r - 1, c - 1 );
  52.             //if ( !won )
  53.                 areaFill( r - 1, c );
  54.             //if ( !won )
  55.                 areaFill( r, c - 1 );
  56.             //if ( !won )
  57.                 areaFill( r, c + 1 );
  58.             //if ( !won )
  59.                 areaFill( r + 1, c );
  60.             //if ( !won )
  61.                 areaFill( r + 1, c + 1 );
  62.  
  63.         }
  64.     }
Add Comment
Please, Sign In to add comment