-
Notifications
You must be signed in to change notification settings - Fork 875
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
count number of pieces or count captures #82
Comments
So I think your approach would run into problems whenever a player promotes a pawn - it would incorrectly assume the pawn was captured. A better way to build the captured pieces sidebar would be to scan the game history ( var history = chess.history({verbose: true});
var initial = {w: {p: 0, n: 0, b: 0, r: 0, q: 0},
b: {p: 0, n: 0, b: 0, r: 0, q: 0}};
var captured = history.reduce(function(acc, move) {
if ('captured' in move) {
var piece = move.captured;
// switch colors since the history stores the color of the player doing the
// capturing, not the color of the captured piece
var color = move.color == 'w' ? 'b' : 'w';
acc[color][piece] += 1;
return acc;
} else {
return acc;
}
}, initial); Does that work for you? |
Yes, I was able to get the captured pieces to the sidebar, except for in the case of pawn promotion. I will try your suggested method as well. Also, I notice that in my two player real-time game, the castling doesn't show on the opponent's screen - instead, just the king's move - i.e., `e1-g1'. How can I pass into the board.move(notation) to make the king move as well? Or do I have to pass in FEN notation? Here is my code, using Pusher : channel.bind('new_move', function(data) {
|
When you call An simpler approach would be to call |
This sounds great. Thank you for the suggestions! |
I would like to be able to query the game for how many of each piece type are still on the board at any given time. For example, game.count('bP') could return 8. I would like to do this so I can display captured pieces on a sidebar. The simplest method I can think of is to check if the number of pawns < 8, then put the remainder of pawn icons in the sidebar. Any suggestions? Thank you in advance :).
The text was updated successfully, but these errors were encountered: