cubing.js icon indicating copy to clipboard operation
cubing.js copied to clipboard

[Feature request] Validate moves for experimentalAddMove()

Open TwitchSolvesCube opened this issue 1 year ago • 1 comments

Goal

The goal of this feature is to prevent the twisty player from getting frozen when an invalid move is added. For example when an invalid move r is added to a 2x2x2 puzzle with experimentalAddMove() valid moves, such as R, will no longer work.

Possible solution

The current work around discussed with @lgarron is to check if the move can be transformed to a kpuzzle with moveToTransformation() before using experimentalAddMove() as the aforementioned function will throw an error.

Here's my current implementation.

    try {
      var result = this.kpuzzle.moveToTransformation(new Move(myMove));
      if (typeof result === 'object') {
        const newMove = new Move(myMove);
        this.player.experimentalAddMove(newMove);
        this.puzzleState = this.puzzleState.applyMove(newMove);
      }
    } catch (error) {
      console.log(error);
    }

The solution would to be to implement this sort of check within the experimentalAddMove() function before appending the move to the twisty player.

Alternatives

No response

TwitchSolvesCube avatar Jun 01 '24 20:06 TwitchSolvesCube

Definitely a worthwhile addition, I'll try to implement this when I get a chance or I'd be happy to review a PR.

lgarron avatar Jun 02 '24 19:06 lgarron