Comments (1)
Hi, thanks for checking out the library!
Pre-moves are a good application, but I do not have plans to add it to the core library as that involves state management, and this chessboard is not intended to maintain complex internal state.
However, I think it should be possible to implement pre-moves in your application using this library, assuming you manage state yourself in your application. Here's a potential way to do it:
(Assuming Player A = white, Player B = black)
- Start with
turn = white
(Player A). When Player A makes a move, then update your copy of the game state (FEN) accordingly. It is now Player B's turn to make a move. - On Player B's board, set
turn = black
, so that Player B can make a move freely. - On Player A's board, set
turn = white
, so that Player A can also move. This isn't a real move, though - just a pre-move. You can customize styles so that moves appear in a different color. A detailed set of CSS styling properties is available on the API page.
Now, you have to handle two different events (you can use a combination of movestart
or movefinished
for this - details on API page):
- For Player A (the person who can pre-move): when they move a piece, record the move in your application state, and also update board FEN for player A to reflect this move (we will revert this after Player B makes a move). Style board accordingly so that Player A knows that this is just a pre-move.
- For Player B (the person whose turn it is), when they move a piece, update board FEN for Player A.
- Immediately after that (or after a short delay), check if recorded move from Player A is valid:
- If the pre-move was valid, update game FEN again. Use this new FEN to change board display for both Player A and B. It is now B's turn again, so set
turn = black
. - If the pre-move was not valid, then don't change the game FEN any further. Use the existing FEN to override board display for Player A, since their pre-move was ignored. Now it is Player A's turn, so set
turn = white
.
Let me know if the above makes sense! Closing issue.
from gchessboard.
Related Issues (18)
- Add polyfill for aspect-ratio HOT 1
- Handle resize correctly for Safari HOT 1
- Initial release feature checklist
- Use Hungarian algorithm to find piece "moves" between two positions
- Use translate instead of absolute positioning for animating chess pieces HOT 1
- Export typings
- Hover does not trigger on Safari when dragging piece HOT 1
- Rudimentary markers support
- Advanced test cases
- Drag does not complete on mobile
- Add endMove() method
- Export types from declarations file HOT 1
- Add functionality for piece creation using drag-and-drop
- Add ability to draw arrows interactively
- Add sensible default color configurations
- Experiment with specifying arrows as nested web components
- Add ability to highlight specific fields by changing the background color HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gchessboard.