chess.js | TypeScript chess library for chess move generation | Runtime Evironment library

 by   jhlywa TypeScript Version: 1.0.0-beta.8 License: BSD-2-Clause

kandi X-RAY | chess.js Summary

kandi X-RAY | chess.js Summary

chess.js is a TypeScript library typically used in Server, Runtime Evironment, React Native, React, Nodejs applications. chess.js has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

chess.js is a Javascript chess library that is used for chess move generation/validation, piece placement/movement, and check/checkmate/stalemate detection - basically everything but the AI. chess.js has been extensively tested in node.js and most modern browsers.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              chess.js has a medium active ecosystem.
              It has 3161 star(s) with 852 fork(s). There are 103 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              There are 65 open issues and 197 have been closed. On average issues are closed in 200 days. There are 40 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of chess.js is 1.0.0-beta.8

            kandi-Quality Quality

              chess.js has 0 bugs and 0 code smells.

            kandi-Security Security

              chess.js has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              chess.js code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              chess.js is licensed under the BSD-2-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              chess.js releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed chess.js and discovered the below as its top functions. This is intended to give you an instant insight into chess.js implemented functionality, and help decide if they suit your requirements.
            • Generate a move .
            • Parse the move .
            • change board .
            • Validate a FENF string .
            • generate FFCion
            • Parse rock .
            • Undo move .
            • Returns a disambiguator for a move
            • Check if material has been depleted
            • check if a board is in the board
            Get all kandi verified functions for this library.

            chess.js Key Features

            No Key Features are available at this moment for chess.js.

            chess.js Examples and Code Snippets

            No Code Snippets are available at this moment for chess.js.

            Community Discussions

            QUESTION

            Error when attempting to import a node module into NuxtJS TypeScript (ES2018)
            Asked 2022-Apr-10 at 05:02

            I am attempting to import the chess.js module like so:

            import Chess from 'chess.js';

            This gives me the following error when loading the app locally:

            require() of ES Module .../app/node_modules/chess.js/chess.js from .../app/node_modules/vue-server-renderer/build.dev.js not supported. Instead change the require of chess.js in .../app/node_modules/vue-server-renderer/build.dev.js to a dynamic import() which is available in all CommonJS modules.

            Well I'm already using an import statement, not require. I've tried playing around with different ways to import the module but nothing is working. I understand this is caused by using TypeScript when creating the NuxtJS app. I'm currently trying to import the chess.js module into a .js file, not a .ts file, and something is getting mistranslated here.

            Any ideas?

            This is my tsconfig:

            ...

            ANSWER

            Answered 2022-Apr-10 at 05:02

            You can try using the import() function with JavaScript.

            You need to follow these steps to accomplish it.

            1. Remove the following line from package.json.

            Source https://stackoverflow.com/questions/71811788

            QUESTION

            How do I initiate the function on button click?
            Asked 2022-Feb-16 at 22:57

            Following code starts a chess game in initial position integrating chess.js library.

            ...

            ANSWER

            Answered 2022-Feb-16 at 22:57

            I simply added the code for the buttons at the bottom of your code. This code attaches event handlers to the start and clear buttons, so it could be placed anywhere outside of a function. Here's some code to display the two buttons below the board. I also added some code to run the code inside the code snippet.

            Source https://stackoverflow.com/questions/71131250

            QUESTION

            What is the best architecture for a web-app communicating with a gRPC service?
            Asked 2022-Jan-03 at 17:43

            I have built a website with chess.js and java chess libraries that communicates with a custom c++ chess engine via gRPC with python. I am new to web dev and especially gRPC, so I am not sure on the architecture I should be going for when it comes to hosting.

            My questions are below:

            • Do the website and gRPC service need to be hosted on separate server instances and connected via API?

              • Everything right now is hosted locally and I use two ports as it is right now (5000 for the website and 8080 for the server). If the site and server aren't separate, is this how they will communicate to each other on a single server (one local port)?
            • I am using this website just for a showcase of my portfolio for job searching, so I am looking for free/cheap hosting that also provides a decent RAM availability since the c++ chess engine is fairly computationally intense. Does anyone have any suggestions for what hosting service I should use for this?

              • I was considering a free hosting for the website and then a cheap dedicated server for the service (if the two should be separate). Is this a bad idea?

            Taking all tips and tricks that anyone has to offer. Again, totally novice to web dev, hosting, servers, etc.

            ...

            ANSWER

            Answered 2022-Jan-03 at 17:43

            NOTE This is an architecture rather than a programming question and discouraged on stack overflow.

            The website and gRPC service may be hosted on the same server (as you're doing locally). You have the flexibility in running both processes (website and gRPC service) on a single more powerful host or separately on two hosts.

            NOTE Although most often gRPC communicates over TCP sockets, it is possible to use UNIX sockets and even buffered memory too.

            If you run both processes on a single host, you will want to consider connecting the website to the gRPC service via localhost (127.0.0.1 or the loopback device). Using localhost, network traffic doesn't leave the host.

            If you run both processes on different hosts, traffic must travel across a network. This is slower and will likely incur charges when hosted.

            You will want to decide whether the gRPC service should be exposed to any network traffic other than your website. In many cases, a gRPC service is used to provide an API to facilitate integration by 3rd-parties. If you definitely don't want the gRPC service accessed by other things, then you'll want to ensure either that it's bound to localhost (see above; and thereby inaccessible to anything other than other processes e.g. your website on the host) or firewalled such that only the website is permitted to send traffic to it.

            You can find cheap hosting of virtual machines (VMs) and you'll likely want to consider hosting both processes on a single VM, ensure that you constrain the resources that you pay for and that you secure traffic (as above).

            You may wish to consider containerizing the application. In this case, while it's possible to run both processes in a single container, this is considered not good practice. You should thus consider 2 containers (website and gRPC server). Many hosting|cloud platforms provide container hosting and this is generally easier than managing VMs (since you don't need to patch|update the OS and any dependencies). If you can find a platform that accepts a Docker Compose describing or a Kubernetes Deployment in which you describe both your services and how they interact such that the gRPC service is only accessible to the website, that could be ideal.

            Source https://stackoverflow.com/questions/70568199

            QUESTION

            Using the chess.js module in Nuxt
            Asked 2021-Sep-17 at 15:13

            I am trying to use the chess.js module in a Nuxt app but the installation instructions don't seem to work for Nuxt.

            ...

            ANSWER

            Answered 2021-Sep-17 at 15:13

            You need to use the import syntax and to call new Chess() in mounted().

            Source https://stackoverflow.com/questions/69225536

            QUESTION

            Passing Object and its Methods to another function
            Asked 2021-Jul-12 at 15:07

            I have a npm library that I import into my app, see below:

            ...

            ANSWER

            Answered 2021-Jul-12 at 15:07

            Does passing chess object in your imported function work for you?

            In your utitilies.js

            Source https://stackoverflow.com/questions/68349678

            QUESTION

            What causes this event handler to keep running?, and why does it halt when I try to add a condition?
            Asked 2021-Jun-08 at 18:02

            I'm making a chess opening trainer. I have a working game using cm-chessboard based on an example, and I'm using an API to get the computer's moves. I have condensed my code and removed this API so it's easier to read. In this version, the computer makes random moves from all valid chess moves.

            The idea is, the API gets the best move, and then the player tries to input that move by moving a piece. If the player is correct, the computer moves for their next go, but if the player incorrectly guesses the best move, they are told 'Incorrect!' and are able to try again.

            However, my code works fine when they are correct, but breaks when they are incorrect.

            Here's what I have done:

            ...

            ANSWER

            Answered 2021-Jun-08 at 18:02

            I played around a bit and I was able to use this to get it to work. This is around line 90 of your code. It uses your code to check if the move is not the correct one and resets it back until you do the correct move

            Source https://stackoverflow.com/questions/67871635

            QUESTION

            How do I implement minimax with the chess.js node module
            Asked 2021-Apr-15 at 04:32

            I'm currently working on creating a chess engine using chess.js, chessboard.js, and the minimax algorithm. I eventually want to implement alpha-beta, but for right now, I just want to get minimax to work. It seems like the computer is thinking, but it usually just does Nc6. If I move the pawn to d4, it usually takes with the knight, but sometimes it just moves the rook back and forth in the spot that was opened up by the knight. If there is nothing for the knight to take, the computer moves the Rook or some other pointless move. My best guess is that all of the moves are returning the same valuation, and so it just makes the first move in the array of possible moves, hence the top left rook being a prime target. I should note that part of my confusion is around the way a recursive function works, and most of the stuff I've found online about recursive functions leaves me more confused than when I started.

            I'm using Express.js with the chessboard.js config in public/javascripts as a boardInit.js that's included in the index.ejs folder, and when the user makes a move, a Post request is sent to /moveVsComp. It sends it to the server, where the app.post function for /moveVsComp tells chess.js to make the move that the player made.

            After the player move is recorded, the computer calls the computerMoveBlack function.

            Function call in the post request:

            ...

            ANSWER

            Answered 2021-Apr-15 at 04:32

            I will point out a few suggestions below to help you on the way if you are just getting started. First I just want to say that you are probably right that all moves get the same score and therefore it picks the first possible move. Try to add some Piece Square Tables (PST) to your Evaluation function and see if it puts pieces on appropriate squares.

            1. I would implement a Negamax function instead of Minimax. It is way easier to debug and you won't have to duplicate a lot of code when you later make more optimizations. Negamax is one of the standard chess algorithms.
            2. It seems like you don't do the legal move generation yourself, do you know how the board is represented in the library that you use? Instead of using the FEN for evaluation you want to use the board (or bitboards) to be able to do more advanced evaluation (more on it further down).
            3. The min/max value of -105/105 is not a good way to go. Use -inf and inf instead to not get into troubles later on.

            Regarding the evaluation you normally use the board representation to figure out how pieces are placed and how they are working together. Chessprogramming.org is a great resource to read up on different evaluation concepts.

            For your simple starting evaluation you could just start with counting up all the material score at the beginning of the game. Then you subtract corresponding piece value when a piece is captured since that is the only case where the score is changing. Now you are recalculating lots of things over and over which will be very slow.

            If you want to add PST to the evaluation then you also want to add the piece value change for the moving piece depending on the old and new square. To try and sum up the evaluation:

            1. Sum up all piece values at start-up of a game (with PST scores if you use them) and save it as e.g. whiteScore and blackScore
            2. In your evaluation you subtract the piece value from the opponent if you capture a piece. Otherwise you keep score as is and return it as usual.
            3. If using PST you change the own score based on the new location for the moved piece.

            I hope it makes sense, let me know if you need any further help.

            Source https://stackoverflow.com/questions/67090608

            QUESTION

            How can I break line after specific scheme in text
            Asked 2021-Mar-24 at 01:26

            I am writing an a chess player and I have this script in js file that writes PGN to the text area.

            Instead of this:

            My script does this:

            I am using chess.js for the backend and code that prints out the PGN in the function that is called every piece drop, so it updates every time player does a move.

            Javascript ...

            ANSWER

            Answered 2021-Mar-24 at 01:26

            As their documentation says here, you can pass options such as newline_char in chess.pgn() to decide what to add before every new line. You can pass \n which adds a new line in the </code> to show moves in a new line.</p>

            Source https://stackoverflow.com/questions/66760812

            QUESTION

            Move Ordering in Javascript Chess Engine chess.js
            Asked 2021-Feb-17 at 01:35

            i am by far a javascript specialist but i am trying to learn it a little.

            For the move ordering in my chess engine (i follow a tutorial), i would like to check for captures first. In the chess.js library the capture moves are listed with the flag 'c'.

            ...

            ANSWER

            Answered 2021-Feb-17 at 01:00

            Based on the documentation at https://github.com/jhlywa/chess.js/blob/master/README.md#moves-options-, the flags are not passed into moves(), but rather, are returned from moves() as an attribute associated with each legal move. Therefore, to get a list of all captures, you will need to apply a filter on the resulting array of all legal moves. Something along the following lines...

            Source https://stackoverflow.com/questions/66230687

            QUESTION

            How to understand the fen arguments of Chess.js
            Asked 2021-Jan-16 at 09:09

            I'm not asking for the chess notation. I'm asking for the use of the arguments given. I'm using Chess.js. And I want to know the use of the arguments given in chess.fen().

            Here's the fen without moves: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 and then move e4: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1.

            Now my question is what's the use of KQkq, e3m 0, and 1. I moved e4 but why did it say e3? I'm confused.

            ...

            ANSWER

            Answered 2021-Jan-16 at 09:09

            The first argument is the board itself with the first 8 characters being row 8, then row 7 and so on. KQkq means white king can castle king side, w king q side, b king k side and b king q side respectively. So if it says only KQ it means only white king can castle king and queen side, black has lost its casting rights. - is no one can castle.

            e3 means that e3 is the enpassant square. So if black had a pawn on d4 he could take the e4 pawn e.p. and end up on e3 square. - means there is no enpassant possible square (no side made a double pawn push).

            The last 2 numbers are half move and move counter, the first one used to keep track of 50 move rule.

            Read more here if you are interested: https://en.m.wikipedia.org/wiki/Forsyth–Edwards_Notation

            Source https://stackoverflow.com/questions/65746496

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install chess.js

            To install the stable version:.

            Support

            The en passant square and castling flags aren't adjusted when using the put/remove functions (workaround: use .load() instead)
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries