public HandResult CheckTitle(int[] cards) { HandResult result = new HandResult(); result.handType = HandResult.HandType.TITLE; cards[0] = -1; cards[1] = -1; cards[2] = -1; cards[3] = -1; cards[4] = -1; for (int i = 0; i < cards.Length; i++) { result.hands[i] = GetCardOrder(cards, i) % 13; if (result.hands[i] == 0) { result.hands[i] = 13; } result.AddMadeCard(cards[i]); } return(result); }
/// <summary> /// Compare the player hands and determine the winner /// </summary> /// <param name="player1"></param> /// <param name="player2"></param> /// <returns></returns> public static Player DetermineWinner(Player player1, Player player2) { var player1Result = HandResult.DetermineHandResult(player1.PlayerHand); var player2Result = HandResult.DetermineHandResult(player2.PlayerHand); if (player1Result.Item1.CompareTo(player2Result.Item1) > 0) { return(player1); } // both results are the same, determine by the High card else if (player1Result.Item1.CompareTo(player2Result.Item1) == 0) { if (player1Result.Item2.CompareTo(player2Result.Item2) > 0) { return(player1); } else { return(player2); } } else { return(player2); } }
private void winHand(HandResult handResult, int handIndex) { this.processedHand[handIndex] = true; this.gameService.ProcessHandResult(handResult, this.currentBet); this.RefreshBankAmountOnScreen(); DisplayWinDialog(handIndex); }
public static string GetResultName(HandResult result) { switch (result) { case HandResult.JacksOrBetter: return("Jacks Or Better"); case HandResult.TwoPairs: return("Two Pairs"); case HandResult.ThreeOfAKind: return("Three of a Kind"); case HandResult.Straight: return("Straight"); case HandResult.Flush: return("Flush"); case HandResult.FullHouse: return("Full House"); case HandResult.FourOfAKind: return("Four of a Kind"); case HandResult.StraightFlush: return("Straight Flush"); case HandResult.RoyalFlush: return("Royal Flush"); default: return(null); } }
public void SetGamePlayer(GamePlayer gamePlayer, Room room) { stage = gamePlayer.stage; status = (GamePlayerState)gamePlayer.state; chairIndex = gamePlayer.chairIndex; card1 = gamePlayer.card1; card2 = gamePlayer.card2; orderNo = gamePlayer.orderNo; buyInLeft = gamePlayer.buyInLeft; lastBetType = (BetType)gamePlayer.lastBetType; betCount = gamePlayer.betCount; lastBet = gamePlayer.lastBet; lastCall = gamePlayer.lastCall; lastRaise = gamePlayer.lastRaise; stageBet = gamePlayer.stageBet; totalBet = gamePlayer.totalBet; userIndex = gamePlayer.userIndex; coin = gamePlayer.coin; nickName = gamePlayer.nickName; result = gamePlayer.result; isMyTurn = gamePlayer.userIndex == room.currentUserIndex && roomStage % 3 == 0; betCount = room.betCount; roomStage = room.stage; isWinner = room.winnerUserIndex == gamePlayer.userIndex; roomState = (int)room.state; }
private void DisplayHandResult(HandResult handResult) { Console.SetCursorPosition(40, 9); if (handResult == HandResult.PlayerBust) { Console.WriteLine($"You were busted! You lost your bet of {_currentPlayer.CurrentBet} chips."); } else if (handResult == HandResult.DealerBust) { Console.WriteLine($"The dealer was busted. You win {_currentPlayer.CurrentBet} chips!"); } else if (handResult == HandResult.Push) { Console.WriteLine($"It's a push! You get your bet {_currentPlayer.CurrentBet} back."); } else if (handResult == HandResult.Blackjack) { Console.WriteLine($"Blackjack. You win {_currentPlayer.CurrentBet * 1.5} chips!"); } else if (handResult == HandResult.Loss) { Console.WriteLine($"You lost! {_currentPlayer.CurrentBet} will be taken from you."); } else if (handResult == HandResult.Win) { Console.WriteLine($"You win {_currentPlayer.CurrentBet} fresh shiny chips."); } Console.WriteLine(); }
public void Update(GamePlayerModel model) { stage = model.stage; status = model.status; chairIndex = model.chairIndex; card1 = model.card1; card2 = model.card2; orderNo = model.orderNo; buyInLeft = model.buyInLeft; lastBetType = model.lastBetType; betCount = model.betCount; lastBet = model.lastBet; lastCall = model.lastCall; lastRaise = model.lastRaise; stageBet = model.stageBet; totalBet = model.totalBet; result = model.result; userIndex = model.userIndex; coin = model.coin; nickName = model.nickName; isMyTurn = model.isMyTurn; roomStage = model.roomStage; roomState = model.roomState; isWinner = model.isWinner; }
private void CheckWinner(Room room) { if (room.stage == 13) { List <GamePlayer> playerList = table.SelectSitGamePlayer(room.index); WinnerValidator validator = WinnerValidator.Instance; for (int i = 0; i < playerList.Count; i++) { HandResult result = validator.GetResult(new int[] { room.card1, room.card2, room.card3, room.card4, room.card5, playerList[i].card1, playerList[i].card2 }); playerList[i].result = result; table.UpdateGamePlayer(room.index, playerList[i]); } room.winnerUserIndex = WinnerValidator.Instance.GetWinner(playerList); room.waitTimeout = Room.WAITTIMEOUT_BY_READY; room.currentUserIndex = 0; room.currentOrderNo = -1; room.stage = 14; table.UpdateRoom(room); } else { room.stage += 1; room.waitTimeout = Room.WAITTIMEOUT_BY_SETTING; room.stageBet = 0; room.currentOrderNo = 0; room.currentUserIndex = 0; table.UpdateRoom(room); } }
private void CheckHands() { result.handType = HandResult.HandType.NONE; SetCards(); cards[0] = 41; cards[1] = 44; cards[2] = 10; cards[3] = 29; cards[4] = 3; cards[5] = 17; cards[6] = 35; Array.Sort(cards); for (int i = hands.Length - 1; i >= 0; i--) { result = hands[i](cards); if (result.handType != HandResult.HandType.NONE) { print(result.handType); break; } } }
public void ShownHands() { HandResult LuckyPlayerResult = NoLimitHand1.PlayerResult("Lucky Player"); HandResult SuperCoolPlayerResult = NoLimitHand1.PlayerResult("SuperCoolPlayer"); Assert.AreEqual("6d Ts", Card.ToString(LuckyPlayerResult.HoleCards)); Assert.AreEqual("6s Qs", Card.ToString(SuperCoolPlayerResult.HoleCards)); }
public void Pots() { Assert.AreEqual(2, NoLimitHand1.Results.Length); HandResult LuckyPlayerResult = NoLimitHand1.PlayerResult("Lucky Player"); Assert.AreEqual(1, LuckyPlayerResult.WonPots.Length); Assert.AreEqual(559.60, LuckyPlayerResult.WonPots[0].Amount); Assert.AreEqual(0, LuckyPlayerResult.WonPots[0].Number); }
private void handBet(HandResult result) { greenWinLabel.Visibility = Visibility.Hidden; redLoseLabel.Visibility = Visibility.Hidden; tieLabel.Visibility = Visibility.Hidden; if (currentBet == 0) { currentBet = 1; currentBetTextBlock.Text = $"$ {currentBet}"; } switch (result) { case HandResult.Banker: if (bankerRadioButton.IsChecked == true) { greenWinLabel.Visibility = Visibility.Visible; amountWonTextBlock.Text = $"$ {currentBet * (decimal)0.95}"; chipStackUpdate(currentBet * (decimal)0.95); } else { redLoseLabel.Visibility = Visibility.Visible; amountWonTextBlock.Text = $"$ {-currentBet}"; chipStackUpdate(-currentBet); } break; case HandResult.Player: if (playerRadioButton.IsChecked == true) { greenWinLabel.Visibility = Visibility.Visible; amountWonTextBlock.Text = $"$ {currentBet}"; chipStackUpdate(currentBet); } else { redLoseLabel.Visibility = Visibility.Visible; amountWonTextBlock.Text = $"$ {-currentBet}"; chipStackUpdate(-currentBet); } break; case HandResult.Tie: tieLabel.Visibility = Visibility.Visible; amountWonTextBlock.Text = "$ 0"; break; case HandResult.Error: break; default: break; } }
public HandResult CheckRoyalStraightFlush(int[] cards) { HandResult result = new HandResult(); int[,] hands = { { 0, 9, 10, 11, 12 } ,{ 13, 22, 23, 24, 25 } ,{ 26, 35, 36, 37, 38 } ,{ 39, 48, 49, 50, 51 } }; int handsCount = 4; int cardsCount = 5; int matchCount = 0; int compare1 = -1; int compare2 = -1; for (int i = 0; i < handsCount; i++) { matchCount = 0; result.InitializeMadeCard(); for (int k = 0; k < cardsCount; k++) { for (int j = 0; j < cards.Length; j++) { compare1 = hands[i, k]; compare2 = cards[j]; if (compare2 == -1) { continue; } if (compare1 == compare2) { matchCount++; result.AddMadeCard(compare1); } } } if (matchCount == cardsCount) { result.handType = HandResult.HandType.ROYAL_STRAIGHT_FLUSH; result.cardType = (HandResult.CardType)i + 1; break; } matchCount = 0; } return(result); }
private static void CheckResult(Player player1, ref bool straightFound, ref string handString) { var result = HandResult.DetermineHandResult(player1.PlayerHand); if (result.Item1 == HandResult.HandResults.Straight || result.Item1 == HandResult.HandResults.StraightFlush) { foreach (var card in player1.PlayerHand.Cards) { handString += card.CardSuitString + card.CardNumberString + ","; } straightFound = true; } }
public void WinnerCalculatorShouldWork(HandType p1HandType, int p1Point, int p1BetRate, HandType p2HandType, int p2Point, int p2BetRate, int betAmount, int expectedReturnAmount) { var p1Hand = new HandResult { Point = p1Point, Hand = p1HandType, BetReturnRate = p1BetRate }; var p2Hand = new HandResult { Point = p2Point, Hand = p2HandType, BetReturnRate = p2BetRate }; var pokdeng = new Pokdeng(); var ReturnAmount = pokdeng.WinnerCalculator(p1Hand, p2Hand, betAmount); Assert.Equal(expectedReturnAmount, ReturnAmount); }
public HandResult CalculateCardInHand(int CardNo1, int CardNo2, int CardNo3, string CardSymbol1, string CardSymbol2, string CardSymbol3) { var Result = new HandResult() { Hand = HandType.ไม่มี, BetReturnRate = 1, Point = PointCalculator(CardNo1, CardNo2, CardNo3) }; if (CardNo3 == 0) { if (Result.Point > 7) { Result.Hand = HandType.ป๊อก; } if (CardNo1 == CardNo2 || CardSymbol1 == CardSymbol2) { Result.BetReturnRate = 2; } } else if (CardNo1 == CardNo2 && CardNo2 == CardNo3) { Result.Hand = HandType.ตอง; Result.BetReturnRate = 5; } else if (CardNo1 >= 11 && CardNo1 <= 13 && CardNo2 >= 11 && CardNo2 <= 13 && CardNo3 >= 11 && CardNo3 <= 13) { Result.Hand = HandType.ผี; Result.BetReturnRate = 3; } else { ReOrderCardInHand(ref CardNo1, ref CardNo2, ref CardNo3, ref CardSymbol1, ref CardSymbol2, ref CardSymbol3); if (CardNo1 + 1 == CardNo2 && CardNo2 + 1 == CardNo3) { Result.Hand = HandType.เรียง; Result.BetReturnRate = 3; } else { if (CardSymbol1 == CardSymbol2 && CardSymbol2 == CardSymbol3) { Result.BetReturnRate = 3; } } } return(Result); }
public static List <T> GetObjectList <T>(Dictionary <string, object>[] dicts) { List <T> objs = null; Type type = typeof(T); if (dicts != null && dicts.Length > 0) { objs = new List <T>(); for (int i = 0; i < dicts.Length; i++) { T obj = (T)Activator.CreateInstance(type); foreach (var kv in dicts[i]) { System.Reflection.FieldInfo property = type.GetField(kv.Key); if (property != null) { if (property.FieldType == typeof(DateTime)) { property.SetValue(obj, DateTime.Parse((string)kv.Value)); } else if (property.FieldType == typeof(HandResult)) { Dictionary <string, object> handResultValue = (Dictionary <string, object>)kv.Value; if (handResultValue.Count > 0) { HandResult result = GetObject <HandResult>(handResultValue); property.SetValue(obj, result); } } else { property.SetValue(obj, kv.Value); } } } objs.Add(obj); } } return(objs); }
public void TestHandResult() { var hand = new Hand(); hand.Cards = BuildRoyalFlush(); var result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.RoyalFlush, result.Item1); hand.Cards = BuildStraightFlush(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.StraightFlush, result.Item1); hand.Cards = Build4OfAkind(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.FourOfAKind, result.Item1); hand.Cards = BuildFullHouse(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.FullHouse, result.Item1); hand.Cards = BuildFlush(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.Flush, result.Item1); hand.Cards = BuildStraight(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.Straight, result.Item1); hand.Cards = Build3OfAkind(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.ThreeOfAKind, result.Item1); hand.Cards = BuildTwoPair(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.TwoPair, result.Item1); hand.Cards = BuildPair(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.Pair, result.Item1); hand.Cards = BuildHighCard(); result = HandResult.DetermineHandResult(hand); Assert.AreEqual(HandResult.HandResults.HighCard, result.Item1); Assert.AreEqual(PokerGameCore.Model.Numbers.CardNumbers.Ace, result.Item2); }
public int WinnerCalculator(HandResult p1Hand, HandResult p2Hand, int betAmount) { var returnAmount = 0; var SameHandType = p1Hand.Hand == p2Hand.Hand && (p1Hand.Hand == HandType.ป๊อก || p1Hand.Hand == HandType.ไม่มี); var p1Win = p1Hand.Hand > p2Hand.Hand || (SameHandType && p1Hand.Point > p2Hand.Point); var p2Win = p1Hand.Hand < p2Hand.Hand || (SameHandType && p1Hand.Point < p2Hand.Point); if (p1Win) { returnAmount = betAmount * p1Hand.BetReturnRate * -1; } else if (p2Win) { returnAmount = betAmount * p2Hand.BetReturnRate; } return(returnAmount); }
public void HandEvaluator(HandResult result, Rank rankOne, Suit suitOne, Rank rankTwo, Suit suitTwo, Rank rankThree, Suit suitthree, Rank rankFour, Suit suitFour, Rank rankFive, Suit SuitFive) { Card[] hand = { new Card(rankOne, suitOne), new Card(rankTwo, suitTwo), new Card(rankThree, suitthree), new Card(rankFour, suitFour), new Card(rankFive, SuitFive) }; Assert.AreEqual(result, this.evaluator.Evaluate(hand)); }
public HandResult CheckHands(int[] cards) { HandResult result = null; Array.Sort(cards); for (int i = hands.Length - 1; i >= 0; i--) { result = hands[i](cards); if (result.handType != HandResult.HandType.NONE) { break; } } return(result); }
private void ResolveRoundResult(Hand hand) { HandResult result = HandResult.Unknown; if (hand.IsBust) { result = HandResult.Lose; } else if (_dealer.Hand.IsBust) { result = HandResult.Win; } if (!hand.IsBust && !_dealer.Hand.IsBust) { if (_dealer.Hand.Value > hand.Value) { result = HandResult.Lose; } else if (_dealer.Hand.Value < hand.Value) { result = HandResult.Win; } else { if (_dealer.HasBlackjack && _player.IsSplit) { result = HandResult.Lose; } else { result = HandResult.Tie; } } } OnRoundHandResult(new OnRoundHandResultArgs() { Result = result, Player = _player, Hand = hand }); }
private void UpdatePlayerChipCount(HandResult handResult) { if (handResult == HandResult.Blackjack) { _currentPlayer.TotalChips += (int)Math.Round(_currentPlayer.CurrentBet * 1.5); } else if (handResult == HandResult.PlayerBust || handResult == HandResult.Loss) { _currentPlayer.TotalChips -= _currentPlayer.CurrentBet; } else if (handResult == HandResult.Win || handResult == HandResult.DealerBust) { _currentPlayer.TotalChips += _currentPlayer.CurrentBet; } if (_currentPlayer.TotalChips == 0) { GivePlayerNewChips(); } }
public void ProcessHandResult(HandResult handResult, double betAmount) { switch (handResult) { case HandResult.WIN: this.bank.add(betAmount); break; case HandResult.LOSE: this.bank.subtract(betAmount); break; case HandResult.DRAW: //do nothing on DRAW. Player gets money back so no addition or subtraction needed break; case HandResult.BLACKJACK: //if player gets Blackjack they get 3:2 payout this.bank.add(betAmount * 1.5); break; } WriteBankToJsonFile(); }
public HandResult CheckStraightFlush(int[] cards) { HandResult result = new HandResult(); int[,] hands = { { 0, 1, 2, 3, 4 } ,{ 1, 2, 3, 4, 5 } ,{ 2, 3, 4, 5, 6 } ,{ 3, 4, 5, 6, 7 } ,{ 4, 5, 6, 7, 8 } ,{ 5, 6, 7, 8, 9 } ,{ 6, 7, 8, 9, 10 } ,{ 7, 8, 9, 10, 11 } ,{ 8, 9, 10, 11, 12 } ,{ 13, 14, 15, 16, 17 } ,{ 14, 15, 16, 17, 18 } ,{ 15, 16, 17, 18, 19 } ,{ 16, 17, 18, 19, 20 } ,{ 17, 18, 19, 20, 21 } ,{ 18, 19, 20, 21, 22 } ,{ 19, 20, 21, 22, 23 } ,{ 20, 21, 22, 23, 24 } ,{ 21, 22, 23, 24, 25 } ,{ 26, 27, 28, 29, 30 } ,{ 27, 28, 29, 30, 31 } ,{ 28, 29, 30, 31, 32 } ,{ 29, 30, 31, 32, 33 } ,{ 30, 31, 32, 33, 34 } ,{ 31, 32, 33, 34, 35 } ,{ 32, 33, 34, 35, 36 } ,{ 33, 34, 35, 36, 37 } ,{ 34, 35, 36, 37, 38 } ,{ 39, 40, 41, 42, 43 } ,{ 40, 41, 42, 43, 44 } ,{ 41, 42, 43, 44, 45 } ,{ 42, 43, 44, 45, 46 } ,{ 43, 44, 45, 46, 47 } ,{ 44, 45, 46, 47, 48 } ,{ 45, 46, 47, 48, 49 } ,{ 46, 47, 48, 49, 50 } ,{ 47, 48, 49, 50, 51 } }; int handsCount = 36; int cardsCount = 5; int matchCount = 0; int compare1 = -1; int compare2 = -1; for (int i = 0; i < handsCount; i++) { matchCount = 0; result.InitializeMadeCard(); for (int k = 0; k < cardsCount; k++) { for (int j = 0; j < cards.Length; j++) { compare1 = hands[i, k]; compare2 = cards[j]; if (compare2 == -1) { continue; } if (compare1 == compare2) { matchCount++; result.AddMadeCard(compare1); } } } if (matchCount == cardsCount) { result.handType = HandResult.HandType.STRAIGHT_FLUSH; result.cardType = (HandResult.CardType)((i - (i % 9)) / 9 + 1); result.hands[0] = 4 + (i % 9); break; } matchCount = 0; } return(result); }
public void Run() { Console.OutputEncoding = Encoding.UTF8; Console.BackgroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); _activeDeck = ShuffleDeck(_activeDeck); while (true) { MenuChoice menuChoice = ShowMainMenu(); if (menuChoice == MenuChoice.PlayGame) { PlayerSelectionScreen(); Console.Clear(); while (true) { LetPlayerPlaceBet(); DealHand(_activeDeck, _currentPlayer, _dealer); PlayerPlayHand(); if (_currentPlayer.HandValue <= 21) { PlayDealerHand(); } HandResult handResult = CheckHandResult(); DisplayHandResult(handResult); UpdatePlayerChipCount(handResult); _dataAccess.UpdatePlayer(_currentPlayer); ClearHand(); if (_activeDeck.PlayingCards.Count < 10) { ReshuffleDeck(); } if (!PlayAnotherHand()) { break; } } } else if (menuChoice == MenuChoice.ShowHighscore) { ShowHighscore(); } else if (menuChoice == MenuChoice.ExitGame) { ShowExitScreen(); break; } } }
public void UpdateForWin() { previousResult = HandResult.Win; }
public void UpdateForLoss() { previousResult = HandResult.Lose; }
public async Task basicRequest(HttpRequestInfo info) { //Jump out for request cancel info.Token.ThrowIfCancellationRequested(); //Monitor //Basic data WebPageModel page = info.Page; ResponseData <string> received = null; var monitor = info.RequestMonitor; bool requestResend; int wrongDataRetryTimes = WrongReceiveRetryTimes; int webErrorRetryTimes = WebErrorRetryTimes; do { //Init requestResend = false; //Requesting monitor.IsRequesting = true; try { received = await info.RequestTask(info.HttpRequestConfig, page.Url, info.Passing.Data, info.Token); } catch (AggregateException e) { throw e; } catch (WebException e) { if (webErrorRetryTimes > 0) { if (e.Response == null) { throw; } HttpWebResponse response = null; if ((response = (e.Response as HttpWebResponse)) != null) { switch (response.StatusCode) { case HttpStatusCode.NotFound: case HttpStatusCode.InternalServerError: case HttpStatusCode.Forbidden: throw; default: break; } response.Dispose(); } --wrongRetryTimes; requestResend = true; if (monitor.OnRetryRequest(e.Message) == RequestReceipt.Cancel) { break; } } } finally { monitor.IsRequesting = false; } //Jump out for request cancel info.Token.ThrowIfCancellationRequested(); //Hand result if (!requestResend) { if (string.IsNullOrEmpty(received.Data)) { if (wrongDataRetryTimes > 0) { if (monitor.OnRetryRequest(received.ErrorMessage) == RequestReceipt.Cancel) { break; } --wrongDataRetryTimes; requestResend = true; } } else { HandResult handResult = await info.HandDataTask(page, info.Passing, received); if (handResult == HandResult.RequestResend) { requestResend = true; } } } } while (requestResend); }
public void UpdateForPush() { previousResult = HandResult.Push; }