Ejemplo n.º 1
0
        public int PlayMatch()
        {
            bool start = true;

            while (Player1.Count > 0 && Player2.Count > 0)
            {
                if (start)
                {
                    start = false;
                }
                else
                {
                    // after one round check if the hands are the same
                    if (HandsMatch())
                    {
                        return(3);
                    }
                }

                int card1 = Player1.Dequeue();
                int card2 = Player2.Dequeue();
                if (card1 <= Player1.Count && card2 <= Player2.Count)
                {
                    var rccg = new RecursiveCrabCombatGame();
                    rccg.Deal(Player1.ToArray().Take(card1), Player2.ToArray().Take(card2));
                    var winner = rccg.PlayMatch();
                    if (winner == 1)
                    {
                        Player1.Enqueue(card1);
                        Player1.Enqueue(card2);
                    }
                    else if (winner == 2)
                    {
                        Player2.Enqueue(card2);
                        Player2.Enqueue(card1);
                    }
                    else if (winner == 3)
                    {
                        Player1.Enqueue(card1);
                        Player1.Enqueue(card2);
                    }
                }
                else
                {
                    if (card1 > card2)
                    {
                        Player1.Enqueue(card1);
                        Player1.Enqueue(card2);
                    }
                    else
                    {
                        Player2.Enqueue(card2);
                        Player2.Enqueue(card1);
                    }
                }
            }

            // who has the full hand
            return((Player1.Count > 0) ? 1 : 2);
        }
Ejemplo n.º 2
0
        public long PlayMatch()
        {
            while (Player1.Count > 0 && Player2.Count > 0)
            {
                long card1 = Player1.Dequeue();
                long card2 = Player2.Dequeue();
                if (card1 > card2)
                {
                    Player1.Enqueue(card1);
                    Player1.Enqueue(card2);
                }
                else
                {
                    Player2.Enqueue(card2);
                    Player2.Enqueue(card1);
                }
            }

            List <long> cards = new List <long>();

            if (Player1.Count > 0)
            {
                cards.AddRange(Player1.ToArray());
            }
            else
            {
                cards.AddRange(Player2.ToArray());
            }
            long score = 0;

            for (int i = 0; i < cards.Count; i++)
            {
                score += cards[i] * (cards.Count - i);
            }
            return(score);
        }