C ++ Poker:跳过If语句,忽略值

时间:2015-04-09 23:30:49

标签: c++

我一直在用C ++创建扑克,我注意到在我确定(或者我认为)玩家的手之后,它总是显示为皇家同花顺(或者9,就手动而言)。我对它进行了测试,结果发现用于确定手的if语句被忽略了。为什么这些陈述没有注册,如何修复?附:我知道这段代码有点长,如果你不想看它,请继续。

    int hand_ranking = 0;
        bool one_pair_bool;
        int one_pair;


        bool two_pair_bool;
        int two1_pair;
        int two2_pair;

        if (min_all == min2_all){
            one_pair = min_all;
            one_pair_bool = true;


            if (mid_card == max2_all){
                two_pair_bool = true;
                two1_pair = min_all;
                two2_pair = mid_card;

            }

            else if (max2_all == max_all){
                two_pair_bool = true;
                two1_pair = min_all;
                two2_pair = max2_all;

            }
            else{
                two_pair_bool = false;
            }
        }
        else if (min2_all == mid_card){
            one_pair = min2_all;
            one_pair_bool = true;

            if (max2_all == max_all){
                two_pair_bool = true;
                two1_pair = min2_all;
                two2_pair = max2_all;
            }

            else {
                two_pair_bool = false;
            }
        }
        else if (mid_card == max2_all){
            one_pair = mid_card;
            one_pair_bool = true;

            if (min_all == min2_all){
                two_pair_bool = true;
                two1_pair = mid_card;
                two2_pair = min_all;
            }
            else{
                two_pair_bool = false;
            }
        }
        else if (max2_all == max_all){
            one_pair = max2_all;
            one_pair_bool = true;

            if (min_all == min2_all){
                two_pair_bool = true;
                two1_pair = max2_all;
                two2_pair = min_all;
            }
            else if (min2_all == mid_card){
                two_pair_bool = true;
                two1_pair = max2_all;
                two2_pair = min2_all;
            }
            else{
                two_pair_bool = false;
            }
        }
        else{
            one_pair_bool = false;
        }



        bool three_of_a_kind;
        int three_of_a_kind_number;

        if (min_all == min2_all && min2_all == mid_card){
            three_of_a_kind = true;
            three_of_a_kind_number = min_all;
        }

        else if (min2_all == mid_card && mid_card == max2_all){
            three_of_a_kind = true;
            three_of_a_kind_number = min2_all;
        }

        else if (mid_card == max2_all && max2_all == max_all){
            three_of_a_kind = true;
            three_of_a_kind_number = mid_card;
        }

        else {
            three_of_a_kind = false;
        }


        bool straight;
        int straight_start;

        if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1){
            straight = true;
            straight_start = min_all;
        }
        else {
            straight = false;
        }

        bool flush;
        char flush_suit;

        if (min_suit == min2_suit == mid_suit == max2_suit == max_suit){
            flush = true;
            flush_suit = min_suit;
        }

        bool full_house;
        int full_house2;
        int full_house3;

        if (min_all == min2_all && min2_all == mid_card){
            if (max2_all == max_all){
                full_house = true;
                full_house2 = max2_all;
                full_house3 = min_all;
            }
        }

        else if (min2_all == mid_card && mid_card == max2_all){

        }

        else if (mid_card == max2_all && max2_all == max_all){
            if (min_all == min2_all){
                full_house = true;
                full_house2 = min_all;
                full_house3 = mid_card;
            }
        }

        else {

        }

        bool four_of_a_kind;
        int four_of_a_kind_number;

        if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1){
            four_of_a_kind = true;
            four_of_a_kind_number = min_all;
        }
        else if (min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1){
            four_of_a_kind = true;
            four_of_a_kind_number = min2_all;
        }

        bool straight_flush;
        char straight_flush_suit;
        int straight_flush_start;

        if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1 && min_suit == min2_suit && min2_suit == mid_suit && mid_suit == max2_suit && max2_suit == max_suit){
            straight_flush = true;
            straight_flush_start = min_all;
            straight_flush_suit = min_suit;
        }
        else {
            straight_flush = false;
        }

        bool royal_flush = false;
        char royal_flush_suit;

        if (min_all == 1 && min2_all == 10 && mid_card == 11 && max2_all == 12 && max_all == 13 && min_suit == min2_suit && min2_suit == mid_suit && mid_suit == max2_suit && max2_suit == max_suit){
            royal_flush = true;
            royal_flush_suit = min_suit;
        }
        else{
            royal_flush = false;
        }


        if (royal_flush = true){
            hand_ranking = 9;

        }
        else if (straight_flush == true){
            hand_ranking = 8;
        }
        else if (four_of_a_kind == true){
            hand_ranking = 7;
        }
        else if (full_house == true){
            hand_ranking = 6;
        }
        else if (flush == true){
            hand_ranking = 5;
        }
        else if (straight == true){
            hand_ranking = 4;
        }
        else if (three_of_a_kind == true){
            hand_ranking = 3;
        }
        else if (two_pair_bool == true){
            hand_ranking = 2;
        }
        else if (one_pair == true){
            hand_ranking = 1;
        }
        else{}

1 个答案:

答案 0 :(得分:3)

看起来你正在分配而不是比较:

    if (royal_flush = true){
        hand_ranking = 9;

    }

该行将royal_flush设置为true并始终评估为true,因此始终将hand_ranking设置为9。

我假设你在if语句中想要royal_flush == true,它会比较这两个值。 if(true == royal_flush)是编写此代码的好方法,以便编译器捕获这些类型的错误。而且if(royal_flush)也可以。