当前位置:首页 » 《关注互联网》 » 正文

模拟斗地主发牌_zuimeng2226的博客

22 人参与  2022年01月20日 10:52  分类 : 《关注互联网》  评论

点击全文阅读


/*
    按照斗地主的规则,完成洗牌发牌的动作。
    要求完成以下功能:
    准备牌:组装54张扑克牌
    洗牌:54张牌顺序打乱
    发牌:三个玩家参与游戏,三人交替摸牌,每人17张牌,最后三张留作底牌。
    看牌:查看三人各自手中的牌(按照牌的大小排序)、底牌

    规则:手中扑克牌从大到小的摆放顺序:大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3

 */

/**
 * @Descriptionn:test
 * @Create by:依然
 * @Date:2021/9/24 10:27
 */
public class DouDiZhu {
    public static void main(String[] args) {
        //键为序号,值为牌面
        HashMap<Integer, String> hashMap = new HashMap<>();
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] pai = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        int cout = 2;
        for (String s : pai) {
            for (String color : colors) {
                // System.out.println("配对为:"+cout+":"+(s+color));
                hashMap.put(cout, (s + color));
                cout++;
            }
        }
        //System.out.println(hashMap);
        hashMap.put(0, "大王");
        hashMap.put(1, "小王");

        //洗牌
        //获取hashMap中的序号
        Set<Integer> set = hashMap.keySet();
        //建立集合
        List<Integer> list = new ArrayList<>();
        //将序号添加到集合中
        list.addAll(set);
        Collections.shuffle(list);
        //打乱后的序号
        //System.out.println(list);

        //发牌

        // 发牌
        TreeSet<Integer> 赌神 = new TreeSet<>();
        TreeSet<Integer> 赌圣 = new TreeSet<>();
        TreeSet<Integer> 赌侠 = new TreeSet<>();
        TreeSet<Integer> 底牌 = new TreeSet<>();
        //list储存牌的编号
        //留三张底牌
        for (int i = 0; i < list.size() - 3; i++) {
            if (i % 3 == 0) {
                //public E get(int index):返回集合中指定位置的元素
                赌神.add(list.get(i));
            } else if (i % 3 == 1) {
                赌圣.add(list.get(i));
            } else {
                赌侠.add(list.get(i));
            }
        }

        底牌.add(list.get(51));
        底牌.add(list.get(52));
        底牌.add(list.get(53));
        //测试牌
        // System.out.println("赌神:" + 赌神);
        // System.out.println("赌圣:" + 赌圣);
        // System.out.println("赌侠:" + 赌侠);
        // System.out.println("底牌:" + 底牌);

        //看牌
        System.out.print("赌神:");
        for (Integer integer : 赌神) {
            String s = hashMap.get(integer);
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.print("赌圣:");
        for (Integer integer : 赌圣) {
            String s = hashMap.get(integer);
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.print("赌侠:");
        for (Integer integer : 赌侠) {
            String s = hashMap.get(integer);
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.print("底牌:");
        for (Integer integer : 底牌) {
            String s = hashMap.get(integer);
            System.out.print(s + " ");
        }

    }
}


点击全文阅读


本文链接:http://zhangshiyu.com/post/33590.html

底牌  发牌  赌神  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1