private void turn() { Hand hand; bool valid = false; do { Console.Clear(); Console.WriteLine($"You are Player {Players[PlayerAtTurn].No}."); if (GameHandType == HandType.Pass) { Console.WriteLine("You decide the stack type; The stack shows:"); } else { Console.WriteLine($"The stack type is {HandTypeMethods.GetString(GameHandType)} - The stack shows:"); } if (Stack.Count == 0) { Console.WriteLine("Empty"); } else { Console.WriteLine(Stack.Last().Cards.PrintHand()); } hand = Players[PlayerAtTurn].Move(); // JF - Results in a hand // JF - Check validity of hand if (Stack.Count() == 0) { // JF - The hand is the first of the round, thus valid setRoundType(hand.Type); valid = true; } else { // JF - Check if hand is of correct type and is higher if (hand.Type == HandType.Pass) { valid = true; } else if (GameHandType == HandType.Straight & hand.Type == HandType.FullHouse) { valid = true; } else if (hand.Type == GameHandType & hand.Hight > Stack.Last().Hight) { valid = true; } else { Console.WriteLine("This hand is not allowed, try again!"); } } } while (!valid); if (hand.Type != HandType.Pass) { Stack.Add(hand); Players[PlayerAtTurn].LayHand(hand); } else { Players[PlayerAtTurn].Pass(); } nextPlayer(); }
private void setHandType() { // JF - We guess the type based on the cards // It could be that multiple types are possible, in which case the user is prompted if (Cards == null) { Type = HandType.Pass; } else if (Cards.Count == 1) { Type = HandType.Single; } else if (Cards.Count == 2) { Type = HandType.Pair; } else if (Cards.Count == 3) { Type = HandType.ThreeOfAKind; } else { // JF - There are several posabilities; We check everyone and add them to a list // TODO - Incorporate jokers var possibleTypes = new List <HandType>(); var suitsGroups = Cards.GroupBy(x => x.Suit).ToList(); var orderGroups = Cards.GroupBy(x => x.Order).ToList(); if (orderGroups.Where(x => x.Count() > 3).Count() > 0) { possibleTypes.Add(HandType.FourOfAKind); } if (orderGroups.Where(x => x.Count() == 2).Count() == 1 && orderGroups.Where(x => x.Count() == 3).Count() == 1) { possibleTypes.Add(HandType.FullHouse); } if (Cards.OrderBy(x => (int)x.Order).Skip(1).Where((x, i) => ((int)x.Order - (int)Cards[i].Order) != 1).Count() == 0) { // JF - All cards are in consecutive order possibleTypes.Add(HandType.Straight); if (suitsGroups.Count() == 1) { // JF - All cards are of the same suits possibleTypes.Add(HandType.StraightFlush); if (Cards.Where(x => x.Order == Order.Two).Count() == 1) { possibleTypes.Add(HandType.RoyalFlush); } } } if (possibleTypes.Count() == 1) { Type = possibleTypes[0]; } else if (possibleTypes.Count() > 1) { // JF - Ask player to choose handType Console.WriteLine("There are several possible hands to play, choose one:"); for (int i = 0; i < possibleTypes.Count; i++) { Console.WriteLine($"{i + 1} : {HandTypeMethods.GetString(possibleTypes[i])}"); } Console.Write($"Enter a number between 1 and {possibleTypes.Count()}: "); var choice = int.Parse(Console.ReadLine().ToString()); // JF - Set hand to choice of player Type = possibleTypes[choice - 1]; } else { throw new Exception("Unable to form hand with these cards."); } } bool valid = validate(); }
// JF - To be called when player has to make a move public Hand Move() { Hand playingHand; bool endMove = false; do { // JF - Print hand and prompt options Console.WriteLine("Your hand is:"); Console.WriteLine(Cards.PrintHand()); Console.WriteLine(Cards.PrintOptions()); // JF - Extract chosen cards and return result Console.WriteLine("Select the cards (by number, seperated by a comma) you want to play, or P to pass:"******"P")) { Console.WriteLine($"You have chosen to Pass, is that correct? (Y/N)"); playingHand = new Hand("P"); } else { // JF - Players makes a move chosenCards = choices.Select(int.Parse).Select(x => Cards[x - 1]).ToList(); playingHand = new Hand(chosenCards); Console.WriteLine($"You have chosen: {chosenCards.PrintHand()} - {HandTypeMethods.GetString(playingHand.Type)} - with " + $"{playingHand.Hight.ToString()} high - , is that correct? (Y/N)"); } string confirm = Console.ReadLine(); endMove = confirm.ToUpper() == "Y"; } while (!endMove); return(playingHand); }