bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
229 stars 80 forks source link

Pieces should be able to tell their algebraic (SAN & FAN) notation #69

Closed ZeroOne3010 closed 3 years ago

ZeroOne3010 commented 3 years ago

In my application I added a Map<Piece,String> which I used to get the FAN representation of each Piece, such as "♜" and "♙". Then I figured it would actually be a very useful feature if this library would just give me those symbols. I dug into the code and found that it already has a feature like that in the MoveList class, but it's just not public.

This pull request improves the Piece enum by adding several new methods: getSanSymbol(), getFanSymbol(), getFenSymbol(), and fromFenSymbol(String). I think these additions also simplify the internal structure of the code, because you need fewer lookup tables in different classes. I was, in fact, able to mark some fields and methods in the Constants class as deprecated. I didn't dare to delete them, as someone may depend on them.

bhlangonijr commented 3 years ago

@ZeroOne3010 thank you. I just needed to fix a javadoc type at MoveList line #579.