Skip to content
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

about onDragStart #222

Open
jimmyyzr opened this issue Jul 9, 2021 · 1 comment
Open

about onDragStart #222

jimmyyzr opened this issue Jul 9, 2021 · 1 comment

Comments

@jimmyyzr
Copy link

jimmyyzr commented Jul 9, 2021

Hi, I am trying to understand the code in onDragStart Preven Drag. I specifically want to ask what does piece.search(/^w/) mean? Is there any document that I can read? I am right now having a bug that when the player is in check, he cannot make any move. atthattime game.turn() === 'w' and piece.search(/^w/) === 0. Below is my onDragStart function. Could you please help me understanding this? Thank you so much!

var onDragStart = function(source, piece, position, orientation) {
  console.log("game turn: ", game.turn());
  console.log("player state: ", PlayerState);
  console.log("player turn: ", PlayerTurn);
  if (game.game_over() === true ||
      (game.turn() === 'w' && piece.search(/^b/) !== -1) ||
      (game.turn() === 'b' && piece.search(/^w/) !== -1) ||
      PlayerState === 'IDLE') {
    console.log("move forbidden");
    console.log("piece search b", piece.search(/^b/));
    console.log("piece search w", piece.search(/^w/));
    return false;
  }
};
@banhmisg9509
Copy link

"I specifically want to ask what does piece.search(/^w/) mean? "
It checks every string which starts with "w". That's mean It checks whether It was a white piece or not, for example wK, w,Q, wN, wB, wR, wP,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants