Chess.js | A chess game written in JavaScript | Game Engine library
kandi X-RAY | Chess.js Summary
kandi X-RAY | Chess.js Summary
A chess game written in JavaScript
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Chess.js
Chess.js Key Features
Chess.js Examples and Code Snippets
Community Discussions
Trending Discussions on Chess.js
QUESTION
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:02I 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
QUESTION
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:32I 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.
- 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.
- 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).
- 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:
- 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
- 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.
- 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.
QUESTION
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:26As 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>
QUESTION
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:00Based 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...
QUESTION
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
, e3
m 0
, and 1
. I moved e4
but why did it say e3
? I'm confused.
ANSWER
Answered 2021-Jan-16 at 09:09The 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
QUESTION
I have a fresh MeteorJS project and I have only installed chessboardjs and chessjs as follows
...ANSWER
Answered 2020-Jun-29 at 14:16There are three issues here.
- Imports typo
- importing css
- Rendering
First your imports and the function you call need to be the same. You imports are
QUESTION
Im trying to build an Angular application for a chessgame. I want to use the library chess.js https://github.com/jhlywa/chess.js/blob/master/README.md with the types declared in https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/chess.js But whenever i run the application theres an error on runtime.
I've installed the packages through npm with
...ANSWER
Answered 2019-Oct-28 at 21:37You can import it like this
QUESTION
I am creating a chessboard with Javascript. I already managed to create the board itself, but I'm having trouble giving every field its fitting class (black or white).
I managed to correctly assign the classes for the first row, but am having trouble with the rest of the board. I know there are probably easier solutions to this.
...ANSWER
Answered 2019-Sep-07 at 19:59Not sure what other functionality you'd need, but for generating the board you could do something like this:
QUESTION
I'm developing a multiplayer chess game using node js with socket.io. The game displays fine in the index.html file and works fine on the server when I run it on localhost:8080. However, the chess moves aren't being submitted to the other player, even though I did everything right. What's missing? I have socket.io installed correctly
I've tried re-watching the tutorial on youtube over and over again to spot my mistake, but I can't. I did everything accordingly. I must be missing something. here's the link https://www.youtube.com/watch?v=Isfqigjo7fQ&t=1621s
EDIT
here is the link to the tutorial on building the multiplayer chess game http://dwcares.com/2015/10/21/realchess/
...ANSWER
Answered 2019-Apr-12 at 16:01Could it be that handleMove
is never called? I can't see it in the code you provided.
Edit: Also you are connecting using var socket = io.connect('http://localhost');
The http port is 80
by default. Try connecting to http://localhost:8080
To do that, change your script in the HTML file:
QUESTION
I am working with react-js. I have a problem that appears only after building the application.
I use
npm run build
to publish I use
both surge
and git pages
The problem consists in having a css-grid(in .Board) that does not work and also some classes that no longer have their css-area assigned.
The css-gird is totally stretched. I don't think the error really matters because the localhost works perfectly. Is it an "import problem"?
import "./Board.css"
How can I fix it?
I've tried moving the import below the last import, changing name to the css file. I've also tried publishing the application with both "GitHub pages" and "surge"
// ----------- Board.css
...ANSWER
Answered 2018-Dec-26 at 10:22Please try
Install:-
npm install --save-dev style-loader
npm install --save-dev css-loader
import disabledLink from "./Board.css";
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Chess.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page