Exemple #1
0
        private bool HasFullHouse(CustomBasicList <ICard> cardList)
        {
            int x;
            CustomBasicList <ICard> tempList = new CustomBasicList <ICard>();

            for (x = 6; x >= 1; x += -1)
            {
                for (var y = 1; y <= 3; y++)
                {
                    var thisColor = y;

                    if (_firstNumber == 0)
                    {
                        CustomBasicList <ICard> newList = new CustomBasicList <ICard>();
                        tempList = cardList.ToCustomBasicList();
                        do
                        {
                            if (newList.Count == 3)
                            {
                                break;
                            }
                            var thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.FirstValue == x && items.SecondValue == 0);
                            if (thisCard != null)
                            {
                                newList.Add(thisCard);
                                tempList.RemoveSpecificItem(thisCard);
                            }
                            else
                            {
                                thisCard = tempList.FirstOrDefault(items => items.Color == EnumColor.Any && items.FirstValue == x);
                                if (thisCard != null)
                                {
                                    newList.Add(thisCard);
                                    tempList.RemoveSpecificItem(thisCard);
                                }
                                else
                                {
                                    thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.FirstValue == x);
                                    if (thisCard != null)
                                    {
                                        newList.Add(thisCard);
                                        tempList.RemoveSpecificItem(thisCard);
                                    }
                                    else
                                    {
                                        thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.SecondValue == x);
                                        if (thisCard != null)
                                        {
                                            newList.Add(thisCard);
                                            tempList.RemoveSpecificItem(thisCard);
                                        }
                                        else
                                        {
                                            thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.IsWild == true);
                                            if (thisCard != null)
                                            {
                                                newList.Add(thisCard);
                                                tempList.RemoveSpecificItem(thisCard);
                                            }
                                            else
                                            {
                                                break; //because no more left.
                                            }
                                        }
                                    }
                                }
                            }
                        } while (true);
                        if (newList.Count == 3)
                        {
                            _firstNumber = x;
                            break;
                        }
                    }
                }
            }
            if (_firstNumber == 0)
            {
                return(false);
            }
            var finList = tempList.ToCustomBasicList();

            for (x = 6; x >= 1; x += -1)
            {
                for (var y = 1; y <= 3; y++)
                {
                    var thisColor = y;
                    if (_secondNumber == 0) //trying to take a risk.
                    {
                        CustomBasicList <ICard> newList = new CustomBasicList <ICard>();
                        tempList = finList.ToCustomBasicList();
                        do
                        {
                            var thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.FirstValue == x && items.SecondValue == 0);
                            if (thisCard != null)
                            {
                                newList.Add(thisCard);
                                tempList.RemoveSpecificItem(thisCard);
                            }
                            else
                            {
                                thisCard = tempList.FirstOrDefault(items => items.Color == EnumColor.Any && items.FirstValue == x);
                                if (thisCard != null)
                                {
                                    newList.Add(thisCard);
                                    tempList.RemoveSpecificItem(thisCard);
                                }
                                else
                                {
                                    thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.FirstValue == x);
                                    if (thisCard != null)
                                    {
                                        newList.Add(thisCard);
                                        tempList.RemoveSpecificItem(thisCard);
                                    }
                                    else
                                    {
                                        thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.SecondValue == x);
                                        if (thisCard != null)
                                        {
                                            newList.Add(thisCard);
                                            tempList.RemoveSpecificItem(thisCard);
                                        }
                                        else
                                        {
                                            thisCard = tempList.FirstOrDefault(items => items.Color == (EnumColor)thisColor && items.IsWild == true);
                                            if (thisCard != null)
                                            {
                                                newList.Add(thisCard);
                                                tempList.RemoveSpecificItem(thisCard);
                                            }
                                            else
                                            {
                                                break; //because no more left.
                                            }
                                        }
                                    }
                                }
                            }
                            if (newList.Count == 3)
                            {
                                break;
                            }
                        } while (true);
                        if (newList.Count == 2)
                        {
                            _secondNumber = x;
                            break;
                        }
                    }
                }
            }
            return(_secondNumber > 0);
        }