From 2fcdb8e58d2ac0a31a710ed50d325c963016aae9 Mon Sep 17 00:00:00 2001 From: todorm85 Date: Sat, 28 Nov 2015 01:11:47 +0200 Subject: [PATCH 1/2] Add showdown Add showdown functionality to TwoPlayersHandLogic. The list of player`s showdown cards is passed as property ShowdownCards of the EndHandContext object to IPlayer.EndHand() method. --- .../GameMechanics/TwoPlayersHandLogic.cs | 14 ++++++++++++-- Source/TexasHoldem.Logic/Players/EndHandContext.cs | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs b/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs index 7746555..cf1744a 100644 --- a/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs +++ b/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs @@ -21,6 +21,8 @@ internal class TwoPlayersHandLogic private readonly TwoPlayersBettingLogic bettingLogic; + private Dictionary> showdownCards; + public TwoPlayersHandLogic(IList players, int handNumber, int smallBlind) { this.handNumber = handNumber; @@ -69,10 +71,18 @@ public void Play() this.DetermineWinnerAndAddPot(this.bettingLogic.Pot); + // showdown + foreach (var player in this.players) + { + if (player.PlayerMoney.InHand) + { + this.showdownCards.Add(player.Name, player.Cards); + } + } + foreach (var player in this.players) { - // TODO: Showdown? - player.EndHand(new EndHandContext()); + player.EndHand(new EndHandContext(this.showdownCards)); } } diff --git a/Source/TexasHoldem.Logic/Players/EndHandContext.cs b/Source/TexasHoldem.Logic/Players/EndHandContext.cs index e073c8d..19bc66c 100644 --- a/Source/TexasHoldem.Logic/Players/EndHandContext.cs +++ b/Source/TexasHoldem.Logic/Players/EndHandContext.cs @@ -1,6 +1,15 @@ namespace TexasHoldem.Logic.Players { + using System.Collections.Generic; + using TexasHoldem.Logic.Cards; + public class EndHandContext { + public EndHandContext(Dictionary> showdownCards) + { + this.ShowdownCards = showdownCards; + } + + public Dictionary> ShowdownCards { get; private set; } } } \ No newline at end of file From 93a6a4ad8343c2ff8b758924ca20eccc2951db8f Mon Sep 17 00:00:00 2001 From: todorm85 Date: Sat, 28 Nov 2015 01:53:58 +0200 Subject: [PATCH 2/2] Fix showdown functionality Only if both players have not folded there`s a showdown, otherwise none of the players hands are shown. --- .../GameMechanics/TwoPlayersHandLogic.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs b/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs index cf1744a..a330a9a 100644 --- a/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs +++ b/Source/TexasHoldem.Logic/GameMechanics/TwoPlayersHandLogic.cs @@ -71,15 +71,6 @@ public void Play() this.DetermineWinnerAndAddPot(this.bettingLogic.Pot); - // showdown - foreach (var player in this.players) - { - if (player.PlayerMoney.InHand) - { - this.showdownCards.Add(player.Name, player.Cards); - } - } - foreach (var player in this.players) { player.EndHand(new EndHandContext(this.showdownCards)); @@ -95,6 +86,15 @@ private void DetermineWinnerAndAddPot(int pot) } else { + // showdown + foreach (var player in this.players) + { + if (player.PlayerMoney.InHand) + { + this.showdownCards.Add(player.Name, player.Cards); + } + } + var betterHand = Helpers.CompareCards( this.players[0].Cards.Concat(this.communityCards), this.players[1].Cards.Concat(this.communityCards));