Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #144 and optimisations #418

Conversation

gavin-lb
Copy link
Contributor

As discussed in the other PR, I'm splitting the optimisations into their own PR.

Since the bug fix is a dependency of the isThreefoldRepetition optimisation, I've included it in this PR.

gavin-lb added 3 commits June 18, 2023 21:34
load method was previously unnecessarily calling _updateCastlingRights, _updateEnPassantSquare, _updateSetup and fen methods for every piece it placed on the board (because put method called these methods). Optimised  it by implementing a private _put method which doesn't call these methods, then changed publicly exposed API method put to be a wrapper around _put that calls these methods if it was successful.
@jhlywa jhlywa merged commit 55181a9 into jhlywa:master Jun 19, 2023
@jhlywa
Copy link
Owner

jhlywa commented Jun 19, 2023

Thanks for the PR @gavin-lb! I'll be mulling over the strict FIDE adherence flags for the next few days.

jhlywa pushed a commit that referenced this pull request Jun 22, 2023
* removed unnecessary method calls from _put

* removed unnecessary .fen call from load
@ajax333221
Copy link

ajax333221 commented Aug 10, 2023

there is an optimization using the half-move clock, you can start counting the positions from newer to older and stop when encounter a 0 in there. Also when move number <= 7 or halfmove <= 7.

      //some code I wrote for another library
      
      clockless_fen = that.getClocklessFenHelper();
      that.fen = clockless_fen + ' ' + that.halfMove + ' ' + that.fullMove;
      that.isThreefold = false;

      if (sliced_fen_history || (that.moveList && that.currentMove > 7 && that.halfMove > 7)) {
        times_found = 1;
        temp = sliced_fen_history || that.fenHistoryExport();
        i = sliced_fen_history ? sliced_fen_history.length - 1 : that.currentMove - 1;

        for (; i >= 0; i--) {
          temp2 = temp[i].split(' ');

          if (temp2.slice(0, 4).join(' ') === clockless_fen) {
            times_found++;

            if (times_found > 2) {
              that.isThreefold = true;
              break;
            }
          }

          if (temp2[4] === '0') {
            break;
          }
        }
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants