private static Player DecideWinner(List <Player> players) { foreach (var player in players) { player.HandAndBoard = player.Hand; player.HandAndBoard.AddRange(CardData.Board); BestHand.SetBestCards(player); } Player bestPlayer = players[0]; for (int i = 1; i < players.Count; i++) { if (players[i].BestHand.Value > bestPlayer.BestHand.Value) { bestPlayer = players[i]; } else if (players[i].BestHand.Value == bestPlayer.BestHand.Value) { for (int j = 0; j < 5; j++) { if (players[i].BestHand.BestCards[j].Number > bestPlayer.BestHand.BestCards[j].Number) { bestPlayer = players[i]; break; } else if (players[i].BestHand.BestCards[j].Number < bestPlayer.BestHand.BestCards[j].Number) { break; } } } } return(bestPlayer); }
public void CompareToShouldWorkCorrectly( ExpectedCompareResult expectedCompareResult, HandRankType firstHandRankType, ICollection <CardType> firstCardTypes, HandRankType secondHandRankType, ICollection <CardType> secondCardTypes) { var firstBestHand = new BestHand(firstHandRankType, firstCardTypes.Shuffle().ToList()); var secondBestHand = new BestHand(secondHandRankType, secondCardTypes.Shuffle().ToList()); var compareToResultFirstSecond = firstBestHand.CompareTo(secondBestHand); var compareToResultSecondFirst = secondBestHand.CompareTo(firstBestHand); switch (expectedCompareResult) { case ExpectedCompareResult.FirstShouldBeBetter: Assert.IsTrue(compareToResultFirstSecond > 0, "compareToResultFirstSecond > 0"); Assert.IsTrue(compareToResultSecondFirst < 0, "compareToResultSecondFirst < 0"); break; case ExpectedCompareResult.SecondShouldBeBetter: Assert.IsTrue(compareToResultFirstSecond < 0, "compareToResultFirstSecond < 0"); Assert.IsTrue(compareToResultSecondFirst > 0, "compareToResultSecondFirst > 0"); break; case ExpectedCompareResult.TheyShouldBeEqual: Assert.AreEqual(0, compareToResultFirstSecond); Assert.AreEqual(0, compareToResultSecondFirst); break; default: Assert.Fail("Invalid ExpectedCompareResult value"); break; } }
public void CheckForTwoPair() { User player = new User("Gosho", 1000); player.HandAndBoard = twoPairCards.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(3, player.BestHand.Value); }
public void CheckForStraightFlushWithDuplicates() { User player = new User("Gosho", 1000); player.HandAndBoard = straightFlushCardsWithDupl.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(9, player.BestHand.Value); }
public void CheckForFullHouse() { User player = new User("Gosho", 1000); player.HandAndBoard = fullHouseCards.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(7, player.BestHand.Value); }
public void ChecksForFlush() { User player = new User("Gosho", 1000); player.HandAndBoard = flushCards.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(6, player.BestHand.Value); }
public void ChecksForStraight() { User player = new User("Gosho", 1000); player.HandAndBoard = straightCards.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(5, player.BestHand.Value); }
private void CheckIfCurrentBestHandIsBestHand(BestHand currentBestHand, ref BestHand bestHandEver, ref int maxRank) { if ((int)currentBestHand.RankType > maxRank) { bestHandEver = currentBestHand; maxRank = (int)currentBestHand.RankType; } }
public void ShouldSayHightestPossibleHand(string hand, int handQuality) { Hand theHand = new Hand(hand); BestHand bestHand = new BestHand(); var result = bestHand.FindBestHand(theHand); Assert.That(result, Is.EqualTo(handQuality)); }
public void ChecksForStraightWithAceLow() { User player = new User("Gosho", 1000); player.HandAndBoard = aceLowStraightCards.ToList(); BestHand.SetBestCards(player); Assert.AreEqual(5, player.BestHand.Value); Assert.AreEqual(14, player.BestHand.BestCards.Last().Number); }
protected Player(string name, uint initialBalance) { this.Hand = new List <Card>(); this.Name = name; this.Balance = initialBalance; this.NotFolded = true; BestHand = new BestHand(); HandAndBoard = new List <Card>(); }
static void Main(string[] args) { Game game = new Game(); while (!game.IsGameOver) { Console.WriteLine($"Round: {game.Round} - Score: {game.Score}"); for (int lcv = 0; lcv < game.CurrentHand.Cards.Count; lcv++) { Card card = game.CurrentHand.Cards[lcv]; Console.Write($"({lcv + 1}) {card}\t"); } Console.WriteLine(); Console.WriteLine($"Select cards to keep as \"1 2\""); while (true) { string keepList = Console.ReadLine(); try { int[] keepIndexes = keepList.Split(" ").Select(item => int.Parse(item)).ToArray(); List <Card> keepCards = keepIndexes.Select(item => game.CurrentHand.Cards[item - 1]).Distinct().ToList(); BestHand result = game.Keep(keepCards); Console.WriteLine("Final hand:"); for (int lcv = 0; lcv < game.CurrentHand.Cards.Count; lcv++) { Card card = game.CurrentHand.Cards[lcv]; Console.Write($" {card}\t"); } Console.WriteLine(); Console.WriteLine($"Your best hand was a {result.HandType} worth {result.Points} points: {string.Join(' ', result.Cards.Select(item => item.ToString()))}"); break; } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } } Console.WriteLine(); if (!game.IsGameOver) { game.Deal(); } } }
public override void StartRound(StartRoundContext context) { base.StartRound(context); if (context.RoundType != GameRoundType.PreFlop) { this.BestHand = this.handEvaluator.GetBestHand( new List <Card>(this.CommunityCards) { this.FirstCard, this.SecondCard }); } }
public void FindStraightFlush() { CardHand hand = CardHand.FromCards( new Card(CardSuits.Spades, CardRanks.Two), new Card(CardSuits.Spades, CardRanks.Three), new Card(CardSuits.Spades, CardRanks.Four), new Card(CardSuits.Spades, CardRanks.Five), new Card(CardSuits.Spades, CardRanks.Six)); HandEvaluator evaluator = new HandEvaluator(); BestHand bestHand = evaluator.FindBestHand(hand); Assert.AreEqual(VideoPokerHands.StraightFlush, bestHand.HandType); }
public void FindRoyalFlush() { CardHand hand = CardHand.FromCards( new Card(CardSuits.Spades, CardRanks.Ace), new Card(CardSuits.Spades, CardRanks.King), new Card(CardSuits.Spades, CardRanks.Queen), new Card(CardSuits.Spades, CardRanks.Jack), new Card(CardSuits.Spades, CardRanks.Ten)); HandEvaluator evaluator = new HandEvaluator(); BestHand bestHand = evaluator.FindBestHand(hand); Assert.AreEqual(VideoPokerHands.RoyalFlush, bestHand.HandType); }
public void FindPairJacksOrBetter() { CardHand hand = CardHand.FromCards( new Card(CardSuits.Spades, CardRanks.Two), new Card(CardSuits.Spades, CardRanks.Three), new Card(CardSuits.Spades, CardRanks.Four), new Card(CardSuits.Spades, CardRanks.Ace), new Card(CardSuits.Hearts, CardRanks.Ace)); HandEvaluator evaluator = new HandEvaluator(); BestHand bestHand = evaluator.FindBestHand(hand); Assert.AreEqual(VideoPokerHands.JacksOrBetter, bestHand.HandType); }
public void FindFourOfAKind() { CardHand hand = CardHand.FromCards( new Card(CardSuits.Spades, CardRanks.Two), new Card(CardSuits.Clubs, CardRanks.Ace), new Card(CardSuits.Diamonds, CardRanks.Ace), new Card(CardSuits.Spades, CardRanks.Ace), new Card(CardSuits.Hearts, CardRanks.Ace)); HandEvaluator evaluator = new HandEvaluator(); BestHand bestHand = evaluator.FindBestHand(hand); Assert.AreEqual(VideoPokerHands.FourOfAKind, bestHand.HandType); }
public void ConstructorSetsProperties() { var rankType = HandRankType.Straight; var cardTypes = new List <CardType> { CardType.Ace, CardType.Three, CardType.Four, CardType.Five, CardType.Two }; var bestHand = new BestHand(rankType, cardTypes); Assert.AreEqual(rankType, bestHand.RankType); CollectionAssert.AreEquivalent(cardTypes, bestHand.Cards); }
public string GetWinningHand(Hand playerOneCards, Hand playerTwoCards) { BestHand playerOneBestHand = new BestHand(); BestHand playerTwoBestHand = new BestHand(); var playerOneHandValue = playerOneBestHand.FindBestHand(playerOneCards); var playerTwoHandValue = playerTwoBestHand.FindBestHand(playerTwoCards); if (playerOneHandValue == playerTwoHandValue) { return("It is a draw"); } if (playerOneHandValue > playerTwoHandValue) { return("Player One Wins"); } return("Player Two Wins"); }
async public Task <IActionResult> Keep(int[] cardIndexes) { Game game = this.SessionGet <Game>(this.SessionGameKey); if (game.IsGameOver) { return(this.RedirectToAction("Show")); } BestHand bestHand = game.Keep(cardIndexes.Where(item => item >= 0).Select(item => game.CurrentHand.Cards[item])); this.SessionSet(this.SessionGameKey, game); this.SessionSet(this.SessionBestHandKey, bestHand); await this.ProcessIfEndOfGame(game); return(this.RedirectToAction("Show")); }
public override PlayerAction GetTurn(GetTurnContext context) { // antiCrash prefix - do not delete if (context.MoneyLeft <= 0) { return(PlayerAction.CheckOrCall()); } if (!smallBlindFlag && context.RoundType == GameRoundType.PreFlop) { smallBlindFlag = true; isSmallBlind = context.MyMoneyInTheRound == context.SmallBlind; this.outs.Clear(); } if (context.RoundType == GameRoundType.Flop && (context.MoneyLeft + context.CurrentPot == 2000 || context.MoneyLeft == 0)) { if (context.PreviousRoundActions.Any() && context.PreviousRoundActions.Last().Action.Type == PlayerActionType.Fold) { magic = true; } } this.lastAction = context.PreviousRoundActions.Any() ? context.PreviousRoundActions.Last().Action.Type : PlayerActionType.Fold; // collecting info for opponent if (context.PreviousRoundActions.Any() && context.SmallBlind <= 10 && context.RoundType != GameRoundType.PreFlop) { if (context.CurrentPot >= 10) { this.opponentActions.Add(context.PreviousRoundActions.Last().Action.Type); } } if (this.opponentActions.Any() && ((!flag && context.SmallBlind == 2) || (flag && context.SmallBlind == 10))) { flag = true; isCallingStation = this.FindCallingStation(this.opponentActions); isVeryAggressive = this.FindAggressiveStation(this.opponentActions); } // get current Rank if (context.RoundType != GameRoundType.PreFlop) { this.currentBestHand = this.GetCurrentBestHand(); } // catching AlwaysRaisePlayer if (context.SmallBlind == 1 && !this.isAlwaysRaise && context.RoundType == GameRoundType.PreFlop && (context.PreviousRoundActions.Count == 3 || context.PreviousRoundActions.Count == 4)) { if (!this.isAlwaysRaise && context.MoneyToCall == 1) { this.raiseCount++; if (this.raiseCount > MagicNumber) { this.isAlwaysRaise = true; } } } // fishing prefix - handles fish and always raise player if ((this.isAlwaysRaise && !this.isAlwaysAllIn) || (context.MoneyToCall < MagicFishingNumber && context.RoundType != GameRoundType.PreFlop)) { if (context.RoundType != GameRoundType.River) { if (context.RoundType == GameRoundType.Turn) { if (this.FirstCard.Type == this.SecondCard.Type) { this.DoIt(this.hand, HandRankType.ThreeOfAKind); } else if (this.CurrentHandRank < HandRankType.Straight && this.FirstCard.Type != this.SecondCard.Type) { this.DoIt(this.hand, HandRankType.Straight); } } return(PlayerAction.CheckOrCall()); } if (context.RoundType == GameRoundType.River && this.CurrentHandRank >= HandRankType.Straight && this.CommunityImproved()) { return(PlayerAction.Raise(AllIn(context.MoneyLeft))); } if (this.ownCardsStrength >= CardValuationType.Strong && this.outs.Count < 5 && this.handEvaluator.GetBestHand(this.CommunityCards).RankType < HandRankType.Pair && this.CurrentHandRank >= HandRankType.TwoPairs) { return(PlayerAction.Raise((context.CurrentPot * 3) + MagicNumber)); } } // TODO: Some better way to access stages if (context.RoundType == GameRoundType.PreFlop) { return(this.PreflopLogic(context)); } if (context.RoundType == GameRoundType.Flop) { return(this.FlopLogic(context)); } if (context.RoundType == GameRoundType.Turn) { return(this.TurnLogic(context)); } if (context.RoundType == GameRoundType.River) { return(this.RiverLogic(context)); } return(PlayerAction.CheckOrCall()); }
public override PlayerAction GetTurn(GetTurnContext context) { // antiCrash prefix - do not delete if (context.MoneyLeft <= 0) { return PlayerAction.CheckOrCall(); } if (!smallBlindFlag && context.RoundType == GameRoundType.PreFlop) { smallBlindFlag = true; isSmallBlind = context.MyMoneyInTheRound == context.SmallBlind; this.outs.Clear(); } if (context.RoundType == GameRoundType.Flop && (context.MoneyLeft + context.CurrentPot == 2000 || context.MoneyLeft == 0)) { if (context.PreviousRoundActions.Any() && context.PreviousRoundActions.Last().Action.Type == PlayerActionType.Fold) { magic = true; } } this.lastAction = context.PreviousRoundActions.Any() ? context.PreviousRoundActions.Last().Action.Type : PlayerActionType.Fold; // collecting info for opponent if (context.PreviousRoundActions.Any() && context.SmallBlind <= 10 && context.RoundType != GameRoundType.PreFlop) { if (context.CurrentPot >= 10) { this.opponentActions.Add(context.PreviousRoundActions.Last().Action.Type); } } if (this.opponentActions.Any() && ((!flag && context.SmallBlind == 2) || (flag && context.SmallBlind == 10))) { flag = true; isCallingStation = this.FindCallingStation(this.opponentActions); isVeryAggressive = this.FindAggressiveStation(this.opponentActions); } // get current Rank if (context.RoundType != GameRoundType.PreFlop) { this.currentBestHand = this.GetCurrentBestHand(); } // catching AlwaysRaisePlayer if (context.SmallBlind == 1 && !this.isAlwaysRaise && context.RoundType == GameRoundType.PreFlop && (context.PreviousRoundActions.Count == 3 || context.PreviousRoundActions.Count == 4)) { if (!this.isAlwaysRaise && context.MoneyToCall == 1) { this.raiseCount++; if (this.raiseCount > MagicNumber) { this.isAlwaysRaise = true; } } } // fishing prefix - handles fish and always raise player if ((this.isAlwaysRaise && !this.isAlwaysAllIn) || (context.MoneyToCall < MagicFishingNumber && context.RoundType != GameRoundType.PreFlop)) { if (context.RoundType != GameRoundType.River) { if (context.RoundType == GameRoundType.Turn) { if (this.FirstCard.Type == this.SecondCard.Type) { this.DoIt(this.hand, HandRankType.ThreeOfAKind); } else if (this.CurrentHandRank < HandRankType.Straight && this.FirstCard.Type != this.SecondCard.Type) { this.DoIt(this.hand, HandRankType.Straight); } } return PlayerAction.CheckOrCall(); } if (context.RoundType == GameRoundType.River && this.CurrentHandRank >= HandRankType.Straight && this.CommunityImproved()) { return PlayerAction.Raise(AllIn(context.MoneyLeft)); } if (this.ownCardsStrength >= CardValuationType.Strong && this.outs.Count < 5 && this.handEvaluator.GetBestHand(this.CommunityCards).RankType < HandRankType.Pair && this.CurrentHandRank >= HandRankType.TwoPairs) { return PlayerAction.Raise((context.CurrentPot * 3) + MagicNumber); } } // TODO: Some better way to access stages if (context.RoundType == GameRoundType.PreFlop) { return this.PreflopLogic(context); } if (context.RoundType == GameRoundType.Flop) { return this.FlopLogic(context); } if (context.RoundType == GameRoundType.Turn) { return this.TurnLogic(context); } if (context.RoundType == GameRoundType.River) { return this.RiverLogic(context); } return PlayerAction.CheckOrCall(); }
public override string ToString() { return(String.Format("Name: {0}, Position: {1}, PlayerState: {2}, Credits: {3}, CurrentBet: {4}, BetAll: {5}, BestHand: {6}, Cards: {7}", Name, Position, PlayerState, Credits, CurrentBet, AllIn, BestHand?.ToString(), CardsString())); }
public VideoPokerShowViewModel(Game game, double elapsed, BestHand bestHand) { this.Game = game; this.Elapsed = elapsed; this.BestHand = bestHand; }
public void CompareToShouldWorkCorrectly( ExpectedCompareResult expectedCompareResult, HandRankType firstHandRankType, ICollection<CardType> firstCardTypes, HandRankType secondHandRankType, ICollection<CardType> secondCardTypes) { var firstBestHand = new BestHand(firstHandRankType, firstCardTypes.Shuffle().ToList()); var secondBestHand = new BestHand(secondHandRankType, secondCardTypes.Shuffle().ToList()); var compareToResultFirstSecond = firstBestHand.CompareTo(secondBestHand); var compareToResultSecondFirst = secondBestHand.CompareTo(firstBestHand); switch (expectedCompareResult) { case ExpectedCompareResult.FirstShouldBeBetter: Assert.IsTrue(compareToResultFirstSecond > 0, "compareToResultFirstSecond > 0"); Assert.IsTrue(compareToResultSecondFirst < 0, "compareToResultSecondFirst < 0"); break; case ExpectedCompareResult.SecondShouldBeBetter: Assert.IsTrue(compareToResultFirstSecond < 0, "compareToResultFirstSecond < 0"); Assert.IsTrue(compareToResultSecondFirst > 0, "compareToResultSecondFirst > 0"); break; case ExpectedCompareResult.TheyShouldBeEqual: Assert.AreEqual(0, compareToResultFirstSecond); Assert.AreEqual(0, compareToResultSecondFirst); break; default: Assert.Fail("Invalid ExpectedCompareResult value"); break; } }
public void ConstructorSetsProperties() { var rankType = HandRankType.Straight; var cardTypes = new List<CardType> { CardType.Ace, CardType.Three, CardType.Four, CardType.Five, CardType.Two }; var bestHand = new BestHand(rankType, cardTypes); Assert.AreEqual(rankType, bestHand.RankType); CollectionAssert.AreEquivalent(cardTypes, bestHand.Cards); }