public void _evaluateTrick(IGameState gameState) { var winner = TrickHelper.PlayerWinningTrick(gameState); winner.TricksTaken++; gameState.CurrentPlayer = winner; OnTrickCompleted?.Invoke(this, new TrickCompletedEventArgs(winner)); }
public virtual ICard ChooseNonLeadCard(IGameState gameState) { //get valid indexes var validCards = CardHelper.GetValidCards(gameState.LeadSuit, gameState.Trump, gameState.CurrentPlayer.Cards).ToList(); var nonTrumpCards = CardHelper.GetAllNonTrump(gameState.Trump, validCards).ToList(); var trumpCards = CardHelper.GetAllTrump(gameState.Trump, validCards).ToList(); //if partner is winning, consider throwing low var currentWinner = TrickHelper.PlayerWinningTrick(gameState); var ourTeamIsWinningTheTrick = currentWinner.TeamNumber == gameState.CurrentPlayer.TeamNumber; if (ourTeamIsWinningTheTrick) { return(_throwJunk(nonTrumpCards, trumpCards)); } else { if (trumpCards.Any()) { //do we have any trump that out ranks the highest played? var highestTrumpPlayed = CardHelper.GetHighestTrump(gameState.Trump, gameState.CurrentHand.Select(x => x.Card).ToList()); var higherTrumpInMyHand = validCards.FirstOrDefault(x => x.IsGreaterThan(highestTrumpPlayed, gameState.Trump)); if (higherTrumpInMyHand != null) { return(higherTrumpInMyHand); } return(_throwJunk(nonTrumpCards, trumpCards)); } else { return(nonTrumpCards.OrderByDescending(x => x.Rank.Value).FirstOrDefault()); } } }