0

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
  • Forgot to add that userPosition refers to positon that user sits on table (i.e early position, dealer etc)! Thanks! –  Nov 24 '13 at 19:52
  • 1
    Unrelated to programming but related to poker, you should also take into consideration the numerical difference of the two cards. The further apart two cards are (2, K) the smaller the straight possibility. – Leon Newswanger Nov 24 '13 at 19:57
  • it is not an answer, but a golder suggestion: FOLLOW [CLEAN CODE][1] INSTRUCTIONS Some are: - Use constants with meaningful names - break you code into multiple small methods (each about 5 statements) and name the method properly - each method shall have only a single responsibility there are much more rules, but use them, so your code will be easier to read and understand, even by yourself. [1]: http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 – Amir Pashazadeh Nov 24 '13 at 20:05

1 Answers1

0

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!");
dansalmo
  • 11,506
  • 5
  • 58
  • 53
  • Thanks a lot that was extremely helpful! Is there any possible way of determining the correct play based upon individual hands rather than hand value. I.e. if cards are "k10" call but if "k9" fold? Thanks –  Nov 25 '13 at 14:46
  • It would be "kt" not "k10". This depends on why one hand would be better than the other. KT is a 2-gap hand where k9 is a three gap. Similar to the examples above, you could do `if (Math.abs(card1 - card2) == 4) //fold` to detect a 3 gap hand. If the only 3 gap you would play is AT you do `if (Math.abs(card1 - card2) == 4 & !(card1 + card2 == 25)) //fold` – dansalmo Nov 25 '13 at 16:17
  • You have been very helpful thanks a lot! Do u think there is a market for this sort of app/program? weve Been tasked with making a project of this type in college! –  Nov 25 '13 at 18:16
  • Can you please take a look at the following code (it uses the code you gave me from above): –  Nov 25 '13 at 22:46
  • (card1 || (card2) = (values.indexOf(hand[12]) ||(values.indexOf(hand[13]))) && (hand[3].equalsIgnoreCase("s") –  Nov 25 '13 at 22:46
  • Here I am trying to write a peice of code that says "For any suited ace or king" then I will say "Go all in". But i am unaware of how to code it to make it any suited ace or king! thanks –  Nov 25 '13 at 22:47
  • I will edit my answer above to add that case. Do you know how to accept an answer by clicking on the check mark? – dansalmo Nov 25 '13 at 23:00
  • I accepted your answer there thanks! Do you mind if I send u a few specific cases to code? For example how would you code for "Any suited ace" Or "Q8" as in q9, q10, qj...but not j8 etc...Thanks! –  Nov 26 '13 at 11:22
  • I have changed the code to make it easier to test for various cases. – dansalmo Nov 26 '13 at 18:30