Пример #1
0
        private void PlayCard(int index, Color color = Color.None)
        {
            UnoCard cardToPlay = this.Hand.ElementAt(index);

            this.Hand.RemoveAt(index);
            this.game.PlayCard(cardToPlay, color);
        }
Пример #2
0
 private bool DoCardsMatch(UnoCard cardToCompare, UnoCard cardToMatch)
 {
     return(cardToCompare.Value == Value.Wild ||
            cardToCompare.Value == Value.DrawFour ||
            cardToCompare.Value == cardToMatch.Value ||
            cardToCompare.Color == cardToMatch.Color);
 }
Пример #3
0
 private void DealHands()
 {
     for (int i = 0; i < NumberOfStartingCards; i++)
     {
         foreach (UnoBot player in this.players)
         {
             UnoCard card = this.deck.DrawCard();
             player.Hand.Add(card);
         }
     }
 }
Пример #4
0
        public UnoCard DiscardCard(int i)
        {
            if (this.cards.Count > 0)
            {
                UnoCard card = this.cards.ElementAt(i);
                this.cards.RemoveAt(i);
                return(card);
            }

            return(null);
        }
Пример #5
0
        public void PlayCard(UnoCard card)
        {
            if (this.currentCard != null)
            {
                if (((UnoCard)this.currentCard).Value == Value.DrawFour ||
                    ((UnoCard)this.currentCard).Value == Value.Wild)
                {
                    ((UnoCard)this.currentCard).Color = Color.None;
                }

                this.graveyard.Add(this.currentCard);
            }

            this.currentCard = card;
        }
Пример #6
0
        public void PlayCard(UnoCard card)
        {
            if (this.currentCard != null)
            {
                if (((UnoCard)this.currentCard).Value == Value.DrawFour ||
                    ((UnoCard)this.currentCard).Value == Value.Wild)
                {
                    ((UnoCard)this.currentCard).Color = Color.None;
                }

                this.graveyard.Add(this.currentCard);
            }

            this.currentCard = card;
        }
Пример #7
0
        public void SetupPlay()
        {
            if (!this.setupComplete)
            {
                UnoCard firstCard = this.PlayFirstCard();
                if (firstCard.Value == Value.DrawFour)
                {
                    do
                    {
                        this.deck.ReAddCardAndReShuffle(firstCard);
                        firstCard = this.PlayFirstCard();
                    } while (firstCard.Value == Value.DrawFour);
                }

                this.setupComplete = true;
            }
        }
Пример #8
0
        public void PlayCard(UnoCard card, Color selectedColor = Color.None)
        {
            switch (card.Value)
            {
            case Value.Reverse:
                if (this.players.Length == 2)
                {
                    this.currentTurn = GetNextPlayer();
                }
                else
                {
                    this.reversed = !this.reversed;
                }

                break;

            case Value.Skip:
                if (!this.initialSkip)
                {
                    this.currentTurn = GetNextPlayer();
                }
                break;

            case Value.DrawTwo:
                // Make next player draw two cards and skip their turn
                this.DrawCardsAndSkip(2);
                break;

            case Value.DrawFour:
                // Make next player draw four cards and skip their turn
                this.DrawCardsAndSkip(4);
                break;
            }

            // If the card is a Wild/DrawFour, give it the chosen color
            if (selectedColor != Color.None)
            {
                card.Color = selectedColor;
            }

            this.deck.PlayCard(card);
        }
Пример #9
0
        private int DrawCardsUntilMatch(UnoCard cardToMatch)
        {
            UnoCard drawnCard         = null;
            int     matchingCardIndex = this.Hand.Count - 1;

            do
            {
                drawnCard = this.game.DrawCard();

                if (drawnCard == null)
                {
                    int x = 0;
                }

                this.Hand.Add(drawnCard);
                matchingCardIndex++;
            } while (!DoCardsMatch(drawnCard, cardToMatch));

            return(matchingCardIndex);
        }
Пример #10
0
        private List <int> GetNumberCards(List <int> indicies)
        {
            List <int> numberCardIndicies = new List <int>();

            foreach (int index in indicies)
            {
                UnoCard card         = this.Hand.ElementAt(index);
                bool    isNumberCard = card.Value != Value.DrawFour &&
                                       card.Value != Value.DrawTwo &&
                                       card.Value != Value.Reverse &&
                                       card.Value != Value.Skip &&
                                       card.Value != Value.Wild;

                if (isNumberCard)
                {
                    numberCardIndicies.Add(index);
                }
            }

            return(numberCardIndicies);
        }
Пример #11
0
        private List <int> GetActionCards(List <int> indicies)
        {
            List <int> actionCardIndicies = new List <int>();

            foreach (int index in indicies)
            {
                UnoCard card         = this.Hand.ElementAt(index);
                bool    isActionCard = card.Value == Value.DrawFour ||
                                       card.Value == Value.DrawTwo ||
                                       card.Value == Value.Reverse ||
                                       card.Value == Value.Skip ||
                                       card.Value == Value.Wild;

                if (isActionCard)
                {
                    actionCardIndicies.Add(index);
                }
            }

            return(actionCardIndicies);
        }
Пример #12
0
        private List <int> GetValidCards(UnoCard cardToMatch)
        {
            List <int> validIndicies    = new List <int>();
            List <int> drawFourIndicies = new List <int>();

            for (int i = 0; i < this.Hand.Count; i++)
            {
                UnoCard card = this.Hand.ElementAt(i);

                if (card.Value == Value.DrawFour)
                {
                    drawFourIndicies.Add(i);
                }
                else if (DoCardsMatch(card, cardToMatch))
                {
                    validIndicies.Add(i);
                }
            }

            return(validIndicies.Count > 0 ? validIndicies : drawFourIndicies);
        }
Пример #13
0
        public void PlayTurn()
        {
            UnoCard    topCard       = this.game.LookAtTopCard();
            List <int> validIndicies = this.GetValidCards(topCard);
            int        indexToPlay   = -1;
            Color      colorToPlay   = Color.None;

            if (validIndicies.Count > 0)
            {
                switch (this.behavior)
                {
                case UnoBehavior.Passive:
                    indexToPlay = this.PickCardPassive(validIndicies);
                    break;

                case UnoBehavior.Aggressive:
                    indexToPlay = this.PickCardAggressive(validIndicies);
                    break;

                case UnoBehavior.Random:
                    indexToPlay = this.PickCardRandom(validIndicies);
                    break;
                }
            }
            else
            {
                indexToPlay = DrawCardsUntilMatch(topCard);
            }

            Debug.Assert(indexToPlay != -1, "Index of card to play should not be -1");

            UnoCard cardToPlay = this.Hand.ElementAt(indexToPlay);

            if (cardToPlay.Value == Value.Wild || cardToPlay.Value == Value.DrawFour)
            {
                colorToPlay = this.GetDeclaredColor();
            }

            this.PlayCard(indexToPlay, colorToPlay);
        }
Пример #14
0
        public void DisplayState()
        {
            for (int i = 0; i < this.players.Length; i++)
            {
                UnoBot player = this.players[i];

                if (this.currentTurn == i)
                {
                    System.Console.Write("> " + Utility.GetBehaviorString(player.GetBehavior()) + " Player " + i + ": ");
                }
                else
                {
                    System.Console.Write("  " + Utility.GetBehaviorString(player.GetBehavior()) + " Player " + i + ": ");
                }

                foreach (UnoCard card in player.Hand)
                {
                    System.Console.Write(GetCardString(card) + "  ");
                }

                System.Console.Write("\n");
            }

            System.Console.Write("\n\n");

            UnoCard topCard = (UnoCard)this.deck.GetCurrentCard();

            System.Console.Write(GetCardString(topCard) + "   D: " + this.deck.GetDeckCount() + "  G: " + this.deck.GetGraveyardCount());

            System.Console.Write("\n\n");

            int winner = HaveWinner();

            if (winner > -1)
            {
                System.Console.WriteLine("Player " + winner + " is the winner!\n");
            }
        }
Пример #15
0
        private UnoCard PlayFirstCard()
        {
            UnoCard card        = (UnoCard)this.deck.GetNextCard();
            Color   chosenColor = Color.None;

            switch (card.Value)
            {
            case Value.Skip:
                this.initialSkip = true;
                break;

            case Value.Wild:
                // Next player choose color and then continue with regular play
                chosenColor = this.players[this.GetNextPlayer()].GetDeclaredColor();
                break;
            }

            if (card.Value != Value.DrawFour)
            {
                this.PlayCard(card, chosenColor);
            }

            return(card);
        }
Пример #16
0
 public void DiscardCard(UnoCard card)
 {
     this.graveyard.Add(card);
 }
Пример #17
0
 public void AddCardToHand(UnoCard card)
 {
     this.Hand.Add(card);
 }
Пример #18
0
        private List<int> GetValidCards(UnoCard cardToMatch)
        {
            List<int> validIndicies = new List<int>();
            List<int> drawFourIndicies = new List<int>();

            for (int i = 0; i < this.Hand.Count; i++)
            {
                UnoCard card = this.Hand.ElementAt(i);

                if (card.Value == Value.DrawFour)
                {
                    drawFourIndicies.Add(i);
                }
                else if (DoCardsMatch(card, cardToMatch))
                {
                    validIndicies.Add(i);
                }
            }

            return (validIndicies.Count > 0 ? validIndicies : drawFourIndicies);
        }
Пример #19
0
        private int DrawCardsUntilMatch(UnoCard cardToMatch)
        {
            UnoCard drawnCard = null;
            int matchingCardIndex = this.Hand.Count - 1;

            do
            {
                drawnCard = this.game.DrawCard();

                if (drawnCard == null)
                {
                    int x = 0;
                }

                this.Hand.Add(drawnCard);
                matchingCardIndex++;
            } while (!DoCardsMatch(drawnCard, cardToMatch));

            return matchingCardIndex;
        }
Пример #20
0
 private bool DoCardsMatch(UnoCard cardToCompare, UnoCard cardToMatch)
 {
     return (cardToCompare.Value == Value.Wild ||
         cardToCompare.Value == Value.DrawFour ||
         cardToCompare.Value == cardToMatch.Value ||
         cardToCompare.Color == cardToMatch.Color);
 }
Пример #21
0
 public void DiscardCard(UnoCard card)
 {
     this.graveyard.Add(card);
 }
Пример #22
0
 public void AddCard(UnoCard card)
 {
     this.cards.Add(card);
 }
Пример #23
0
 public void ReAddCardAndReShuffle(UnoCard card)
 {
     this.cards.Add(card);
     this.Shuffle();
 }
Пример #24
0
 public void AddCardToHand(UnoCard card)
 {
     this.Hand.Add(card);
 }
Пример #25
0
        private string GetCardString(UnoCard card)
        {
            string cardString = string.Empty;

            switch (card.Color)
            {
                case Color.Red:
                    cardString += "R";
                    break;
                case Color.Blue:
                    cardString += "B";
                    break;
                case Color.Green:
                    cardString += "G";
                    break;
                case Color.Yellow:
                    cardString += "Y";
                    break;
                case Color.None:
                    cardString += "N";
                    break;
            }

            switch (card.Value)
            {
                case Value.Zero:
                    cardString += "00";
                    break;
                case Value.One:
                    cardString += "01";
                    break;
                case Value.Two:
                    cardString += "02";
                    break;
                case Value.Three:
                    cardString += "03";
                    break;
                case Value.Four:
                    cardString += "04";
                    break;
                case Value.Five:
                    cardString += "05";
                    break;
                case Value.Six:
                    cardString += "06";
                    break;
                case Value.Seven:
                    cardString += "07";
                    break;
                case Value.Eight:
                    cardString += "08";
                    break;
                case Value.Nine:
                    cardString += "09";
                    break;
                case Value.Reverse:
                    cardString += "Re";
                    break;
                case Value.Skip:
                    cardString += "Sk";
                    break;
                case Value.DrawTwo:
                    cardString += "D2";
                    break;
                case Value.DrawFour:
                    cardString += "D4";
                    break;
                case Value.Wild:
                    cardString += "Wi";
                    break;
            }

            return cardString;
        }
Пример #26
0
        private string GetCardString(UnoCard card)
        {
            string cardString = string.Empty;

            switch (card.Color)
            {
            case Color.Red:
                cardString += "R";
                break;

            case Color.Blue:
                cardString += "B";
                break;

            case Color.Green:
                cardString += "G";
                break;

            case Color.Yellow:
                cardString += "Y";
                break;

            case Color.None:
                cardString += "N";
                break;
            }

            switch (card.Value)
            {
            case Value.Zero:
                cardString += "00";
                break;

            case Value.One:
                cardString += "01";
                break;

            case Value.Two:
                cardString += "02";
                break;

            case Value.Three:
                cardString += "03";
                break;

            case Value.Four:
                cardString += "04";
                break;

            case Value.Five:
                cardString += "05";
                break;

            case Value.Six:
                cardString += "06";
                break;

            case Value.Seven:
                cardString += "07";
                break;

            case Value.Eight:
                cardString += "08";
                break;

            case Value.Nine:
                cardString += "09";
                break;

            case Value.Reverse:
                cardString += "Re";
                break;

            case Value.Skip:
                cardString += "Sk";
                break;

            case Value.DrawTwo:
                cardString += "D2";
                break;

            case Value.DrawFour:
                cardString += "D4";
                break;

            case Value.Wild:
                cardString += "Wi";
                break;
            }

            return(cardString);
        }
Пример #27
0
 public void ReAddCardAndReShuffle(UnoCard card)
 {
     this.cards.Add(card);
     this.Shuffle();
 }
Пример #28
0
        public void PlayCard(UnoCard card, Color selectedColor = Color.None)
        {
            switch (card.Value)
            {
                case Value.Reverse:
                    if (this.players.Length == 2)
                    {
                        this.currentTurn = GetNextPlayer();
                    }
                    else
                    {
                        this.reversed = !this.reversed;
                    }

                    break;
                case Value.Skip:
                    if (!this.initialSkip)
                    {
                        this.currentTurn = GetNextPlayer();
                    }
                    break;
                case Value.DrawTwo:
                    // Make next player draw two cards and skip their turn
                    this.DrawCardsAndSkip(2);
                    break;
                case Value.DrawFour:
                    // Make next player draw four cards and skip their turn
                    this.DrawCardsAndSkip(4);
                    break;
            }

            // If the card is a Wild/DrawFour, give it the chosen color
            if (selectedColor != Color.None)
            {
                card.Color = selectedColor;
            }

            this.deck.PlayCard(card);
        }