public static bool Check(NumberLimitRule rule, int count) { if (rule == null) { throw new ArgumentNullException(nameof(rule)); } if (count <= 0 || rule.Count < 0) { throw new ArgumentException("参数错误"); } if (rule.Type == NumberLimitType.Equal) { return(rule.Count == count); } else if (rule.Type == NumberLimitType.GreaterThan) { return(count > rule.Count); } else { return(count < rule.Count); } }
public SameNumberCards(IEnumerable <Poker> pokers) { if (pokers == null || !pokers.Any()) { throw new ArgumentNullException(nameof(pokers)); } Pokers = pokers.ToImmutableList(); NumberLimit = new NumberLimitRule { Count = LimitNumber, Type = NumberLimitType.Equal }; }
public virtual bool Check() { if (!NumberLimitRule.Check(NumberLimit, Pokers.Count)) { return(false); } if (!Pokers.All(x => x.Display == Pokers.First().Display)) { return(false); } return(true); }
public bool Check() { if (!NumberLimitRule.Check(NumberLimit, Pokers.Count)) { return(false); } var pokerKeys = Pokers.Select(x => x.Display).Distinct(); if (pokerKeys.Count() != 2) { return(false); } return(Pokers.Count(x => x.Display == pokerKeys.First()) == 3 || Pokers.Count(x => x.Display == pokerKeys.Last()) == 3); }
public bool Check() { if (!NumberLimitRule.Check(NumberLimit, Pokers.Count)) { return(false); } //不能包含大小王和2 //不能有相同 for (var i = 1; i < Pokers.Count; i++) { if (Pokers[i].Weight == Pokers.First().Weight) { return(false); } } //连续的,这里是最大的减去最小的等于一个值 return(Pokers.Max(x => x.Weight) - Pokers.Min(x => x.Weight) == Pokers.Count - 1); }
public bool Check() { if (!NumberLimitRule.Check(NumberLimit, Pokers.Count)) { return(false); } //判断数目是否是偶数 if (Pokers.Count % 2 != 0) { return(false); } //不能包含大小王和2 if (!Pokers.Select(x => x.Display).Distinct().All(x => Pokers.Count(y => y.Display == x) == 2)) { return(false); } //判断牌是否是连续的,这里是最大的减去最小的等于一个值 return(Pokers.Max(x => x.Weight) - Pokers.Min(x => x.Weight) == Pokers.Count - 1); }