POKER

card类

public class card{
    private int value;
    private String color;

    public String toString() {
        String str = "";
        if (value == 11) {
            str = "J";
        } else if (value == 12) {
            str = "Q";
        } else if (value == 13) {
            str = "K";
        } else if (value == 1) {
            str = "A";
        } else {
            str = value + " ";
        }
        return color + str;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

}


Poker类

public class poker2 {
    private List<card2> cards = new ArrayList<card2>();
    private int[] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,};
    private String[] colors = {"红桃", "梅花", "黑桃", "方片"};

    public poker2() {
        for (int i = 0; i < 52; i++) {
            card2 card2s = new card2();
            card2s.setColor(colors[i / 13]);
            card2s.setValue(values[i % 13]);
            cards.add(card2s);
        }
    }

    public void show() {

        System.out.println(cards + "\t");
    }

    public void shuffer() {
        Collections.shuffle(cards);
    }

    public List<card2> takecard() {
        int n = 0;
        List<card2> card2List = new ArrayList<card2>();
        for (card2 c : cards) {
            card2List.add(c);
            n++;
            if (n == 5) {
                break;
            }
        }
        return card2List;
    }

    public String texttype(List<card2> card2List) {
        boolean isfoluwer = false;
        boolean isshunzi = false;
        String str = "h";
        Set<String> colorset = new HashSet<String>();
        for (card2 cc : card2List) {
            colorset.add(cc.getColor());
        }
        Set<Integer> valueset = new HashSet<Integer>();
        List<Integer> valuelist = new ArrayList<Integer>();
        for (card2 cc : card2List) {
            valueset.add(cc.getValue());
            valuelist.add(cc.getValue());
        }
        Collections.sort(valuelist);

        if (colorset.size() == 1) {
            isfoluwer = true;
        }
        if (valueset.size() == 5 && valuelist.get(4) - valuelist.get(0) == 4) {
            isshunzi = true;
        }
        if (isfoluwer == true && isshunzi == true) {
            // System.out.println("同花顺");
            str = "同花顺";
        } else if (isfoluwer == true) {
            // System.out.println("同花");
            str = "同花";
        } else if (isshunzi == true) {
            //System.out.println("顺子");
            str = "顺子";
        } else if (valueset.size() == 5) {
            // System.out.println("杂牌");
            str = "杂牌";
        } else if (valueset.size() == 4) {
            // System.out.println("一对");
            str = "一对";
        } else if (valueset.size() == 3) {//两队或三条
            Map<Integer, Integer> mapCardValue2Times = new HashMap<>();
            for (card2 card2 : card2List) {
                if (mapCardValue2Times.containsKey(card2.getValue())) {
                    int c = mapCardValue2Times.get(card2.getValue());
                    c++;
                    mapCardValue2Times.put(card2.getValue(), c);
                } else {
                    mapCardValue2Times.put(card2.getValue(), 1);
                }
            }
            for (Integer integer : mapCardValue2Times.keySet()) {//(8,2)(5,2) (4,1) (5,3) (3,1)(4,1)
                if (mapCardValue2Times.get(integer) == 2) {
                    //System.out.println("两对");
                    str = "两对";
                    break;
                } else if (mapCardValue2Times.get(integer) == 3) {
                    // System.out.println("三条");
                    str = "三条";
                    break;
                }
            }
        } else if (valueset.size() == 2) {//四代一或三代二
            Map<Integer, Integer> mapCardValue2Times = new HashMap<>();
            for (card2 card2 : card2List) {
                if (mapCardValue2Times.containsKey(card2.getValue())) {
                    int c = mapCardValue2Times.get(card2.getValue());
                    c++;
                    mapCardValue2Times.put(card2.getValue(), c);
                } else {
                    mapCardValue2Times.put(card2.getValue(), 1);
                }
            }
            for (Integer integer : mapCardValue2Times.keySet()) {//(8,4)(5,1) (5,3) (3,2)
                if (mapCardValue2Times.get(integer) == 4) {
                    // System.out.println("四带一");
                    str = "四带一";
                    break;
                } else if (mapCardValue2Times.get(integer) == 3) {
                    //System.out.println("三带一对");
                    str = "三带一对";
                    break;
                }
            }
        }

        return str;
    }


}


主方法

public class pokermain {
    public static void main(String[] args) {
        poker2 p = new poker2();
        p.show();
        p.shuffer();
        System.out.println();
        p.show();
        List<card2> cl = p.takecard();
        System.out.println(cl);
        String string = p.texttype(cl);
        System.out.println(string);

    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 01 坚果先生是我的好朋友,三个月前,他举行了盛大的婚礼,宾朋满座,我是扮狼。嗯,先是扮狼,后是伴郎。我们提前聚集...
    昕璐妹阅读 5,259评论 29 10
  • 这款poker2买来已经好久了,一直也就当一个普通的机械键盘来使用。当时买这款机械键盘出于三个考虑: 买不起HHK...
    telnetning阅读 22,197评论 12 10
  • #观察永澄50天-01天# 希望跟着永澄老师共同进步,打破固有的模式建立属于自己的系统。第一步:承诺坚持50天认真...
    烨彬0820阅读 2,924评论 1 1
  • 小时候,我们心智不成熟,一遇到事情很容易就情绪化,如果看到对方做的不符合自己的要求就会很容易情绪化,由此误会,仇恨...
    瑚琏少年阅读 4,237评论 0 0
  • 01 我们都应该知道,二十岁左右的年纪,是我们青春中最无畏、最勇敢的年龄。我们应该珍惜这段时光,重视这段时光,而不...
    青禾姑娘阅读 4,511评论 0 1

友情链接更多精彩内容