Question

I am attempting to write a program that helps a user make the correct EV play for each hand. However at the minute I am using card value (i.e. total of two cards) to base my decisions. For example 9=9, 10=10, j=11, q=12.... I would like the use to be able to enter in their actualy hands e.g. Adks (ace of diamonds, king of spades). This would be more accurate as it would take into account the suited value of the hand etc. Can anyone give me advice on the best way to incorporate this? Many thanks in advance! My cuurent code is below!

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
Was it helpful?

Solution

If you take the card input like this; "AA", "9T" or "9Ts", you can then compute a hand value based on suitedness and gaps like such using you input cards:

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!");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top