diff --git a/src/ChainOfResponssibility/Poker/Validators/HandValidators/StraightFlushValidation.cs b/src/ChainOfResponssibility/Poker/Validators/HandValidators/StraightFlushValidation.cs index b6e26cb..89ec7f2 100644 --- a/src/ChainOfResponssibility/Poker/Validators/HandValidators/StraightFlushValidation.cs +++ b/src/ChainOfResponssibility/Poker/Validators/HandValidators/StraightFlushValidation.cs @@ -4,24 +4,19 @@ namespace ChainOfResponssibility.Poker.Validators.HandValidators { public class StraightFlushValidation : HandValidation { + private StraightValidation straight; + private FlushValidation flush; + + public StraightFlushValidation() + { + straight = new StraightValidation(); + flush = new FlushValidation(); + } + protected override string IsValid(Card[] hand) { - var gr = hand.GroupBy(x => x.Suite); - var flush = gr.FirstOrDefault(x => x.Count() == 5); - if (flush != null) - { - var Value2Index = hand.Select((i, j) => i.GetIntValue() - j).Distinct(); - if (!Value2Index.Skip(1).Any())// consecutive - return "You have a Straight Flush with " + string.Join(", ", hand.Select(x => x.ToString())); - - //special case for A,2,3,4,5 - if (Value2Index.Count() == 2 - && Value2Index.First() == 2//for 2,3,4,5 - && Value2Index.Last() == 10)//for A - return "You have a Straight Flush with " + string.Join(", ", hand.Select(x => x.ToString())); - - return string.Empty; - } + if ((!string.IsNullOrEmpty(flush.Validate(hand))) && (!string.IsNullOrEmpty(straight.Validate(hand)))) + return "You have a Straight Flush with " + string.Join(", ", hand.Select(x => x.ToString())); return string.Empty; }