-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandEvaluator.java
36 lines (31 loc) · 929 Bytes
/
HandEvaluator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Alan Tan
7.5.16
This class evaluates a 5 card poker hand
*/
import java.util.*;
public class HandEvaluator {
// Evaluates the given hand and returns the String representing
// the best hand
// Null is returned if the inputHand is invalid
// (not sorted and/or not 5 unique cards)
public static String evaluate(PlayingCard[] inputHand) {
List<HandRank> allHandTypes = new ArrayList<HandRank>();
allHandTypes.add(new RoyalFlush());
allHandTypes.add(new StraightFlush());
allHandTypes.add(new FullHouse());
allHandTypes.add(new Flush());
allHandTypes.add(new Straight());
allHandTypes.add(new ThreeOfAKind());
allHandTypes.add(new TwoPair());
allHandTypes.add(new Pair());
allHandTypes.add(new HighCard());
for (int i = 0; i < allHandTypes.size(); i++) {
HandRank current = allHandTypes.get(i);
if (current.qualifies(inputHand)) {
return "" + current;
}
}
return null;
}
}