From charlesreid1

Problem Statement

POKER TIME!!!

This problem asks us to compare 1 thousand poker hands and count the number of hands player 1 wins.

  • High Card: Highest value card.
  • One Pair: Two cards of the same value.
  • Two Pairs: Two different pairs.
  • Three of a Kind: Three cards of the same value.
  • Straight: All cards are consecutive values.
  • Flush: All cards of the same suit.
  • Full House: Three of a kind and a pair.
  • Four of a Kind: Four cards of the same value.
  • Straight Flush: All cards are consecutive values of same suit.
  • Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.

Solution Technique

The technique was to implement each type of hand as a boolean check, and run through checks of each type of hand in the correct order. I also wrote lots of individual sanity checks to test particular types of hands and make sure they would win if they were supposed to.

I also used Java and implemented a PokerHand object as a comparable, so that I could do something like if(hand1>hand2) playerOneWins++

I also had arrays of outcomes and card values.

class PokerHand implements Comparable<PokerHand> { 
	
	public static final String[] OUTCOMES = {"high","one","two","three","straight","flush","full house","four","straight flush","royal flush"};
	public static final char[] VALUES = {'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
	public static final char[] SUITS = {'S','C','D','H'};

Code

Link: https://charlesreid1.com:3000/cs/euler/src/master/scratch/Round2_050-070/054

Flags