public static String stringifySolution ( int width , int height , List < List < ColumnName > > solution ) { String [ ] [ ] picture = new String [ height ] [ width ] ; StringBuffer result = new StringBuffer ( ) ; // for each piece placement... for ( List < ColumnName > row : solution ) { // go through to find which piece was placed Piece piece = null ; for ( ColumnName item : row ) { if ( item instanceof Piece ) { piece = ( Piece ) item ; break ; } } // for each point where the piece was placed, mark it with the piece name for ( ColumnName item : row ) { if ( item instanceof Point ) { Point p = ( Point ) item ; picture [ p . y ] [ p . x ] = piece . getName ( ) ; } } } // put the string together for ( int y = 0 ; y < picture . length ; ++ y ) { for ( int x = 0 ; x < picture [ y ] . length ; ++ x ) { result . append ( picture [ y ] [ x ] ) ; } result . append ( "\n" ) ; } return result . toString ( ) ; }
Convert a solution to the puzzle returned by the model into a string that represents the placement of the pieces onto the board .