Use straight and flush validators for straightflush validation
This commit is contained in:
@@ -4,25 +4,20 @@ namespace ChainOfResponssibility.Poker.Validators.HandValidators
|
|||||||
{
|
{
|
||||||
public class StraightFlushValidation : HandValidation
|
public class StraightFlushValidation : HandValidation
|
||||||
{
|
{
|
||||||
|
private StraightValidation straight;
|
||||||
|
private FlushValidation flush;
|
||||||
|
|
||||||
|
public StraightFlushValidation()
|
||||||
|
{
|
||||||
|
straight = new StraightValidation();
|
||||||
|
flush = new FlushValidation();
|
||||||
|
}
|
||||||
|
|
||||||
protected override string IsValid(Card[] hand)
|
protected override string IsValid(Card[] hand)
|
||||||
{
|
{
|
||||||
var gr = hand.GroupBy(x => x.Suite);
|
if ((!string.IsNullOrEmpty(flush.Validate(hand))) && (!string.IsNullOrEmpty(straight.Validate(hand))))
|
||||||
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()));
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user