Implement compareHands method, add compareHands tests and fix UserIO Test

This commit is contained in:
Mitch Peck
2022-02-18 19:35:54 -06:00
parent db1e32a314
commit 5f28cd03fe
3 changed files with 128 additions and 6 deletions

View File

@@ -198,15 +198,28 @@ public class Game {
}
/**
* Compares two hands accounting for natural blackjacks
* Compares two hands accounting for natural blackjacks using the
* java.lang.Comparable convention of returning positive or negative integers
*
* @param handA hand to compare
* @param handB other hand to compare
* @return a negative integer, zero, or a positive integer as handA is less than, equal to, or greater than handB.
*/
private int compareHands(LinkedList<Card> handA, LinkedList<Card> handB) {
// TODO implement compareHands
return 0;
protected int compareHands(LinkedList<Card> handA, LinkedList<Card> handB) {
int scoreA = this.scoreHand(handA);
int scoreB = this.scoreHand(handB);
if(scoreA == 21 && scoreB == 21){
if(handA.size() == 2 && handB.size() != 2){
return 1; //Hand A wins
} else if (handA.size() != 2 && handB.size() == 2) {
return -1; //Hand B wins
} else {
return 0; //Tie
}
} else {
return Integer.compare(scoreA, scoreB);
}
}
/**