private static bool IsStraightBoth(this IDeckDict <A8RoundRummyCardInformation> cardList, IDeckDict <A8RoundRummyCardInformation> straightList, A8RoundRummyMainGameClass mainGame, int reverses) { var firstList = straightList.GroupBy(Items => new { Items.Color, Items.Shape }).ToCustomBasicList(); if (firstList.Count > 2) { return(false); } var nextFirst = firstList.First().GroupBy(Items => Items.Value).ToCustomBasicList(); var finList = nextFirst.Where(Items => Items.Count() > 1).ToCustomBasicList(); DeckRegularDict <A8RoundRummyCardInformation> tempList; EnumCardShape shapeUsed; EnumColor colorUsed; if (firstList.Count == 1) { if (finList.Count == 0) { tempList = cardList.Where(Items => Items.CardType != EnumCardType.Reverse).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (reverses == 1) { return(false); } if (finList.Count > 1) { return(false); } mainGame.LastSuccessful = true; mainGame.LastCard = finList.Single().First(); //hopefully this simple. return(true); } if (reverses == 1) { return(false); } var nextSecond = firstList.Last().GroupBy(Items => Items.Value).ToCustomBasicList(); if (nextSecond.Count > 1 && nextFirst.Count > 1) { return(false); } if (nextSecond.Count > 1) { shapeUsed = firstList.Last().Key.Shape; colorUsed = firstList.Last().Key.Color; finList = nextSecond.Where(Items => Items.Count() > 1).ToCustomBasicList(); } else { shapeUsed = firstList.First().Key.Shape; colorUsed = firstList.First().Key.Color; } if (finList.Count == 0) { tempList = cardList.Where(Items => Items.CardType == EnumCardType.Wild || (Items.Shape == shapeUsed && Items.Color == colorUsed)).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (finList.Count > 1) { return(false); } mainGame.LastSuccessful = true; mainGame.LastCard = finList.Single().First(); return(true); }
private static bool IsStraightColorOnly(this IDeckDict <A8RoundRummyCardInformation> cardList, IDeckDict <A8RoundRummyCardInformation> straightList, A8RoundRummyMainGameClass mainGame, int reverses) { var firstList = straightList.GroupBy(Items => Items.Color).ToCustomBasicList(); if (firstList.Count > 2) { throw new BasicBlankException("Can only have 2 colors at the most"); } var nextFirst = firstList.First().GroupBy(Items => Items.Value).ToCustomBasicList(); var finList = nextFirst.Where(Items => Items.Count() > 1).ToCustomBasicList(); DeckRegularDict <A8RoundRummyCardInformation> tempList; EnumColor colorUsed; if (firstList.Count == 1) { if (finList.Count == 0) { tempList = cardList.Where(Items => Items.CardType != EnumCardType.Reverse).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (reverses == 1) { return(false); } if (finList.Count > 1) { return(false); } mainGame.LastSuccessful = true; mainGame.LastCard = finList.Single().First(); //i think first. return(true); } if (reverses == 1) { return(false); } var nextSecond = firstList.Last().GroupBy(Items => Items.Value).ToCustomBasicList(); if (nextSecond.Count > 1 && nextFirst.Count > 1) { return(false); } if (nextSecond.Count > 1) { colorUsed = firstList.Last().Key; finList = nextSecond.Where(Items => Items.Count() > 1).ToCustomBasicList(); } else { colorUsed = firstList.First().Key; } if (finList.Count == 0) { tempList = cardList.Where(Items => Items.Color == colorUsed || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (finList.Count > 1) { return(false); } mainGame.LastSuccessful = true; mainGame.LastCard = finList.Single().First(); return(true); }