maksimKorzh / wukong-xiangqi

Didactic Chinese chess Xiangqi engine by Code Monkey King
MIT License
32 stars 17 forks source link

link to specific puzzle #2

Open khonkhortisan opened 1 year ago

khonkhortisan commented 1 year ago

spaced repetition requires being able to jump straight to a specific puzzle, pass/fail it, then leave. This can be done by linking to a website (in an iframe) or by assimilating enough of it to self-host a local functioning html page. Anki has restrictions on media files (no folders, any file not directly referenced in a field or template must begin with an underline to avoid being deleted), so assimilation may require modification, and linking is easier if it's supported. This puzzle solver doesn't seem to support #anchor nor ?querystring, and iframes don't allow running setPuzzle("puzzle_2") from outside.

♟️ chess https://ankiweb.net/shared/info/2023846080 assimilated 🔴 connect four https://sites.math.rutgers.edu/~zeilberg/C4/ch2/P2.html linked then assimilated ⚫ go https://online-go.com/puzzle/2627 linked ☗️ shogi https://playshogi.com/#Problems:7:1:null linked (https://lishogi.org/study/DVkrN1nl failed to link or assimilate) 🐘 xiangxi

https://github.com/maksimKorzh/interactive-xiangqi-apps/blob/097a56af1c44b4f57f42a8e3e6441a2c16c76baa/apps/puzzle_solver/gui/game/puzzle_solver.js#L591 It looks like the puzzle solver would have to be modified either way whether I tried to link or assimilate the puzzles.

This issue is an attempt to link to specific puzzles.

khonkhortisan commented 1 year ago

oh. The puzzle data doesn't include the right move sequence, so it can't reset the puzzle when I make a mistake.

khonkhortisan commented 1 year ago

Green feedback on mate without waiting 5 seconds to go the next puzzle, and red feedback on all moves spent. No feedback for wrong move.

$("#xiangqiboard").mouseover(function(){
    setTimeout( function(){
        maxmoves = Puzzles["{{Front}}".split('_')[1]].title.match(/(\d+)/)[0];
    if ($("#pgn").val().endsWith(" mate")) {
            //$("#xiangqiboard")[0].style.border="1px solid green";
            $("#qa")[0].style.backgroundColor="green";
        } else if ($("#pgn").val().includes(maxmoves+". ")) {
            $("#qa")[0].style.backgroundColor="red";
        }
  }, 100 );
});

mouseover catches both click/mouseup and ondragend/ondrop, without having to wrap ondrop for every td>img[draggable]

khonkhortisan commented 1 year ago

_xiangqi_puzzle_solver.js

    // load next position
    setTimeout(function() {
      currentPuzzleId++;
      if (currentPuzzleId >= Puzzles.length) currentPuzzleId = 0;
      setPuzzle('puzzle_' + currentPuzzleId);  
      return;
    }, 5000);

If I pass card 1 and move to card 2 too fast, this function puts me on puzzle 3 so I had to disable it. I was grading pass/fail for the wrong puzzle.