public DeckRegularDict <MonasteryCardInfo> RunList(DeckRegularDict <MonasteryCardInfo> thisCol, EnumRunType runType) { var tempCol = PopulateTempCol(thisCol, out DeckRegularDict <MonasteryCardInfo> aceList); DeckRegularDict <MonasteryCardInfo> output = new DeckRegularDict <MonasteryCardInfo>(); var thisCard = tempCol.First(); int minNumber = (int)thisCard.Value; int maxNumber = minNumber + thisCol.Count - 1; if (maxNumber > 13) { thisCard = tempCol.Last(); maxNumber = (int)thisCard.Value; minNumber = maxNumber - thisCol.Count + 1; } EnumSuitList suitNeeded; if (runType == EnumRunType.Color) { if (thisCard.Color == EnumColorList.Red) { suitNeeded = EnumSuitList.Diamonds; } else { suitNeeded = EnumSuitList.Clubs; } } else if (runType == EnumRunType.Suit) { suitNeeded = thisCard.Suit; } else { suitNeeded = EnumSuitList.Diamonds; } int currentNum = minNumber; thisCol.Count.Times(x => { if (tempCol.Any(items => (int)items.Value == currentNum) == false) { thisCard = EntireList.First(items => items.Suit == suitNeeded && (int)items.Value == currentNum); var nextCard = new MonasteryCardInfo(); nextCard.Populate(thisCard.Deck); nextCard.Temp = thisCard.Deck; //this too i think. nextCard.Deck = aceList.First().Deck; //this is what i had to do now. aceList.RemoveFirstItem(); //has to use the deck of the ace to stop the id problems. output.Add(nextCard); } else { thisCard = tempCol.Single(items => (int)items.Value == currentNum); tempCol.RemoveSpecificItem(thisCard); output.Add(thisCard); } currentNum++; }); return(output); }
public bool IsRun(DeckRegularDict <MonasteryCardInfo> thisCol, EnumRunType needType, int required) { if (thisCol.Count < required) { return(false); } if (needType == EnumRunType.Suit) { if (thisCol.GroupBy(items => items.Suit).Count() > 1) { return(false); } } if (needType == EnumRunType.Color) { if (thisCol.GroupBy(items => items.Color).Count() > 1) { return(false); } } var tempCol = PopulateTempCol(thisCol, out DeckRegularDict <MonasteryCardInfo> aceList); if (tempCol.Count == 0) { return(true); //if all aces, then fine at this point. } int howMany = tempCol.GroupBy(items => items.Value).Count(); if (howMany != tempCol.Count) { return(false); } int currentNumber = 0; int diffs; int previousNumber = 0; int x = 0; foreach (var thisCard in tempCol) { x++; currentNumber = (int)thisCard.Value; if (x == 1) { previousNumber = (int)thisCard.Value; } else { diffs = currentNumber - previousNumber - 1; if (diffs > 0) { if (aceList.Count < diffs) { return(false); } diffs.Times(y => aceList.RemoveFirstItem()); } } previousNumber = (int)thisCard.Value; } return(true); }