//Finds the best onsuit play, which is win with the worst of the best, or just go with the worst //It's given that there's at least two valid moves. Must return a valid move public int findOnsuitPlay(Trick currentTrick, ArrayList validMoves) { int index = 0; bool winnable = false; for (int i = 0; i < validMoves.Count; i++) { //If we can beat the current card if (isBetterCard(currentTrick.getMoves()[currentTrick.currentWinner], (Card)validMoves[i], currentTrick.trumpSuit)) { //There was no previous winning card if (!winnable) { winnable = true; index = i; } //There is already a winnable card else { //If the old card can beat the new card, we want to use the new one to save the better if (isBetterCard((Card)validMoves[i], (Card)validMoves[index], currentTrick.trumpSuit)) { index = i; } } } //This card can't beat the current card, and there isn't yet a card that can else if (!winnable) { //If the old card can beat the new card, we want to use the new to save our better one if (isBetterCard((Card)validMoves[i], (Card)validMoves[index], currentTrick.trumpSuit)) { index = i; } } } return(index); }
public void updatedCardCount(Trick pastTrick) { counter.removeGroup(new ArrayList(pastTrick.getMoves())); }