public static bool HasRummy(this IDeckDict <A8RoundRummyCardInformation> cardList, A8RoundRummyMainGameClass mainGame) //you have to send one more argument { if (cardList.Count != 8) { throw new BasicBlankException("Must have 8 cards in order to have the rummy"); } mainGame.LastCard = null; mainGame.LastSuccessful = false; RoundClass currentRound = mainGame.SaveRoot !.RoundList.First(); int wilds = cardList.Count(Items => Items.CardType == EnumCardType.Wild); int reverses = cardList.Count(Items => Items.CardType == EnumCardType.Reverse); EnumCardShape shapeUsed; EnumColor colorUsed; if (reverses > 1) { return(false); //can't have more than one reverse in your hand. } if (currentRound.Category == EnumCategory.Colors && currentRound.Rummy == EnumRummyType.Regular) { var blueList = cardList.Where(Items => Items.Color == EnumColor.Blue || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict(); var redList = cardList.Where(Items => Items.Color == EnumColor.Red || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict(); if (blueList.Count < 7 && redList.Count < 7) //has to be and, not or. { return(false); } mainGame.LastSuccessful = true; if (blueList.Count == 7) { mainGame.LastCard = cardList.GetLastCard(blueList); } else { mainGame.LastCard = cardList.GetLastCard(redList); } return(true); } DeckRegularDict <A8RoundRummyCardInformation> tempList; if (currentRound.Category == EnumCategory.Shapes && currentRound.Rummy == EnumRummyType.Regular) { var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => Items.Shape).ToCustomBasicList(); if (firstList.Count > 2) { return(false); } if (firstList.Count > 1 && reverses > 0) { return(false); } if (firstList.Count > 1) { if (firstList.First().Count() > 1 && firstList.Last().Count() > 1) { return(false); } if (firstList.First().Count() > 1) { shapeUsed = firstList.First().Key; } else { shapeUsed = firstList.Last().Key; } } else { shapeUsed = firstList.First().Key; } tempList = cardList.Where(Items => Items.Shape == shapeUsed || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (currentRound.Category == EnumCategory.Both && currentRound.Rummy == EnumRummyType.Regular) { var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => new { Items.Color, Items.Shape }).ToCustomBasicList(); //iffy if (firstList.Count > 2) { return(false); } if (firstList.Count > 1 && reverses > 0) { return(false); } if (firstList.Count > 1) { if (firstList.First().Count() > 1 && firstList.Last().Count() > 1) { return(false); } if (firstList.First().Count() > 1) { shapeUsed = firstList.First().Key.Shape; colorUsed = firstList.First().Key.Color; } else { shapeUsed = firstList.Last().Key.Shape; colorUsed = firstList.Last().Key.Color; } } else { shapeUsed = firstList.First().Key.Shape; colorUsed = firstList.First().Key.Color; } tempList = cardList.Where(Items => Items.CardType == EnumCardType.Wild || (Items.Color == colorUsed && Items.Shape == shapeUsed)).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (currentRound.Rummy == EnumRummyType.Kinds) { var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => Items.Value).ToCustomBasicList(); int numberUsed; if (firstList.Count > 2) { return(false); } if (firstList.Count > 1 && reverses > 0) { return(false); } if (firstList.Count > 1) { if (firstList.First().Count() > 1 && firstList.Last().Count() > 1) { return(false); } if (firstList.First().Count() > 1) { numberUsed = firstList.First().Key; } else { numberUsed = firstList.Last().Key; } } else { numberUsed = firstList.First().Key; } tempList = cardList.Where(Items => Items.Value == numberUsed || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict(); mainGame.LastSuccessful = true; mainGame.LastCard = cardList.GetLastCard(tempList); return(true); } if (currentRound.Rummy != EnumRummyType.Straight) { throw new BasicBlankException("Not Supported"); } var straightList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).OrderBy(Items => Items.Value).ToRegularDeckDict(); switch (currentRound.Category) { case EnumCategory.None: var nexts = straightList.GroupBy(Items => Items.Value).ToCustomBasicList(); var finList = nexts.Where(Items => Items.Count() > 1).ToCustomBasicList(); 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 can take the first one. return(true); case EnumCategory.Colors: return(cardList.IsStraightColorOnly(straightList, mainGame, reverses)); case EnumCategory.Shapes: return(cardList.IsStraightShapeOnly(straightList, mainGame, reverses)); case EnumCategory.Both: return(cardList.IsStraightBoth(straightList, mainGame, reverses)); default: throw new BasicBlankException("Not Supported"); } }