def piecesAround(board, cord): kingMoves = moveArray[KING] friends = board.friends[board.color] for co_ord in iterBits(kingMoves[cord] & friends): yield co_ord, board.arBoard[co_ord], board.color enemies = board.friends[1 - board.color] for co_ord in iterBits(kingMoves[cord] & enemies): yield co_ord, board.arBoard[co_ord], 1 - board.color
def test3(self): """Testing iterbits""" for positions, board in self.positionSets: positions.sort() itered = sorted(iterBits(board)) self.assertEqual(positions, itered)
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)
def cordsAround(cord): kingMoves = moveArray[KING] for co_ord in iterBits(kingMoves[cord.cord]): yield Cord(co_ord)