Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean blackHasWon()
- {
- boolean touch = false;
- for ( int i = 0; i < numRows(); i++ )
- {
- areaFill( i, 0 );
- // if ( won )
- // {
- // touch = true;
- // break;
- // }
- }
- System.out.println( toString() );
- for ( int i = 0; i < numRows(); i++ )
- {
- if ( isGray( i, numCols() - 1 ) )
- {
- touch = true;
- }
- }
- for ( int r = 0; r < numRows(); r++ )
- {
- for ( int c = 0; c < numCols(); c++ )
- {
- if ( isGray( r, c ) )
- {
- setBlack( r, c );
- }
- }
- }
- //won = false;
- return touch;
- }
- /**
- * Fills the contiguous area that contains r,c with gray color. Does nothing
- * if r, c is out of bounds or is not black.
- */
- public void areaFill( int r, int c )
- {
- if ( isInBounds( r, c ) && isBlack( r, c ) && c == numCols() - 1 )
- {
- return;
- }
- if ( isInBounds( r, c ) && isBlack( r, c ) )
- {
- setGray( r, c );
- //if ( !won )
- areaFill( r - 1, c - 1 );
- //if ( !won )
- areaFill( r - 1, c );
- //if ( !won )
- areaFill( r, c - 1 );
- //if ( !won )
- areaFill( r, c + 1 );
- //if ( !won )
- areaFill( r + 1, c );
- //if ( !won )
- areaFill( r + 1, c + 1 );
- }
- }
Add Comment
Please, Sign In to add comment