gpt4 book ai didi

Java:扑克手牌

转载 作者:行者123 更新时间:2023-12-02 05:28:29 25 4
gpt4 key购买 nike

所以,我必须使用函数/方法和数组创建一个扑克牌程序。

这是我需要的示例输出:

Enter five numeric cards, no face cards. Use 2 - 9.Card 1: 8 Card 2: 7Card 3: 8Card 4: 2Card 5: 7Two Pair!Enter five numeric cards, no face cards. Use 2 - 9.Card 1: 4 Card 2: 5Card 3: 6Card 4: 8Card 5: 7Straight!Enter five numeric cards, no face cards. Use 2 - 9.Card 1: 9Card 2: 2Card 3: 3Card 4: 4Card 5: 5High Card!

And here's my code (I'm having issues with logic in determining if one gets pair, 3 of a kind, etc.). They have be methods/functions. So, if I can figure out how to do 1 or 2 of them, it should be hopefully be a breeze from there:

import java.util.Scanner;

public class Assignment4
{
public static void main(String args[])
{
final int LEN = 5;
int[] hand = new int[LEN];

Scanner input = new Scanner(System.in);

//input the hand
System.out.println("Enter five numeric cards, no face cards. Use 2-9.");
for (int index = 0; index < hand.length; index++) {
System.out.print("Card " + (index + 1) + ": ");
hand[index] = input.nextInt();
}

//sort the collection
bubbleSortCards(hand);

//determine players hand type
//flow of evaluation -> checking complex hands first
if (containsFullHouse(hand)) {
System.out.println("Full House!");
} else if (containsStraight(hand)) {
System.out.println("Straight!");
} else if (containsFourOfaKind(hand)) {
System.out.println("Four of a Kind!");
} else if (containsThreeOfaKind(hand)) {
System.out.println("Three of a Kind!");
} else if (containsTwoPair(hand)) {
System.out.println("Two Pair!");
} else if (containsPair(hand)) {
System.out.println("Pair!");
} else
System.out.println("High Card!");
}

这是作业说明中推荐的方法:

public class PokerHand
{
public static void main(String args[])
{
int hand[] = {5, 2, 2, 3, 8};

if (containsAPair(hand)) {
System.out.println("Pair!");
} else {
System.out.println("Not a pair!");
}
}

public static boolean containsAPair(int hand[]) {
// Your code here... don’t return true every time...
return true;
}

}

如果需要更多信息,我将非常乐意提供。谢谢!

最佳答案

我建议您计算手牌的内容并生成一个计数数组,而不是对手牌进行排序,其中数组的第 ith 元素有值为i的卡片数量。然后您应该能够弄清楚如何使用该数组来确定它是否是特定类型的手牌。

关于Java:扑克手牌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25774914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com