def emit_move_signal(self, cord0, cord1, promotion=None): # Game end can change cord0 to None while dragging a piece if cord0 is None: return color = self.view.model.boards[-1].color board = self.view.model.getBoardAtPly(self.view.shown, self.view.shown_variation_idx) # Ask player for which piece to promote into. If this move does not # include a promotion, QUEEN will be sent as a dummy value, but not used if promotion is None and board[ cord0].sign == PAWN and cord1.cord in board.PROMOTION_ZONE[ color]: if self.variant.variant == SITTUYINCHESS: # no promotion allowed if we have queen if board.board.boards[color][QUEEN]: promotion = None else: # promotion is always optional promotion = self.getPromotion() if promotion is None and cord0 == cord1: # if don't want in place promotion return elif len(self.variant.PROMOTIONS) == 1: promotion = lmove.PROMOTE_PIECE(self.variant.PROMOTIONS[0]) else: if conf.get("autoPromote", False): promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) else: promotion = self.getPromotion() if promotion is None: # Put back pawn moved be d'n'd self.view.runAnimation(redraw_misc=False) return if cord0.x < 0 or cord0.x > self.FILES - 1: move = Move(lmovegen.newMove(board[cord0].piece, cord1.cord, DROP)) else: move = Move(cord0, cord1, board, promotion) if (self.view.model.curplayer.__type__ == LOCAL or self.view.model.examined) and \ self.view.shownIsMainLine() and \ self.view.model.boards[-1] == board and \ self.view.model.status == RUNNING: if self.setup_position: self.emit("piece_moved", (cord0, cord1), board[cord0].color) else: self.emit("piece_moved", move, color) if self.view.model.examined: self.view.model.connection.bm.sendMove(toAN(board, move)) else: if board.board.next is None and not self.view.shownIsMainLine(): self.view.model.add_move2variation( board, move, self.view.shown_variation_idx) self.view.shown += 1 else: new_vari = self.view.model.add_variation(board, (move, )) self.view.setShownBoard(new_vari[-1])
def emit_move_signal(self, cord0, cord1, promotion=None): # Game end can change cord0 to None while dragging a piece if cord0 is None: return board = self.getBoard() color = board.color # Ask player for which piece to promote into. If this move does not # include a promotion, QUEEN will be sent as a dummy value, but not used if promotion is None and board[cord0].sign == PAWN and \ cord1.cord in board.PROMOTION_ZONE[color] and \ self.variant.variant != SITTUYINCHESS: if len(self.variant.PROMOTIONS) == 1: promotion = lmove.PROMOTE_PIECE(self.variant.PROMOTIONS[0]) else: if conf.get("autoPromote"): promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) else: promotion = self.getPromotion() if promotion is None: # Put back pawn moved be d'n'd self.view.runAnimation(redraw_misc=False) return if promotion is None and board[cord0].sign == PAWN and \ cord0.cord in board.PROMOTION_ZONE[color] and \ self.variant.variant == SITTUYINCHESS: # no promotion allowed if we have queen if board.board.boards[color][QUEEN]: promotion = None # in place promotion elif cord1.cord in board.PROMOTION_ZONE[color]: promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) # queen move promotion (but not a pawn capture!) elif board[cord1] is None and (cord0.cord + cord1.cord) % 2 == 1: promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) if cord0.x < 0 or cord0.x > self.FILES - 1: move = Move(lmovegen.newMove(board[cord0].piece, cord1.cord, DROP)) else: move = Move(cord0, cord1, board, promotion) if (self.view.model.curplayer.__type__ == LOCAL or self.view.model.examined) and \ self.view.shownIsMainLine() and \ self.view.model.boards[-1] == board and \ self.view.model.status == RUNNING: # emit move if self.setup_position: self.emit("piece_moved", (cord0, cord1), board[cord0].color) else: self.emit("piece_moved", move, color) if self.view.model.examined: self.view.model.connection.bm.sendMove(toAN(board, move)) else: self.play_or_add_move(board, move)
def release(self, x_loc, y_loc): cord = self.point2Cord(x_loc, y_loc) if cord == self.view.active == self.view.selected == self.parent.selected_last: # User clicked (press+release) same piece twice, so unselect it self.view.active = None self.view.selected = None self.view.dragged_piece = None self.view.startAnimation() self.parent.setStateNormal() elif self.parent.allowPremove and self.view.selected and self.isAPotentiallyLegalNextMove( self.view.selected, cord): # In mixed locked selected/active state and user selects a valid premove cord board = self.getBoard() if board[self.view.selected].sign == PAWN and \ cord.cord in board.PROMOTION_ZONE[1 - board.color]: if conf.get("autoPromote"): promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) else: promotion = self.parent.getPromotion() else: promotion = None self.view.setPremove(board[self.view.selected], self.view.selected, cord, self.view.shown + 2, promotion) self.view.selected = None self.view.active = None self.view.dragged_piece = None self.view.startAnimation() self.parent.setStateNormal() elif self.parent.allowPremove and self.isAPotentiallyLegalNextMove( self.view.active, cord): # User drags a piece to a valid premove square board = self.getBoard() if board[self.view.active].sign == PAWN and \ cord.cord in board.PROMOTION_ZONE[1 - board.color]: if conf.get("autoPromote"): promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) else: promotion = self.parent.getPromotion() else: promotion = None self.view.setPremove(self.getBoard()[self.view.active], self.view.active, cord, self.view.shown + 2, promotion) self.view.selected = None self.view.active = None self.view.dragged_piece = None self.view.startAnimation() self.parent.setStateNormal() elif self.view.active or self.view.selected: # Select last piece user tried to move or that was selected self.view.selected = self.view.active if self.view.active else self.view.selected self.view.active = None self.view.dragged_piece = None self.view.startAnimation() self.parent.setStateSelected() else: self.view.active = None self.view.selected = None self.view.dragged_piece = None self.view.startAnimation() self.parent.setStateNormal() self.parent.selected_last = self.view.selected
def emit_move_signal(self, cord0, cord1, promotion=None): # Game end can change cord0 to None while dragging a piece if cord0 is None: return gating = None board = self.getBoard() color = board.color # Ask player for which piece to promote into. If this move does not # include a promotion, QUEEN will be sent as a dummy value, but not used if promotion is None and board[cord0].sign == PAWN and \ cord1.cord in board.PROMOTION_ZONE[color] and \ self.variant.variant != SITTUYINCHESS: if len(self.variant.PROMOTIONS) == 1: promotion = lmove.PROMOTE_PIECE(self.variant.PROMOTIONS[0]) elif self.variant.variant == LIGHTBRIGADECHESS: promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION if color == WHITE else KNIGHT_PROMOTION) else: if conf.get("autoPromote"): promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) else: promotion = self.getPromotion() if promotion is None: # Put back pawn moved be d'n'd self.view.runAnimation(redraw_misc=False) return if promotion is None and board[cord0].sign == PAWN and \ cord0.cord in board.PROMOTION_ZONE[color] and \ self.variant.variant == SITTUYINCHESS: # no promotion allowed if we have queen if board.board.boards[color][QUEEN]: promotion = None # in place promotion elif cord1.cord in board.PROMOTION_ZONE[color]: promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) # queen move promotion (but not a pawn capture!) elif board[cord1] is None and (cord0.cord + cord1.cord) % 2 == 1: promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION) holding = board.board.holding[color] if self.variant.variant == SCHESS: moved = board[cord0].sign hawk = holding[HAWK] > 0 elephant = holding[ELEPHANT] > 0 if (hawk or elephant) and cord0.cord in iterBits( board.board.virgin[color]): castling = moved == KING and abs(cord0.x - cord1.x) == 2 gating = self.getGating(castling, hawk, elephant) if gating is not None: if gating in (HAWK_GATE_AT_ROOK, ELEPHANT_GATE_AT_ROOK): side = 0 if cord0.x - cord1.x == 2 else 1 rcord = board.board.ini_rooks[color][side] move = Move(lmovegen.newMove(rcord, cord0.cord, gating)) else: move = Move(lmovegen.newMove(cord0.cord, cord1.cord, gating)) elif cord0.x < 0 or cord0.x > self.FILES - 1: move = Move(lmovegen.newMove(board[cord0].piece, cord1.cord, DROP)) else: move = Move(cord0, cord1, board, promotion) if (self.view.model.curplayer.__type__ == LOCAL or self.view.model.examined) and \ self.view.shownIsMainLine() and \ self.view.model.boards[-1] == board and \ self.view.model.status == RUNNING: # emit move if self.setup_position: self.emit("piece_moved", (cord0, cord1), board[cord0].color) else: self.emit("piece_moved", move, color) if self.view.model.examined: self.view.model.connection.bm.sendMove(toAN(board, move)) else: self.play_or_add_move(board, move)