Example #1
0
        public static string B(string input)
        {
            /*
             * List<int> a = new List<int>();
             * List<int> b = new List<int>();
             * a.Add(5);
             * a.Add(2);
             * a.Add(1);
             * a.Add(10);
             * b.Add(5);
             * b.Add(2);
             * b.Add(1);
             * b.Add(10);
             * Console.WriteLine(a.GetHashCode().ToString());
             * Console.WriteLine(b.GetHashCode().ToString());
             * Console.WriteLine((a == b).ToString());
             * Console.WriteLine(a.Equals(b).ToString());
             * HashSet<List<int>> set = new HashSet<List<int>>();
             * set.Add(a);
             * Console.WriteLine(set.Contains(b).ToString());
             */
            RecursiveCrabCards game = new RecursiveCrabCards(input);

            game.FindWinner();
            return(game.HighestScore().ToString());
        }
Example #2
0
        internal Player FindWinner()
        {
            while (playerHands[0].Count > 0 && playerHands[1].Count > 0)
            {
                if (CheckAndStoreHand())
                {
                    //Console.WriteLine("Repeated hands! Player 1 wins game!");
                    return(Player.Player1);
                }
                int player1Card = playerHands[0].Dequeue();
                int player2Card = playerHands[1].Dequeue();
                //Console.WriteLine("Player 1: " + player1Card + ". Player 2: " + player2Card);
                Player winner;
                if (player1Card <= playerHands[0].Count && player2Card <= playerHands[1].Count)
                {
                    // Play sub game
                    // Copy the card decks
                    //Console.WriteLine("Playing Subgame!");

                    List <Queue <int> > newHands = new List <Queue <int> >();
                    newHands.Add(CopyQueue(player1Card, playerHands[0]));
                    newHands.Add(CopyQueue(player2Card, playerHands[1]));
                    RecursiveCrabCards subGame = new RecursiveCrabCards(newHands);
                    winner = subGame.FindWinner();
                }
                else
                {
                    // Highest card wins
                    if (player1Card > player2Card)
                    {
                        //Console.WriteLine("Player1 wins draw");
                        winner = Player.Player1;
                    }
                    else
                    {
                        //Console.WriteLine("Player2 wins draw");
                        winner = Player.Player2;
                    }
                }
                if (winner == Player.Player1)
                {
                    playerHands[0].Enqueue(player1Card);
                    playerHands[0].Enqueue(player2Card);
                }
                else
                {
                    playerHands[1].Enqueue(player2Card);
                    playerHands[1].Enqueue(player1Card);
                }
            }
            if (playerHands[0].Count == 0)
            {
                //Console.WriteLine("Player 2 wins game!");
                return(Player.Player2);
            }
            else
            {
                //Console.WriteLine("Player 1 wins game!");
                return(Player.Player1);
            }
        }