Ejemplo n.º 1
0
def is_move_valid(match, srcx, srcy, dstx, dsty, prom_piece):
    # print(" counts " + str(match.wKg_first_movecnt) + " " + str(match.wRk_h1_first_movecnt)  + " " + str(match.wRk_a1_first_movecnt))
    # print(" counts " + str(match.bKg_first_movecnt) + " " + str(match.bRk_h8_first_movecnt)  + " " + str(match.bRk_a8_first_movecnt))
    # print("-------------------------------------------")
    if not is_move_inbounds(srcx, srcy, dstx, dsty):
        return False, ERROR_CODES["out-of-bounds"]

    piece = match.readfield(srcx, srcy)

    if match.next_color() != Match.color_of_piece(piece):
        return False, ERROR_CODES["wrong-color"]

    if piece != Match.PIECES["wKg"] and piece != Match.PIECES["bKg"]:
        if is_king_after_move_attacked(match, srcx, srcy, dstx, dsty):
            return False, ERROR_CODES["king-error"]

    if piece == Match.PIECES["wPw"] or piece == Match.PIECES["bPw"]:
        if not pawn.is_move_ok(match, srcx, srcy, dstx, dsty, piece, prom_piece):
            return False, ERROR_CODES["pawn-error"]
        else:
            return True, ERROR_CODES["none"]
    elif piece == Match.PIECES["wRk"] or piece == Match.PIECES["bRk"]:
        if not rook.is_move_ok(match, srcx, srcy, dstx, dsty, piece):
            return False, ERROR_CODES["rook-error"]
        else:
            return True, ERROR_CODES["none"]
    elif piece == Match.PIECES["wKn"] or piece == Match.PIECES["bKn"]:
        if not knight.is_move_ok(match, srcx, srcy, dstx, dsty, piece):
            return False, ERROR_CODES["knight-error"]
        else:
            return True, ERROR_CODES["none"]
    elif piece == Match.PIECES["wBp"] or piece == Match.PIECES["bBp"]:
        if not bishop.is_move_ok(match, srcx, srcy, dstx, dsty, piece):
            return False, ERROR_CODES["bishop-error"]
        else:
            return True, ERROR_CODES["none"]
    elif piece == Match.PIECES["wQu"] or piece == Match.PIECES["bQu"]:
        if not queen.is_move_ok(match, srcx, srcy, dstx, dsty, piece):
            return False, ERROR_CODES["queen-error"]
        else:
            return True, ERROR_CODES["none"]
    elif piece == Match.PIECES["wKg"] or piece == Match.PIECES["bKg"]:
        if not king.is_move_ok(match, srcx, srcy, dstx, dsty, piece):
            return False, ERROR_CODES["king-error"]
        else:
            return True, ERROR_CODES["none"]
    else:
        return False, ERROR_CODES["general-error"]
Ejemplo n.º 2
0
def is_move_ok(match, srcx, srcy, dstx, dsty, piece):
    if(rook.is_move_ok(match, srcx, srcy, dstx, dsty, piece)):
        return True
    else:
        return bishop.is_move_ok(match, srcx, srcy, dstx, dsty, piece)