Changed game header parsing to use quotation marks (Closes #204)
authorQueensGambit <curry-berry@freenet.de>
Sun, 8 Nov 2020 12:33:50 +0000 (13:33 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 8 Nov 2020 13:32:00 +0000 (14:32 +0100)
Added test for loading Seirawan chess pgn
Updated README.md
Updated ffish to 0.4.6

src/apiutil.h
src/ffishjs.cpp
tests/js/README.md
tests/js/package.json
tests/js/test.js
tests/pgn/pychess-variants_zJxHRVm1.pgn [new file with mode: 0644]

index 8334eaf..57a5f11 100644 (file)
@@ -827,3 +827,4 @@ FenValidation validate_fen(const std::string& fen, const Variant* v) {
     return FEN_OK;
 }
 }
+
index a94dc9e..448b80f 100644 (file)
@@ -425,8 +425,8 @@ Game read_game_pgn(std::string pgn) {
       // look for item
       size_t headerKeyStart = lineStart+1;
       size_t headerKeyEnd = pgn.find(' ', lineStart);
-      size_t headerItemStart = headerKeyEnd+2;
-      size_t headerItemEnd = pgn.find(']', headerKeyEnd)-1;
+      size_t headerItemStart = pgn.find('"', headerKeyEnd)+1;
+      size_t headerItemEnd = pgn.find('"', headerItemStart);
 
       // put item into list
       game.header[pgn.substr(headerKeyStart, headerKeyEnd-headerKeyStart)] = pgn.substr(headerItemStart, headerItemEnd-headerItemStart);
index 79d058e..e12e569 100644 (file)
@@ -151,7 +151,7 @@ fs.readFile(pgnFilePath, 'utf8', function (err,data) {
   game = ffish.readGamePGN(data);
   console.log(game.headerKeys());
   console.log(game.headers("White"));
-  console.log(game.mainlineMoves())
+  const mainlineMoves = game.mainlineMoves().split(" ");
 
   let board = new ffish.Board(game.headers("Variant").toLowerCase());
   for (let idx = 0; idx < mainlineMoves.length; ++idx) {
@@ -269,6 +269,8 @@ syzygy/*.cpp \
 -o ../tests/js/ffish.js
 ```
 
+Make sure that the wasm file is in the `public` directory.
+
 Reference: [emscripten/#10114](https://github.com/emscripten-core/emscripten/issues/10114)
 
 ## Instructions to run the tests
index ae5bf84..bd28e48 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "ffish",
-  "version": "0.4.4",
+  "version": "0.4.6",
   "description": "A high performance WebAssembly chess variant library based on Fairy-Stockfish",
   "main": "ffish.js",
   "scripts": {
index 749045e..f39b26c 100644 (file)
@@ -196,7 +196,7 @@ describe('board.setFen(fen)', function () {
   });
 });
 
-describe('board.sanMove()', function () {
+describe('board.sanMove(uciMove)', function () {
   it("it converts an uci move into san", () => {
     const board = new ffish.Board();
     const san = board.sanMove("g1f3");
@@ -471,10 +471,11 @@ describe('ffish.validateFen(fen, uciVariant)', function () {
 describe('ffish.readGamePGN(pgn)', function () {
   it("it reads a pgn string and returns a game object", () => {
      fs = require('fs');
-     let pgnFiles = ['deep_blue_kasparov_1997.pgn', 'lichess_pgn_2018.12.21_JannLee_vs_CrazyAra.j9eQS4TF.pgn', 'c60_ruy_lopez.pgn']
+     let pgnFiles = ['deep_blue_kasparov_1997.pgn', 'lichess_pgn_2018.12.21_JannLee_vs_CrazyAra.j9eQS4TF.pgn', 'c60_ruy_lopez.pgn', 'pychess-variants_zJxHRVm1.pgn']
      let expectedFens = ["1r6/5kp1/RqQb1p1p/1p1PpP2/1Pp1B3/2P4P/6P1/5K2 b - - 14 45",
                          "3r2kr/2pb1Q2/4ppp1/3pN2p/1P1P4/3PbP2/P1P3PP/6NK[PPqrrbbnn] b - - 1 37",
-                         "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3"]
+                         "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3",
+                         "r1bQkb1r/ppp1pppp/2P5/2n2q2/8/2N2N2/PPP2PPP/R1BEKB1R[Hh] b KQACEFHkqacefh - 0 8"]
 
      for (let idx = 0; idx < pgnFiles.length; ++idx) {
      let pgnFilePath = pgnDir + pgnFiles[idx];
@@ -521,7 +522,7 @@ describe('game.headerKeys()', function () {
 describe('game.headers(key)', function () {
   it("it returns the value for a given header key of a loaded game", () => {
      fs = require('fs');
-     let pgnFile = 'lichess_pgn_2018.12.21_JannLee_vs_CrazyAra.j9eQS4TF.pgn';
+     let pgnFile = 'pychess-variants_zJxHRVm1.pgn';
      let pgnFilePath = pgnDir + pgnFile;
 
      fs.readFile(pgnFilePath, 'utf8', function (err,data) {
@@ -529,9 +530,11 @@ describe('game.headers(key)', function () {
          return console.log(err);
        }
        let game = ffish.readGamePGN(data);
-       chai.expect(game.headers("White")).to.equal("JannLee");
-       chai.expect(game.headers("Black")).to.equal("CrazyAra");
-       chai.expect(game.headers("Variant")).to.equal("Crazyhouse");
+       chai.expect(game.headers("White")).to.equal("catask");
+       chai.expect(game.headers("Black")).to.equal("Fairy-Stockfish");
+       chai.expect(game.headers("Variant")).to.equal("Seirawan");
+       chai.expect(game.headers("FEN")).to.equal("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[HEhe] w KQBCDFGkqbcdfg - 0 1");
+
        game.delete();
      });
   });
diff --git a/tests/pgn/pychess-variants_zJxHRVm1.pgn b/tests/pgn/pychess-variants_zJxHRVm1.pgn
new file mode 100644 (file)
index 0000000..8956e30
--- /dev/null
@@ -0,0 +1,15 @@
+[Event "PyChess casual game"]
+[Site "https://www.pychess.org/zJxHRVm1"]
+[Date "2020.05.28"]
+[Round "-"]
+[White "catask"]
+[Black "Fairy-Stockfish"]
+[Result "1-0"]
+[TimeControl "300+3"]
+[WhiteElo "1500?"]
+[BlackElo "1500?"]
+[Variant "Seirawan"]
+[FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[HEhe] w KQBCDFGkqbcdfg - 0 1"]
+[SetUp "1"]
+
+1. e4 d5 2. exd5 Qxd5/E 3. Nc3 Qf5 4. d4 Nf6 5. Nf3 Nc6 6. d5 Ne4 7. dxc6 Nc5 8. Qxd8/E# 1-0