From 3eee148d7628cce8d1ee06b8f00f276dbade7bda Mon Sep 17 00:00:00 2001 From: Gardient Date: Sun, 3 Jul 2016 22:27:53 +0300 Subject: [PATCH] Use straight and flush validators for straightflush validation --- .../HandValidators/StraightFlushValidation.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) 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; }