public void StraightFlush_vs_StraightFlush() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Spades, Rank.Two), new Card(Suit.Spades, Rank.Three), new Card(Suit.Spades, Rank.Four), new Card(Suit.Spades, Rank.Five), new Card(Suit.Spades, Rank.Six), new Card(Suit.Diamonds, Rank.Jack), new Card(Suit.Hearts, Rank.Queen) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Spades, Rank.Seven), new Card(Suit.Spades, Rank.Eight), new Card(Suit.Spades, Rank.Four), new Card(Suit.Spades, Rank.Five), new Card(Suit.Spades, Rank.Six), new Card(Suit.Diamonds, Rank.Jack), new Card(Suit.Hearts, Rank.Queen) }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me2", winner.UserId); Assert.AreEqual((int)PokerScores.StraightFlush, winner.PokerHand.Score); }
public void Quads_vs_Quads_Kicker() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Spades, Rank.Jack), new Card(Suit.Hearts, Rank.Ten), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Clubs, Rank.Queen), new Card(Suit.Diamonds, Rank.Queen), new Card(Suit.Clubs, Rank.Two) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.King), new Card(Suit.Diamonds, Rank.Nine), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Clubs, Rank.Queen), new Card(Suit.Diamonds, Rank.Queen), new Card(Suit.Clubs, Rank.Two) }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me2", winner.UserId); Assert.AreEqual((int)PokerScores.Quads, winner.PokerHand.Score); }
public void Quads_vs_Quads_SplitPot() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Spades, Rank.King), new Card(Suit.Hearts, Rank.Ten), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Clubs, Rank.Queen), new Card(Suit.Diamonds, Rank.Queen), new Card(Suit.Clubs, Rank.Two) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.King), new Card(Suit.Diamonds, Rank.Nine), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Clubs, Rank.Queen), new Card(Suit.Diamonds, Rank.Queen), new Card(Suit.Clubs, Rank.Two) }); var winners = detector.GetWinners().ToList(); Assert.AreEqual(2, winners.Count); Assert.AreEqual((int)PokerScores.Quads, winners[0].PokerHand.Score); Assert.AreEqual((int)PokerScores.Quads, winners[1].PokerHand.Score); }
public void TwoPairs_vs_Pair() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Clubs, Rank.King), new Card(Suit.Diamonds, Rank.Ten), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Clubs, Rank.Queen), }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.Three), new Card(Suit.Diamonds, Rank.Seven), new Card(Suit.Hearts, Rank.Ten), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Clubs, Rank.Two), }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me1", winner.UserId); Assert.AreEqual((int)PokerScores.TwoPairs, winner.PokerHand.Score); }
public void Flush_vs_Flush() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Hearts, Rank.Five), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Hearts, Rank.Eight), new Card(Suit.Hearts, Rank.Three), new Card(Suit.Hearts, Rank.Jack), new Card(Suit.Hearts, Rank.Ten), new Card(Suit.Hearts, Rank.Two) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Hearts, Rank.Nine), new Card(Suit.Hearts, Rank.King), new Card(Suit.Hearts, Rank.Eight), new Card(Suit.Hearts, Rank.Three), new Card(Suit.Hearts, Rank.Jack), new Card(Suit.Hearts, Rank.Ten), new Card(Suit.Hearts, Rank.Two) }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me2", winner.UserId); Assert.AreEqual((int)PokerScores.Flush, winner.PokerHand.Score); }
public void FullHouse_vs_Flush() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Clubs, Rank.Ace), new Card(Suit.Diamonds, Rank.Ace), new Card(Suit.Spades, Rank.Ace), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Spades, Rank.Ten), new Card(Suit.Spades, Rank.King) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.Ace), new Card(Suit.Clubs, Rank.Seven), new Card(Suit.Clubs, Rank.King), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Clubs, Rank.Seven) }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me1", winner.UserId); Assert.AreEqual((int)PokerScores.FullHouse, winner.PokerHand.Score); }
public void Set_vs_Set_when_hand_has_various_sets() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Spades, Rank.Three), new Card(Suit.Hearts, Rank.Three), new Card(Suit.Spades, Rank.Three), new Card(Suit.Spades, Rank.Two), new Card(Suit.Spades, Rank.Five), new Card(Suit.Diamonds, Rank.Five), new Card(Suit.Clubs, Rank.Five) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.Two), new Card(Suit.Diamonds, Rank.Two), new Card(Suit.Spades, Rank.Three), new Card(Suit.Spades, Rank.Two), new Card(Suit.Spades, Rank.Five), new Card(Suit.Diamonds, Rank.Five), new Card(Suit.Clubs, Rank.Five) }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me1", winner.UserId); Assert.AreEqual((int)PokerScores.Set, winner.PokerHand.Score); }
public override void Update(GameTime gameTime) { if (!GameState.IsPaused) { if (GameState.IsEnd) { ShowLabels.ShowEndGame(); FirstSprite.HandleSpriteMovement(gameTime); SecondSprite.HandleSpriteMovement(gameTime); if (!GameState.IsEnd) { FirstSprite.Stop(); SecondSprite.Stop(); } } else { ShowLabels.ShowWinner(); ShowLabels.ShowRound(); firstState = FirstSprite.HandleSpriteMovement(gameTime); secondState = SecondSprite.HandleSpriteMovement(gameTime); if (firstState == PlayerState.Move || secondState == PlayerState.Move) { CollideDetector.RepairMoveCollision(FirstSprite, SecondSprite, width); } CollideDetector.HitCollision(FirstSprite, SecondSprite, gameTime); FirstHealthBar.Update(FirstSprite.Information.Health); SecondHealthBar.Update(SecondSprite.Information.Health); WinnerDetector.DetectWinner(gameTime, FirstSprite, SecondSprite); } base.Update(gameTime); } }
public void test() { var first = new OnePair(); first.SetCards(new List <Card> { new Card(Suit.Clubs, Rank.Eight), new Card(Suit.Diamonds, Rank.Eight), new Card(Suit.Hearts, Rank.Two), new Card(Suit.Spades, Rank.Ace), new Card(Suit.Spades, Rank.Three), new Card(Suit.Diamonds, Rank.Six), new Card(Suit.Clubs, Rank.Seven), }); Assert.IsTrue(first.IsPresent()); var second = new OnePair(); second.SetCards(new List <Card> { new Card(Suit.Clubs, Rank.Eight), new Card(Suit.Diamonds, Rank.Eight), new Card(Suit.Hearts, Rank.Two), new Card(Suit.Spades, Rank.Ace), new Card(Suit.Spades, Rank.Three), new Card(Suit.Diamonds, Rank.Six), new Card(Suit.Clubs, Rank.Seven), }); Assert.IsTrue(second.IsPresent()); var third = new OnePair(); third.SetCards(new List <Card> { new Card(Suit.Clubs, Rank.Eight), new Card(Suit.Diamonds, Rank.Eight), new Card(Suit.Hearts, Rank.Two), new Card(Suit.Spades, Rank.Four), new Card(Suit.Spades, Rank.Three), new Card(Suit.Diamonds, Rank.Six), new Card(Suit.Clubs, Rank.Seven), }); Assert.IsTrue(third.IsPresent()); var hands = new List <IPokerHand> { first, second, third }; Assert.AreEqual(0, first.CompareTo(second)); var sortedList = new WinnerDetector().GetOrdered(hands); Assert.AreEqual(2, sortedList[0].Count()); Assert.AreEqual(1, sortedList[1].Count()); Assert.AreSame(third, sortedList[1].First()); }
public void test() { var detector = new WinnerDetector(); detector.AddPlayer("me1", Cards.TwoPairsJacksFives()); detector.AddPlayer("me2", Cards.TwoPairsJacksSixes()); var winners = detector.GetWinners(100).ToList(); Assert.AreEqual(1, winners.Count); Assert.AreEqual("me2", winners[0].UserId); Assert.AreEqual(100, winners[0].Prize); Assert.AreEqual(typeof(TwoPairs), winners[0].PokerHand.GetType()); }
public void two() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Spades, Rank.King), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Spades, Rank.King), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Spades, Rank.Five), new Card(Suit.Diamonds, Rank.Six), new Card(Suit.Clubs, Rank.Two) }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.King), new Card(Suit.Diamonds, Rank.Queen), new Card(Suit.Spades, Rank.King), new Card(Suit.Spades, Rank.Queen), new Card(Suit.Spades, Rank.Five), new Card(Suit.Diamonds, Rank.Six), new Card(Suit.Clubs, Rank.Two) }); var winners = detector.GetWinners(100).ToList(); Assert.AreEqual(2, winners.Count); Assert.AreEqual(winners[0].Prize, 50); Assert.AreEqual(winners[0].PokerHand.GetType(), typeof(TwoPairs)); Assert.AreEqual(winners[1].Prize, 50); Assert.AreEqual(winners[1].PokerHand.GetType(), typeof(TwoPairs)); var ids = winners.Select(x => x.UserId).ToList(); Assert.Contains("me1", ids); Assert.Contains("me2", ids); }
public void HighCard_vs_HighCard() { var detector = new WinnerDetector(); detector.AddPlayer("me1", new List <Card>() { new Card(Suit.Clubs, Rank.King), new Card(Suit.Diamonds, Rank.Seven), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Clubs, Rank.Two), }); detector.AddPlayer("me2", new List <Card>() { new Card(Suit.Clubs, Rank.Three), new Card(Suit.Diamonds, Rank.Seven), new Card(Suit.Hearts, Rank.Queen), new Card(Suit.Clubs, Rank.Ten), new Card(Suit.Clubs, Rank.Two), }); var winner = detector.GetWinners().Single(); Assert.AreEqual("me1", winner.UserId); }
private void NextTurn(int currentPosition) { if (State.IsAllExceptOneAreFold()) { var winner = State.Players.Values.Single(x => !x.Fold); Apply(new GameFinished { Id = State.TableId, GameId = State.GameId, Winners = new List <WinnerInfo> { new WinnerInfo(winner, State.CurrentBidding.GetBank()) }, }); CreateGame(GenerateGameId()); } else { if (CheckBiddingFinished()) { Apply(new BiddingFinished { Id = State.TableId, GameId = State.GameId, Bank = State.CurrentBidding.GetBank() }); if (State.Deck.Count == 5) { var detector = new WinnerDetector(); foreach (var player in State.Players.Values) { var cards = new List <Card>(player.Cards); cards.AddRange(State.Deck); detector.AddPlayer(player.UserId, cards); } var bank = State.CurrentBidding.GetBank(); var winners = detector.GetWinners(bank); Apply(new GameFinished { Id = State.TableId, Winners = winners.Select( winner => new WinnerInfo(winner.UserId, State.JoinedPlayers[winner.UserId].Position, winner.Prize, winner.PokerHand.Score)).ToList(), GameId = State.GameId }); //TODO: check for players with not enough money and dissconnect them CreateGame(GenerateGameId()); return; } else { var cards = new List <Card> { State.Pack.TakeRandom() }; if (!State.Deck.Any()) { cards.Add(State.Pack.TakeRandom()); cards.Add(State.Pack.TakeRandom()); } Apply(new DeckDealed { Id = State.TableId, GameId = State.GameId, Cards = cards }); currentPosition = State.Dealer.Value; } } Apply(new NextPlayerTurned { Id = State.TableId, GameId = State.GameId, Player = State.GetPlayerInfo(State.GetNextNotFoldPlayer(currentPosition)), MinBet = State.GetMinBet(), MaxRaisedValue = State.MaxRaisedValue }); } }
public static IEnumerable <WinnerResult> GetWinners(this WinnerDetector source) { return(source.GetWinners(100)); }