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

[Feature request] Validate moves for experimentalAddMove() #331

Open
TwitchSolvesCube opened this issue Jun 1, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@TwitchSolvesCube
Copy link

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 TwitchSolvesCube added the enhancement New feature or request label Jun 1, 2024
@lgarron
Copy link
Member

lgarron commented Jun 2, 2024

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

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

No branches or pull requests

2 participants