@@ -264,83 +264,88 @@ impl BoardBuilder {
264264 self . en_passant = file;
265265 self
266266 }
267- }
268-
269- impl Index < Square > for BoardBuilder {
270- type Output = Option < ( Piece , Color ) > ;
271-
272- fn index < ' a > ( & ' a self , index : Square ) -> & ' a Self :: Output {
273- & self . pieces [ index. to_index ( ) ]
274- }
275- }
276267
277- impl IndexMut < Square > for BoardBuilder {
278- fn index_mut < ' a > ( & ' a mut self , index : Square ) -> & ' a mut Self :: Output {
279- & mut self . pieces [ index. to_index ( ) ]
280- }
281- }
282-
283- impl fmt:: Display for BoardBuilder {
284- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
268+ pub fn get_psuedo_fen ( & self ) -> String {
269+ let mut psuedo_fen = String :: new ( ) ;
285270 let mut count = 0 ;
286271 for rank in ALL_RANKS . iter ( ) . rev ( ) {
287272 for file in ALL_FILES . iter ( ) {
288273 let square = Square :: make_square ( * rank, * file) . to_index ( ) ;
289274
290275 if self . pieces [ square] . is_some ( ) && count != 0 {
291- write ! ( f , "{}" , count) ? ;
276+ psuedo_fen . push_str ( count. to_string ( ) . as_str ( ) ) ;
292277 count = 0 ;
293278 }
294279
295280 if let Some ( ( piece, color) ) = self . pieces [ square] {
296- write ! ( f , "{}" , piece. to_string( color) ) ? ;
281+ psuedo_fen . push_str ( piece. to_string ( color) . as_str ( ) ) ;
297282 } else {
298283 count += 1 ;
299284 }
300285 }
301286
302287 if count != 0 {
303- write ! ( f , "{}" , count) ? ;
288+ psuedo_fen . push_str ( count. to_string ( ) . as_str ( ) ) ;
304289 }
305290
306291 if * rank != Rank :: First {
307- write ! ( f , "/" ) ? ;
292+ psuedo_fen . push_str ( "/" ) ;
308293 }
309294 count = 0 ;
310295 }
311296
312- write ! ( f , " " ) ? ;
297+ psuedo_fen . push_str ( " " ) ;
313298
314299 if self . side_to_move == Color :: White {
315- write ! ( f , "w " ) ? ;
300+ psuedo_fen . push_str ( "w " ) ;
316301 } else {
317- write ! ( f , "b " ) ? ;
302+ psuedo_fen . push_str ( "b " ) ;
318303 }
319304
320- write ! (
321- f ,
322- "{}" ,
323- self . castle_rights [ Color :: White . to_index ( ) ] . to_string ( Color :: White )
324- ) ? ;
325- write ! (
326- f ,
327- "{}" ,
328- self . castle_rights [ Color :: Black . to_index ( ) ] . to_string ( Color :: Black )
329- ) ? ;
305+ psuedo_fen . push_str (
306+ self . castle_rights [ Color :: White . to_index ( ) ]
307+ . to_string ( Color :: White )
308+ . as_str ( ) ,
309+ ) ;
310+ psuedo_fen . push_str (
311+ self . castle_rights [ Color :: Black . to_index ( ) ]
312+ . to_string ( Color :: Black )
313+ . as_str ( ) ,
314+ ) ;
330315 if self . castle_rights [ 0 ] == CastleRights :: NoRights
331316 && self . castle_rights [ 1 ] == CastleRights :: NoRights
332317 {
333- write ! ( f , "-" ) ? ;
318+ psuedo_fen . push_str ( "-" ) ;
334319 }
335320
336- write ! ( f , " " ) ? ;
321+ psuedo_fen . push_str ( " " ) ;
337322 if let Some ( sq) = self . en_passant_target {
338- write ! ( f , "{}" , sq ) ? ;
323+ psuedo_fen . push_str ( sq . to_string ( ) . as_str ( ) ) ;
339324 } else {
340- write ! ( f , "-" ) ? ;
325+ psuedo_fen . push_str ( "-" ) ;
341326 }
342327
343- write ! ( f, " 0 1" )
328+ psuedo_fen
329+ }
330+ }
331+
332+ impl Index < Square > for BoardBuilder {
333+ type Output = Option < ( Piece , Color ) > ;
334+
335+ fn index < ' a > ( & ' a self , index : Square ) -> & ' a Self :: Output {
336+ & self . pieces [ index. to_index ( ) ]
337+ }
338+ }
339+
340+ impl IndexMut < Square > for BoardBuilder {
341+ fn index_mut < ' a > ( & ' a mut self , index : Square ) -> & ' a mut Self :: Output {
342+ & mut self . pieces [ index. to_index ( ) ]
343+ }
344+ }
345+
346+ impl fmt:: Display for BoardBuilder {
347+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
348+ write ! ( f, "{} 0 1" , self . get_psuedo_fen( ) )
344349 }
345350}
346351
0 commit comments