def move(fromSqr, availMoves, choice): pc = copy.deepcopy(fromSqr.piece) pc.color = fromSqr.piece.color pc.type = fromSqr.piece.type track_last_pos(pc) toSqr = copy.deepcopy(availMoves[choice - 1]) deletePiece(toSqr.piece, fromSqr.piece) recordMove(fromSqr, toSqr) pc.row = toSqr.row pc.col = toSqr.col pc.selected = False #reset availMoves resetAvailMoves(availMoves) # update board with new piece board.uGrid(pc) updatePieces(pc) #turn off piece for fromSqr board.Grid(fromSqr.row, fromSqr.col).pieceStatus = False board.Grid(fromSqr.row, fromSqr.col).piece.color = "none" if pc.type == "pawn": pc.firstMove = False return pc
def check_pawn(pc): W_success = (pc.type == "pawn") and (globVar.player == "W") and (pc.row == 0) b_success = (pc.type == "pawn") and (globVar.player == "b") and (pc.row == 7) if W_success or b_success: if ((globVar.numPlayers == 1 and globVar.player == "W") or globVar.numPlayers == 2): choice = Canvas.pawn_to_new() else: choice = random.randint(1, 4) color = pc.color label = pc.label row = pc.row col = pc.col if choice == 1: pc = pieces.Rook(color, "rook") elif choice == 2: pc = pieces.Knight(color, "knight") elif choice == 3: pc = pieces.Bishop(color, "bishop") elif choice == 4: pc = pieces.Queen(color, "queen") pc.label = label pc.row = row pc.col = col updatePieces(pc) board.uGrid(pc)
def undoMove(): # read and build fpc fSqr_status = globVar.m_f_ps f_clr = globVar.m_f_p_color f_type = globVar.m_f_p_type f_label = globVar.m_f_p_label f_row = globVar.m_f_row f_col = globVar.m_f_col fpc = pieceConstructor(f_clr, f_type) fpc.label = f_label fpc.row = f_row fpc.col = f_col # read and build tpc tSqr_status = globVar.m_t_ps t_clr = globVar.m_t_p_color t_type = globVar.m_t_p_type t_label = globVar.m_t_p_label t_row = globVar.m_t_row t_col = globVar.m_t_col tpc = pieceConstructor(t_clr, t_type) tpc.label = t_label tpc.row = t_row tpc.col = t_col if fpc.type == "pawn": fpc.firstMove = globVar.m_fm # update the board board.uGrid(fpc) board.uGrid(tpc) updatePieces(fpc) board.Grid(fpc.row, fpc.col).pieceStatus = fSqr_status board.Grid(tpc.row, tpc.col).pieceStatus = tSqr_status # reset des board.Grid(fpc.row, fpc.col).des = False board.Grid(tpc.row, tpc.col).des = False if not globVar.removed: board.Grid(tpc.row, tpc.col).pieceStatus = False board.Grid(tpc.row, tpc.col).piece.color = "none" un_deletePiece(fpc) globVar.removed = False board.Grid(fpc.row, fpc.col).piece.selected = True
def un_deletePiece(fpc): if globVar.removed: index = find_r_Index(globVar.removed_label, globVar.removed_color) if fpc.color == "W": tmp_pc = copy.deepcopy(globVar.r_b_pieces[index]) globVar.b_pieces.append(tmp_pc) globVar.r_b_pieces.pop(index) globVar.b_NumPieces += 1 globVar.r_b_NumPieces -= 1 if tmp_pc.type == "king": globVar.no_b_king = False else: tmp_pc = copy.deepcopy(globVar.r_w_pieces[index]) globVar.w_pieces.append(tmp_pc) globVar.r_w_pieces.pop(index) globVar.w_NumPieces += 1 globVar.r_w_NumPieces -= 1 if tmp_pc.type == "king": globVar.no_w_king = False # put piece back on board board.uGrid(tmp_pc)