POKER

card類(lèi)

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類(lèi)

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("一對(duì)");
            str = "一對(duì)";
        } else if (valueset.size() == 3) {//兩隊(duì)或三條
            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("兩對(duì)");
                    str = "兩對(duì)";
                    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("三帶一對(duì)");
                    str = "三帶一對(duì)";
                    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);

    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 01 堅(jiān)果先生是我的好朋友,三個(gè)月前,他舉行了盛大的婚禮,賓朋滿(mǎn)座,我是扮狼。嗯,先是扮狼,后是伴郎。我們提前聚集...
    昕璐妹閱讀 1,467評(píng)論 29 10
  • 這款poker2買(mǎi)來(lái)已經(jīng)好久了,一直也就當(dāng)一個(gè)普通的機(jī)械鍵盤(pán)來(lái)使用。當(dāng)時(shí)買(mǎi)這款機(jī)械鍵盤(pán)出于三個(gè)考慮: 買(mǎi)不起HHK...
    telnetning閱讀 22,307評(píng)論 12 10
  • #觀察永澄50天-01天# 希望跟著永澄老師共同進(jìn)步,打破固有的模式建立屬于自己的系統(tǒng)。第一步:承諾堅(jiān)持50天認(rèn)真...
    燁彬0820閱讀 428評(píng)論 1 1
  • 小時(shí)候,我們心智不成熟,一遇到事情很容易就情緒化,如果看到對(duì)方做的不符合自己的要求就會(huì)很容易情緒化,由此誤會(huì),仇恨...
    瑚璉少年閱讀 883評(píng)論 0 0
  • 01 我們都應(yīng)該知道,二十歲左右的年紀(jì),是我們青春中最無(wú)畏、最勇敢的年齡。我們應(yīng)該珍惜這段時(shí)光,重視這段時(shí)光,而不...
    青禾姑娘閱讀 1,040評(píng)論 0 1

友情鏈接更多精彩內(nèi)容