Example #1
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            long       userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HoldemGame game   = casino.GetGame(userid);

            if (game == null)
            {
                SendMessage(channel, command.User, "You have no active holdem game. Use !holdem to start a new game.");
                return;
            }

            casino.RemoveGame(userid);

            RPGMessageBuilder message          = messagemodule.Create().User(userid).Text(" folds the hand. ");
            HandEvaluation    dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand);
            HandEvaluation    playerevaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            if (dealerevaluation < playerevaluation || dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four))
            {
                message.ShopKeeper().Text(" laughs and shows ");
                foreach (Card card in game.DealerHand)
                {
                    message.Image(cardimages.GetCardUrl(card), $"{card} ");
                }
                message.Text("while grabbing ").Gold(game.Pot);
            }
            else
            {
                message.ShopKeeper().Text(" gladly rakes in ").Gold(game.Pot);
            }
            message.Send();
        }
Example #2
0
        public void TestPairKickerEvaluation()
        {
            HandEvaluation first  = HandEvaluator.Evaluate(Board.Parse("4d4s3h5c2s8sJc"));
            HandEvaluation second = HandEvaluator.Evaluate(Board.Parse("4d4s3h5c2sKc6s"));

            Assert.That(second > first);
        }
Example #3
0
        public void TestTripsKickerEvaluation()
        {
            HandEvaluation first  = HandEvaluator.Evaluate(Board.Parse("Qd7d9dQcQs8sJc"));
            HandEvaluation second = HandEvaluator.Evaluate(Board.Parse("Qd7d9dQcQsKc6s"));

            Assert.That(second > first);
        }
 int GetMultiplicator(HandEvaluation evaluation, bool ismaxbet) {
     switch(evaluation.Rank) {
         case HandRank.RoyalFlush:
             if(ismaxbet)
                 return 4001;
             return 251;
         case HandRank.StraightFlush:
             return 51;
         case HandRank.FourOfAKind:
             return 26;
         case HandRank.FullHouse:
             return 10;
         case HandRank.Flush:
             return 7;
         case HandRank.Straight:
             return 5;
         case HandRank.ThreeOfAKind:
             return 4;
         case HandRank.TwoPair:
             return 3;
         case HandRank.Pair:
             if(evaluation.HighCard >= CardRank.Jack)
                 return 2;
             return 0;
         default:
             return 0;
     }
 }
        public void Evaluate_Straight_Returns4()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Five, CardSuit.Spades),
                new Card(CardRank.Two, CardSuit.Clubs),
                new Card(CardRank.Ace, CardSuit.Diamonds),
                new Card(CardRank.Four, CardSuit.Diamonds),
                new Card(CardRank.Three, CardSuit.Hearts)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(4, result);
        }
        public void Evaluate_Flush_Returns6()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Two, CardSuit.Diamonds),
                new Card(CardRank.Five, CardSuit.Diamonds),
                new Card(CardRank.Ace, CardSuit.Diamonds),
                new Card(CardRank.Jack, CardSuit.Diamonds),
                new Card(CardRank.Nine, CardSuit.Diamonds)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(6, result);
        }
        public void Evaluate_FullHouse_Returns9()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Seven, CardSuit.Diamonds),
                new Card(CardRank.Seven, CardSuit.Spades),
                new Card(CardRank.Seven, CardSuit.Hearts),
                new Card(CardRank.Ace, CardSuit.Clubs),
                new Card(CardRank.Ace, CardSuit.Diamonds)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(9, result);
        }
        public void Evaluate_StraightFlush_Returns50()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Six, CardSuit.Diamonds),
                new Card(CardRank.Eight, CardSuit.Diamonds),
                new Card(CardRank.Ten, CardSuit.Diamonds),
                new Card(CardRank.Seven, CardSuit.Diamonds),
                new Card(CardRank.Nine, CardSuit.Diamonds)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(50, result);
        }
        public void Evaluate_Nothing_Returns0()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Three, CardSuit.Spades),
                new Card(CardRank.Seven, CardSuit.Clubs),
                new Card(CardRank.Two, CardSuit.Spades),
                new Card(CardRank.Five, CardSuit.Diamonds),
                new Card(CardRank.Ten, CardSuit.Hearts)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(0, result);
        }
        public void Evaluate_JacksOrBetter_Returns1()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Jack, CardSuit.Spades),
                new Card(CardRank.Seven, CardSuit.Clubs),
                new Card(CardRank.Two, CardSuit.Spades),
                new Card(CardRank.Five, CardSuit.Diamonds),
                new Card(CardRank.Ten, CardSuit.Hearts)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(1, result);
        }
        public void Evaluate_TwoPair_Returns2()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Seven, CardSuit.Spades),
                new Card(CardRank.Seven, CardSuit.Clubs),
                new Card(CardRank.King, CardSuit.Spades),
                new Card(CardRank.King, CardSuit.Diamonds),
                new Card(CardRank.Three, CardSuit.Hearts)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(2, result);
        }
        public void Evaluate_ThreeOfAKind_Returns3()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Seven, CardSuit.Spades),
                new Card(CardRank.Seven, CardSuit.Clubs),
                new Card(CardRank.Seven, CardSuit.Diamonds),
                new Card(CardRank.Four, CardSuit.Diamonds),
                new Card(CardRank.Three, CardSuit.Hearts)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(3, result);
        }
        public void Evaluate_RoyalFlush_Returns800()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.King, CardSuit.Clubs),
                new Card(CardRank.Ten, CardSuit.Clubs),
                new Card(CardRank.Jack, CardSuit.Clubs),
                new Card(CardRank.Queen, CardSuit.Clubs),
                new Card(CardRank.Ace, CardSuit.Clubs)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(800, result);
        }
        public void Evaluate_FourOfAKind_Returns25()
        {
            var hand = new List <Card>
            {
                new Card(CardRank.Jack, CardSuit.Diamonds),
                new Card(CardRank.Jack, CardSuit.Spades),
                new Card(CardRank.Jack, CardSuit.Hearts),
                new Card(CardRank.Jack, CardSuit.Clubs),
                new Card(CardRank.Nine, CardSuit.Diamonds)
            };

            var result = HandEvaluation.Evaluate(hand);

            Assert.AreEqual(25, result);
        }
Example #15
0
        private void GetAndAwardWinners(int tableId)
        {
            var communityCards   = Games.First(e => e.TableId == tableId).TableCards;
            var evaluatedPlayers = new Hashtable();

            foreach (var player in Games.First(e => e.TableId == tableId).Players.Where(e => e.ActionState == PlayerActionState.Playing))
            {
                player.HandStrength = HandEvaluation.Evaluate(communityCards.Concat(player.HandCards).ToList());
                evaluatedPlayers.Add(player.Name, player.HandStrength);
            }

            foreach (var pot in Games.First(e => e.TableId == tableId).Winnings)
            {
                var    highestHand = HandStrength.Nothing;
                string winner      = null;
                foreach (var potPlayer in pot.Players.Where(potPlayer => highestHand > (HandStrength)evaluatedPlayers[potPlayer]))
                {
                    highestHand = (HandStrength)evaluatedPlayers[potPlayer];
                    winner      = potPlayer;
                }
                pot.Winner = winner;
                Users.First(e => e.Name == pot.Winner).Balance += pot.PotAmount;
            }
        }
        public static int BetRequest(JObject gameState)
        {
            int bet = -1;

            try
            {
                var gs        = new GameState(gameState);
                var ourPlayer = gs.Players.First(p => p.Name == "Cranberry Icefrog");

                var hand = new HandEvaluation
                {
                    CommunityCards = gs.CommunityCards,
                    HoleCards      = ourPlayer.HoleCards
                };

                bool isPreFlop = hand.AllCards.Count == 2;
                bool isFlop    = hand.AllCards.Count > 2;

                if (isPreFlop)
                {
                    bet = gs.CurrentBuyIn;

                    if (hand.IsHighCard)
                    {
                        bet += gs.BigBlind;
                    }
                    else if (hand.IsOnePair)
                    {
                        bet += gs.BigBlind + gs.SmallBlind;
                    }
                    else if (hand.IsHighCard && hand.IsOnePair)
                    {
                        bet += gs.BigBlind * 2;
                    }
                }
                if (isFlop)
                {
                    bet = gs.CurrentBuyIn;

                    if (hand.IsFourOfAKind)
                    {
                        bet = ourPlayer.Stack;
                    }
                    if (hand.IsFlush)
                    {
                        bet = ourPlayer.Stack;
                    }
                    else if (hand.IsFullHouse)
                    {
                        bet = 10000;
                    }
                    else if (hand.IsThreeOfAKind)
                    {
                        bet *= 3;
                    }
                    else if (hand.IsOnePair)
                    {
                        bet *= 2;
                    }
                    else if (hand.IsHighCard)
                    {
                        // do nothing
                    }
                    else
                    {
                        bet = 0;
                    }
                }

                Console.WriteLine("CurrentBuyIn: " + gs.CurrentBuyIn);
                Console.WriteLine("BigBlind: " + gs.BigBlind);
                Console.WriteLine("bet: " + bet);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            if (bet < 0)
            {
                bet = 10000;
            }
            return(bet);
        }
Example #17
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            long       userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HoldemGame game   = casino.GetGame(userid);

            if (game != null)
            {
                SendMessage(channel, command.User, "You are already active in a holdem game. Use !fold to fold your hand or !call to stay active in the game.");
                return;
            }

            int bet;

            if (command.Arguments.Length == 0)
            {
                bet = 1;
            }
            else
            {
                int.TryParse(command.Arguments[0], out bet);
            }

            if (bet <= 0)
            {
                SendMessage(channel, command.User, $"{command.Arguments[0]} is no valid bet");
                return;
            }

            int gold = playermodule.GetPlayerGold(userid);

            if (bet > 1 && bet > gold)
            {
                SendMessage(channel, command.User, "You can't bet more than you have.");
                return;
            }

            int maxbet = playermodule.GetLevel(userid) * 10;

            if (bet > maxbet)
            {
                SendMessage(channel, command.User, $"On your level you're only allowed to bet up to {maxbet} gold.");
                return;
            }

            // allow the player to play for one gold even if he has no gold
            if (gold > 0)
            {
                playermodule.UpdateGold(userid, -bet);
            }

            game = casino.CreateGame(userid, bet);

            game.Deck.Shuffle();

            game.PlayerHand += game.Deck.Pop();
            game.DealerHand += game.Deck.Pop();
            game.PlayerHand += game.Deck.Pop();
            game.DealerHand += game.Deck.Pop();

            game.Muck.Push(game.Deck.Pop());
            for (int i = 0; i < 3; ++i)
            {
                game.Board += game.Deck.Pop();
            }

            RPGMessageBuilder message = messagemodule.Create();

            message.Text("You have ");
            foreach (Card card in game.PlayerHand)
            {
                message.Image(imagemodule.GetCardUrl(card), $"{card} ");
            }
            message.Text(". The board shows ");
            foreach (Card card in game.Board)
            {
                message.Image(imagemodule.GetCardUrl(card), $"{card} ");
            }

            HandEvaluation evaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            message.Text($" ({evaluation})").Send();
        }
Example #18
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            long       userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HoldemGame game   = casino.GetGame(userid);

            if (game == null)
            {
                SendMessage(channel, command.User, "You have no active holdem game. Use !holdem to start a new game.");
                return;
            }

            int bet = Math.Min(playermodule.GetPlayerGold(userid), game.Bet);

            if (bet > 0)
            {
                playermodule.UpdateGold(userid, -bet);
                game.Pot += bet;
            }

            game.Muck.Push(game.Deck.Pop());
            game.Board += game.Deck.Pop();

            RPGMessageBuilder message = messagemodule.Create();

            if (game.Board.Count == 5)
            {
                // showdown
                message.Text("Showdown! ");
            }

            message.Text("The board shows ");
            foreach (Card card in game.Board)
            {
                message.Image(cardimages.GetCardUrl(card), $"{card} ");
            }
            message.Text(". You have ");
            foreach (Card card in game.PlayerHand)
            {
                message.Image(cardimages.GetCardUrl(card), $"{card} ");
            }

            HandEvaluation evaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            message.Text($" ({evaluation})");

            if (game.Board.Count == 5)
            {
                message.Text(". ").ShopKeeper().Text(" shows ");
                foreach (Card card in game.DealerHand)
                {
                    message.Image(cardimages.GetCardUrl(card), $"{card} ");
                }
                HandEvaluation dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand);
                message.Text($" ({dealerevaluation}). ");

                int multiplier = 0;

                if (dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four))
                {
                    message.ShopKeeper().Text(" isn't qualified for a showdown.");
                    multiplier = GetMultiplier(evaluation.Rank);
                }
                else if (dealerevaluation > evaluation)
                {
                    message.ShopKeeper().Text(" wins the hand and ").Gold(game.Pot).Text(" laughing at your face.");
                }
                else if (dealerevaluation == evaluation)
                {
                    message.ShopKeeper().Text(" Has the same hand as you.");
                    multiplier = 1;
                }
                else
                {
                    message.Text(" You win the hand.");
                    multiplier = GetMultiplier(evaluation.Rank);
                }

                if (multiplier > 0)
                {
                    message.Text(" Payout is ").Gold(game.Pot * multiplier);
                    playermodule.UpdateGold(userid, game.Pot * multiplier);
                }

                casino.RemoveGame(userid);
            }

            message.Send();
        }
Example #19
0
        public void TestEvaluatedRank([ValueSource("Hands")] Tuple <Board, HandRank> data)
        {
            HandEvaluation evaluation = HandEvaluator.Evaluate(data.Item1);

            Assert.AreEqual(data.Item2, evaluation.Rank);
        }