Result: Whenever I try to remove a triplet of J, Q, and K, my program does not remove them and replace them with new cards. The boolean methods that determine whether or not cards should be removed (either J, Q, and K together or sum pair of 11 are removed and replaced) are below. However, the method that determines whether or not a pair of cards add up to 11 works. Thanks so much!
/**
* Determines if the selected cards form a valid group for removal.
* In Elevens, the legal groups are (1) a pair of non-face cards
* whose values add to 11, and (2) a group of three cards consisting of
* a jack, a queen, and a king in some order.
* @param selectedCards the list of the indices of the selected cards.
* @return true if the selected cards form a valid group for removal;
* false otherwise.
*/
public boolean isLegal(List<Integer> selectedCards)
{
boolean toReturn = true;
int jack = 0;
int queen = 0;
int king = 0;
for(int count = 0; count < selectedCards.size() - 1; count++)
{
for(int counter = count + 1; counter < selectedCards.size(); counter++)
{
if(cards[selectedCards.get(count)].pointValue() == 0 || cards[selectedCards.get(counter)].pointValue() == 0)
{
if(cards[selectedCards.get(count)].rank().equals("jack") || cards[selectedCards.get(counter)].rank().equals("jack"))
{
jack = 11;
}
else if(cards[selectedCards.get(count)].rank().equals("queen") || cards[selectedCards.get(counter)].rank().equals("queen"))
{
queen = 12;
}
else if(cards[selectedCards.get(count)].rank().equals("king") || cards[selectedCards.get(counter)].rank().equals("king"))
{
king = 13;
}
}
if(cards[selectedCards.get(count)].pointValue() + cards[selectedCards.get(counter)].pointValue() == 11)
{
toReturn = true;
return true;
}
else if(jack == 11 && queen == 12 && king == 13)
{
toReturn = true;
return true;
}
else
{
toReturn = false;
}
}
}
return toReturn;
}
--------------
/**
* Check for a JQK in the selected cards.
* @param selectedCards selects a subset of this board. It is list
* of indexes into this board that are searched
* to find a JQK group.
* @return true if the board entries in selectedCards
* include a jack, a queen, and a king; false otherwise.
*/
private boolean containsJQK(List<Integer> selectedCards)
{
boolean toReturn = true;
int jack = 0;
int queen = 0;
int king = 0;
for(int count = 0; count < selectedCards.size(); count++)
{
if(cards[selectedCards.get(count)].pointValue() == 0)
{
if(cards[selectedCards.get(count)].rank().equals("jack"))
{
jack = 11;
}
else if(cards[selectedCards.get(count)].rank().equals("queen"))
{
queen = 12;
}
else if(cards[selectedCards.get(count)].rank().equals("king"))
{
king = 13;
}
}
}
if(jack == 11 && queen == 12 && king == 13)
{
toReturn = true;
}
else
{
toReturn = false;
}
return toReturn;
}