GithubHelp home page GithubHelp logo

Comments (2)

zekicaneksi avatar zekicaneksi commented on May 16, 2024 1

Now that taking a look at your solution, even though my solution worked, it was not safe for other reasons, and yours is much better, thanks! xd

Also, as a newbie programmer "catching" this issue was a long and painful process for me, believe me xd i thought about abandoning my project even. I trusted you more than myself, thought that i was using it wrong rather than it being wrong.

Anyways, thanks a lot. This is a very nice package/library or whatever its called. Have a nice one <3

from react-chessboard.

Clariity avatar Clariity commented on May 16, 2024

You raise a very good point, this was written back when I had less of an idea about state update rules and I hadn't thought to look back at it, so good catch.

The good news is that there is a simple solution, which I think maybe is the one you've done but I'm not sure from the description.

The solution is actually already implemented in another example, so I must have found this issue at some point but not updated other examples:

function onDrop(sourceSquare, targetSquare) {
    const gameCopy = { ...game };
    const move = gameCopy.move({
      from: sourceSquare,
      to: targetSquare,
      promotion: 'q' // always promote to a queen for example simplicity
    });
    setGame(gameCopy);

    // illegal move
    if (move === null) return false;

    // store timeout so it can be cleared on undo/reset so computer doesn't execute move
    const newTimeout = setTimeout(makeRandomMove, 200);
    setCurrentTimeout(newTimeout);
    return true;
  }

from react-chessboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.