斗地主发牌理牌

代码

   private static <list> void swap(List<list> list,int a,int b) {
    list list1=list.get(a);
    list.set(a, list.get(b));
    list.set(b, list1);
}

private static ArrayList<String> zhengli(ArrayList<String> x){
    ArrayList<Integer> a=new ArrayList<>();
    int b=-1;

    for (int i = 0; i < x.size(); i++) {
        if(x.get(i).equals("大王"))
            b=170;
        else if(x.get(i).equals("小王"))
            b=160;
        else {
            if (x.get(i).substring(1).equals("A"))
                b = 140;
            else if (x.get(i).substring(1).equals("2"))
                b = 150;
            else if (x.get(i).substring(1).equals("J"))
                b = 110;
            else if (x.get(i).substring(1).equals("Q"))
                b= 120;
            else if (x.get(i).substring(1).equals("K"))
                b = 130;
            else b= Integer.parseInt(x.get(i).substring(1)) * 10;

            if(x.get(i).substring(0,1).equals("♥")){
                b+=4;
            }else if(x.get(i).substring(0,1).equals("♦")){
                b+=3;
            }else if(x.get(i).substring(0,1).equals("♠")){
                b+=2;
            }else if(x.get(i).substring(0,1).equals("♣")){
                b+=1;
            }
        }
        a.add(b);
    }



    for (int i = x.size(); i > 1; i--) {
        for (int j = 0; j < i-1; j++) {
            if(a.get(j) < a.get(j+1)){
                swap(a,j,j+1);
                swap(x,j,j+1);
            }
        }
    }

    return x;
}

    public static void main (String[]args){
        List<String> pokes = new ArrayList<>();
        List<String> colors = new ArrayList<>();
        List<String> numbers = new ArrayList<>();

        colors.add("❥");
        colors.add("♠");
        colors.add("♦");
        colors.add("♣");
        for (int i = 2; i <= 10; i++) {
            numbers.add(i + "");
        }
        numbers.add("A");
        numbers.add("J");
        numbers.add("Q");
        numbers.add("K");
        for (String c : colors) {
            for (String n : numbers) {
                String pai = c + n;
                pokes.add(pai);
            }
        }
            pokes.add("大王");
            pokes.add("小王");
            System.out.println(pokes);
            Collections.shuffle(pokes);
            System.out.println(pokes);

            ArrayList<String> a = new ArrayList<>();
            ArrayList<String> b = new ArrayList<>();
            ArrayList<String> d = new ArrayList<>();
            ArrayList<String> dipai = new ArrayList<>();
            for (int i = 0; i < pokes.size(); i++) {
                String pai = pokes.get(i);
                if (i > 51) {
                    dipai.add(pai);
                } else {
                    if (i % 3 == 0) {
                        a.add(pai);
                    } else if (i % 3 == 1) {
                        b.add(pai);
                    } else {
                        d.add(pai);
                    }
                }

            }
            System.out.println(dipai);
            System.out.println(a);
            System.out.println(b);
            System.out.println(d);
            a=zhengli(a);
            b=zhengli(b);
            d=zhengli(d);
            dipai=zhengli(dipai);

            System.out.println("\n整理后:");
            System.out.println(a);
            System.out.println(b);
            System.out.println(d);
            System.out.println(dipai);

        }
    }

运行结果

[❥2, ❥3, ❥4, ❥5, ❥6, ❥7, ❥8, ❥9, ❥10, ❥A, ❥J, ❥Q, ❥K, ♠2, ♠3, ♠4, ♠5, ♠6, ♠7, ♠8, ♠9, ♠10, ♠A, ♠J, ♠Q, ♠K, ♦2, ♦3, ♦4, ♦5, ♦6, ♦7, ♦8, ♦9, ♦10, ♦A, ♦J, ♦Q, ♦K, ♣2, ♣3, ♣4, ♣5, ♣6, ♣7, ♣8, ♣9, ♣10, ♣A, ♣J, ♣Q, ♣K, 大王, 小王]
[小王, ♣3, ♠7, ❥3, ♠A, ♣9, ♠2, ♦7, ❥5, ♦9, ♠8, ❥6, ♣Q, ♠10, ♠K, ♦10, ❥K, ♣7, 大王, ♣2, ♦5, ❥A, ♠5, ❥9, ♦4, ♣10, ♣5, ♣8, ♣4, ♣A, ♦6, ❥J, ♠Q, ♦2, ♦Q, ♦A, ♣J, ♠9, ♣K, ♣6, ❥7, ❥2, ♠3, ❥8, ❥10, ❥Q, ♦J, ♦K, ♦8, ❥4, ♠J, ♦3, ♠6, ♠4]
[♠6, ♠4]
[小王, ❥3, ♠2, ♦9, ♣Q, ♦10, 大王, ❥A, ♦4, ♣8, ♦6, ♦2, ♣J, ♣6, ♠3, ❥Q, ♦8, ♦3]
[♣3, ♠A, ♦7, ♠8, ♠10, ❥K, ♣2, ♠5, ♣10, ♣4, ❥J, ♦Q, ♠9, ❥7, ❥8, ♦J, ❥4]
[♠7, ♣9, ❥5, ❥6, ♠K, ♣7, ♦5, ❥9, ♣5, ♣A, ♠Q, ♦A, ♣K, ❥2, ❥10, ♦K, ♠J]

整理后:
[大王, 小王, ♦2, ♠2, ❥A, ♣Q, ❥Q, ♣J, ♦10, ♦9, ♦8, ♣8, ♦6, ♣6, ♦4, ♦3, ♠3, ❥3]
[♣2, ♠A, ❥K, ♦Q, ♦J, ❥J, ♠10, ♣10, ♠9, ♠8, ❥8, ♦7, ❥7, ♠5, ♣4, ❥4, ♣3]
[❥2, ♦A, ♣A, ♦K, ♠K, ♣K, ♠Q, ♠J, ❥10, ♣9, ❥9, ♠7, ♣7, ❥6, ♦5, ♣5, ❥5]
[♠6, ♠4]

©️2020 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值