首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扑克电动汽车计算器:计算手值?

扑克电动汽车计算器:计算手值?
EN

Stack Overflow用户
提问于 2013-11-24 19:51:24
回答 1查看 562关注 0票数 0

我试图写一个程序,帮助用户使正确的EV播放每一只手。然而,在这一分钟,我使用卡值(即总共两张卡)作为我的决定的基础。比如9=9,10=10,j=11,q=12.我希望能够在他们的实际手中进入,例如Adks (钻石王牌,黑桃之王)。这将是更准确的,因为它将考虑到合适的价值,手等。谁能给我的意见,最好的方式纳入这一点?事先非常感谢!我的密码在下面!

代码语言:javascript
复制
package uk.ac.qub.lectures;

//importing resources (scanner)
import java.util.Scanner;

public class PokeGame {

    public static final int MIN_POSITION = 1;
    public static final int MAX_POSITION = 8;

    public static void main(String[] args) {
        // declaring user position
        int userPosition = 0;
        // setting up scanner
        Scanner scanner = new Scanner(System.in);
        // integer referring to use again or not
        int useAgain = 0;
        // boolean getting valid input for repeat
        boolean repeat = false;

        // declaring number value of each card
        int cards;

        do {

            // getting user position
            do {
                System.out.printf("Please enter position between %d and %d\n",MIN_POSITION, MAX_POSITION);
                userPosition = scanner.nextInt();
            } while ((userPosition < MIN_POSITION)  || (userPosition > MAX_POSITION));
            // getting hand hand strength
            System.out.println("Enter card value");
            cards = scanner.nextInt();

            switch (userPosition) {

            case 1:
            case 2:
                if (cards > 10) {
                    System.out.println("SHOVE");
                } else
                    System.out.println("FOLD");
                break;
            case 3:
            case 4:
            case 5:
                if (cards > 13) {
                    System.out.println("SHOVE");
                } else
                    System.out.println("FOLD");
                break;
            case 6:
            case 7:
            case 8:
                if (cards > 17) {
                    System.out.println("SHOVE");
                } else
                    System.out.println("FOLD");
                break;
            default:
                System.out.println("ENTER VALID POSITION");
            }
            do {

                System.out.println("Do you advice on another Hand?");
                System.out.println("Enter 1 for Yes, Enter 0 for No");
                useAgain = scanner.nextInt();
                if ((useAgain == 1) || (useAgain == 0)) {

                    repeat = false;
                } else {

                    System.out.println("Invalid Input, please enter 1 or 0");
                    repeat = true;
                }
            } while (repeat);
        } while (useAgain != 0);

        // clean up resources
        scanner.close();
    }// method end

}// class end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-24 20:52:08

如果您将卡片输入如下:"AA“、"9T”或“9T”,则可以使用输入卡根据合适性和空白计算手值:

代码语言:javascript
复制
import java.util.Arrays;
import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
String[] hand = (scanner.nextLine() + 'u').toUpperCase().split("");
String values = "  23456789TJQKA";
int[] cards = new int[] {values.indexOf(hand[1]), values.indexOf(hand[2])};
Arrays.sort(cards);
int gap = cards[1] - cards[0] - 1;
boolean pair = gap == -1;
boolean suited = hand[3].equals("S");
char[] cards = new char[] {(char)values.charAt(cards[0]), (char)values.charAt(cards[1])};
int handValue = 0;

// adjust value based on pairs, suitedness or connectedness
if (pair) // hand is a pair
    handValue += 10; //or whatever you want
else if (suited) // hand is suited
    handValue += 3; //or whatever you want

if (gap == 0) // hand is no gap
    handValue += 5; //or whatever you want.

if (gap == 1) // hand is one gap
    handValue += 3; //or whatever you want.

if (cards[1] == 'A' && cards[0] == 'K' && suited) // AK suited
    System.out.println("AK Suited!");
else if (cards[1] == 'A' && suited) // Ax suited
    System.out.println("Ax Suited!");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20180133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档