bhlangonijr / chesslib

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

Add methods to view the board from either player's view point #60

Closed ZeroOne3010 closed 3 years ago

ZeroOne3010 commented 3 years ago

Greetings,

I figured it would be useful (for me, at least!) if you could view the board from either player's view point. The current toString() method of the Board class always renders the board so that White is at the bottom.

With this pull request I introduce new methods for the Board class:

The first one renders the board as if it was the White player looking at it, i.e. the 1st rank at the bottom. The second one renders the board as if it was the Black player looking at it, i.e. the 8th rank at the bottom. The third method allows you to specify the side as a parameter. Internally, the first and second method refer to the third one. Similarly, the old toString() method refers to the first one, and then just appends the info on whose turn it is. I also created unit tests for all of these methods, including the old toString() which kind of had a test but without any assertions.

I figured I could do this feature quicker than I could create a pull request that would explain everything that I would need, so I just went ahead and did it before asking, I hope you don't mind. 😃

bhlangonijr commented 3 years ago

Thank you @ZeroOne3010