pioz / chess

A fast chess library that use bitboards to play chess with Ruby
GNU Lesser General Public License v3.0
60 stars 17 forks source link

Load PGN string instead of file? #18

Closed raquelhortab closed 5 years ago

raquelhortab commented 5 years ago

Hi there!

I was wondering if there is a way to load the pgn to create the game in string format instead of having to create a file.

Thanks!

pioz commented 5 years ago

At this time is not possible. I can add this feature on the weekend!

raquelhortab commented 5 years ago

That would be amazing!

For instance, I am using chessboard.js with chess.js, and I was intending to check in the server whether the moves were legal with chess gem before saving the state of the game.

PGN in chess.js is in the standard format: strings like "1. d3 e6 2. d4 e5 3. dxe5 g6". It would be interesting that pgn.rb load and to_s functions followed the standard format.

Thanks for the amazing and quick support!

pioz commented 5 years ago

I've just added this new method to the class Chess::Pgn http://blog.pioz.it/chess/Chess/Pgn.html#load_from_string-instance_method and a couple of tests. Here the commit.

pioz commented 5 years ago

Let me know if this can resolve your problem!

raquelhortab commented 5 years ago

Hi there! Well... actually it does not... I need to use it with ruby 1.9 and I cannot find the workaround, I've been trying to unpack, modify, and rebuild the gem but since I am a noob in this, I cannot get it to work...

raquelhortab commented 5 years ago

Thank you very much for your help though!! Magnificent support!!!

pioz commented 5 years ago

@raquelhortab, unfortunately, Ruby 1.9 is no more supported by this gem.