Beispiel #1
0
 public bool UpdateDeckPile(GameTime gameTime, DiscardPile discardPile)
 {
     if (!SSEngine.IsACardMoving)
     {
         SSEngine.IsACardMoving = true;
         deckPile[2].IsCovered  = false;
         deckPile[2].IsMoving   = true;
         deckPile[2].CourseToCard(discardPile.GetDiscardSprite());
         elapsedTime = gameTime.TotalGameTime.TotalMilliseconds;
         drawEffect.Play();
     }
     else if (deckPile[2].Time >= gameTime.TotalGameTime.TotalMilliseconds - elapsedTime && deckPile[2].IsMoving)
     {
         deckPile[2].Move(gameTime, deckPile[0].Position, discardPile.GetDiscardSprite().Position);
     }
     else if (deckPile[2].Time < gameTime.TotalGameTime.TotalMilliseconds - elapsedTime && deckPile[2].IsMoving)
     {
         discardPile.DiscardList.Add(RetrieveCard(3));
         Deck.RemoveAt(3);
         deckPile[2].Position    = deckPile[0].Position;
         deckPile[2].Destination = deckPile[2].CollisionRectangle;
         SSEngine.IsACardMoving  = false;
         deckPile[2].IsMoving    = false;
         elapsedTime             = 0.0;
         setEffect.Play();
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 public bool UpdateHand(GameTime gameTime, int i, DiscardPile discardPile)
 {
     if (!SSEngine.IsACardMoving)
     {
         SSEngine.IsACardMoving = true;
         hand[i].IsMoving       = true;
         hand[i].CourseToCard(discardPile.GetDiscardSprite());
         cardInHandPos = hand[i].Position;
         elaspedTime   = gameTime.TotalGameTime.TotalMilliseconds;
         hand[i].IsFromFaceDownToFaceUp = false;
     }
     else if (hand[i].Time >= gameTime.TotalGameTime.TotalMilliseconds - elaspedTime && hand[i].IsMoving)
     {
         hand[i].Move(gameTime, cardInHandPos, discardPile.GetDiscardSprite().Position);
     }
     else if (hand[i].Time < gameTime.TotalGameTime.TotalMilliseconds - elaspedTime && hand[i].IsMoving)
     {
         discardPile.DiscardList.Add(hand[i].Clone(discardPile.GetDiscardSprite().Position));
         SSEngine.IsACardMoving = false;
         hand[i].IsMoving       = false;
         elaspedTime            = 0.0;
         RemoveCardFromHand(i);
         setEffect.Play();
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 private static int checkHandHasThirdRank(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
 {
     if (discardPile.Count > 1 && discardPile[discardPile.Count - 1].Rank == discardPile[discardPile.Count - 2].Rank)
     {
         return(playerCards2.Find(c => c.Rank == discardPile[discardPile.Count - 1].Rank));
     }
     else
     {
         return(-1);
     }
 }
Beispiel #4
0
 private static int checkHandDiscardRank(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
 {
     if (discardPile.Count > 0)
     {
         return(playerCards2.Find(c => c.Rank == discardPile[discardPile.Count - 1].Rank &&
                                  c.Rank != RankValue.Three && c.Rank != RankValue.Four));
     }
     else
     {
         return(-1);
     }
 }
 private bool handChecking(CardSprite card, DiscardPile discardPile, Suit?changedSuit, ref string cardAbility)
 {
     if (card.Rank != discardPile[discardPile.Count - 1].Rank && card.CardSuit != changedSuit &&
         card.Rank != RankValue.Eight)
     {
         cardAbility = "Wrong Card Selected.";
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #6
0
 private static int checkHandSameRank(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
 {
     int[] sameSuits = playerCards2.FindAllIndex(c => c.CardSuit == changedSuit);
     foreach (int cards in sameSuits)
     {
         int value = playerCards2.FindCount(c => c.Rank == playerCards2[cards].Rank);
         if (value > 1)
         {
             return(cards);
         }
     }
     return(-1);
 }
Beispiel #7
0
        private static int computerVersion1(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
        {
            int compIndex;

            for (compIndex = 0; compIndex < playerCards2.Count; compIndex++)
            {
                if (playerCards2[compIndex].CardSuit == changedSuit || playerCards2[compIndex].Rank == discardPile[discardPile.Count - 1].Rank ||
                    playerCards2[compIndex].Rank == RankValue.Eight)
                {
                    return(compIndex);
                }
            }
            return(-1);
        }
Beispiel #8
0
        public bool ShuffleDeck(DiscardPile discardPile)
        {
            if (deckPile.Count == 3 && (SSEngine.VersionStage != MenuStage.LAN || SSEngine.VersionStage != MenuStage.Online ||
                                        SSEngine.Player1 != SSEngine.Player1First))
            {
                Random            random       = new Random();
                List <CardSprite> shuffledDeck = new List <CardSprite>();

                while (discardPile.Count > 1)
                {
                    CardSprite card = discardPile[random.Next(0, discardPile.Count - 1)];
                    discardPile.Remove(card);
                    shuffledDeck.Add(card);
                }

                deckPile.AddRange(shuffledDeck);

                if (SSEngine.VersionStage == MenuStage.LAN)
                {
                    byte[] data = new byte[2 * (deckPile.Count - 3) + 1];
                    data[0] = (byte)NetGame.Shuffle;
                    for (int i = 3, j = 1; j < data.Length - 1; i++, j += 2)
                    {
                        data[j]     = (byte)deckPile[i].Rank;
                        data[j + 1] = (byte)deckPile[i].CardSuit;
                    }
                    SSEngine.LANClient.Send(data);
                }
                else if (SSEngine.VersionStage == MenuStage.Online)
                {
                    NetOutgoingMessage msg = SSEngine.Peer.CreateMessage();
                    msg.Write((byte)NetGame.Shuffle);
                    msg.Write((byte)(2 * (deckPile.Count - 3)));
                    byte[] data = new byte[2 * (deckPile.Count - 3)];
                    for (int i = 3, j = 0; j < data.Length - 1; i++, j += 2)
                    {
                        data[j]     = (byte)deckPile[i].Rank;
                        data[j + 1] = (byte)deckPile[i].CardSuit;
                    }
                    msg.Write(data);
                    SSEngine.Peer.SendMessage(msg, SSEngine.Peer.Connections[0], NetDeliveryMethod.ReliableOrdered);
                }
                return(true);
            }
            return(false);
        }
Beispiel #9
0
        private static int computerVersion2(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
        {
            int card;

            for (card = 0; card < playerCards2.Count; card++)
            {
                if (changedSuit == playerCards2[card].CardSuit &&
                    (playerCards2[card].Rank == RankValue.Four || playerCards2[card].Rank == RankValue.Deuce ||
                     playerCards2[card].Rank == RankValue.Three))
                {
                    return(card);
                }
            }
            for (card = 0; card < playerCards2.Count; card++)
            {
                if (discardPile.Count > 1 && discardPile[discardPile.Count - 1] == discardPile[discardPile.Count - 2] &&
                    playerCards2[card].Rank == discardPile[discardPile.Count - 1].Rank)
                {
                    return(card);
                }
            }
            for (card = 0; card < playerCards2.Count; card++)
            {
                if (playerCards2[card].CardSuit == changedSuit)
                {
                    return(card);
                }
            }
            for (card = 0; card < playerCards2.Count; card++)
            {
                if (playerCards2[card].Rank == RankValue.Eight)
                {
                    return(card);
                }
            }
            for (card = 0; card < playerCards2.Count; card++)
            {
                if (playerCards2[card].Rank == discardPile[discardPile.Count - 1].Rank)
                {
                    return(card);
                }
            }
            return(-1);
        }
Beispiel #10
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            SSEngine.DeckSprites["AceClub"]      = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/AceClub"), RankValue.Ace, Suit.Club);
            SSEngine.DeckSprites["AceDiamond"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/AceDiamond"), RankValue.Ace, Suit.Diamond);
            SSEngine.DeckSprites["AceHearts"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/AceHearts"), RankValue.Ace, Suit.Hearts);
            SSEngine.DeckSprites["AceSpades"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/AceSpades"), RankValue.Ace, Suit.Spades);
            SSEngine.DeckSprites["DeuceClub"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/DeuceClub"), RankValue.Deuce, Suit.Club);
            SSEngine.DeckSprites["DeuceDiamond"] = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/DeuceDiamond"), RankValue.Deuce, Suit.Diamond);
            SSEngine.DeckSprites["DeuceHearts"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/DeuceHearts"), RankValue.Deuce, Suit.Hearts);
            SSEngine.DeckSprites["DeuceSpades"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/DeuceSpades"), RankValue.Deuce, Suit.Spades);
            SSEngine.DeckSprites["ThreeClub"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/ThreeClub"), RankValue.Three, Suit.Club);
            SSEngine.DeckSprites["ThreeDiamond"] = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/ThreeDiamond"), RankValue.Three, Suit.Diamond);
            SSEngine.DeckSprites["ThreeHearts"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/ThreeHearts"), RankValue.Three, Suit.Hearts);
            SSEngine.DeckSprites["ThreeSpades"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/ThreeSpades"), RankValue.Three, Suit.Spades);
            SSEngine.DeckSprites["FourClub"]     = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FourClub"), RankValue.Four, Suit.Club);
            SSEngine.DeckSprites["FourDiamond"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FourDiamond"), RankValue.Four, Suit.Diamond);
            SSEngine.DeckSprites["FourHearts"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FourHearts"), RankValue.Four, Suit.Hearts);
            SSEngine.DeckSprites["FourSpades"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FourSpades"), RankValue.Four, Suit.Spades);
            SSEngine.DeckSprites["FiveClub"]     = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FiveClub"), RankValue.Five, Suit.Club);
            SSEngine.DeckSprites["FiveDiamond"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FiveDiamond"), RankValue.Five, Suit.Diamond);
            SSEngine.DeckSprites["FiveHearts"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FiveHearts"), RankValue.Five, Suit.Hearts);
            SSEngine.DeckSprites["FiveSpades"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/FiveSpades"), RankValue.Five, Suit.Spades);
            SSEngine.DeckSprites["SixClub"]      = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SixClub"), RankValue.Six, Suit.Club);
            SSEngine.DeckSprites["SixDiamond"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SixDiamond"), RankValue.Six, Suit.Diamond);
            SSEngine.DeckSprites["SixHearts"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SixHearts"), RankValue.Six, Suit.Hearts);
            SSEngine.DeckSprites["SixSpades"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SixSpades"), RankValue.Six, Suit.Spades);
            SSEngine.DeckSprites["SevenClub"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SevenClub"), RankValue.Seven, Suit.Club);
            SSEngine.DeckSprites["SevenDiamond"] = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SevenDiamond"), RankValue.Seven, Suit.Diamond);
            SSEngine.DeckSprites["SevenHearts"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SevenHearts"), RankValue.Seven, Suit.Hearts);
            SSEngine.DeckSprites["SevenSpades"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/SevenSpades"), RankValue.Seven, Suit.Spades);
            SSEngine.DeckSprites["EightClub"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/EightClub"), RankValue.Eight, Suit.Club);
            SSEngine.DeckSprites["EightDiamond"] = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/EightDiamond"), RankValue.Eight, Suit.Diamond);
            SSEngine.DeckSprites["EightHearts"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/EightHearts"), RankValue.Eight, Suit.Hearts);
            SSEngine.DeckSprites["EightSpades"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/EightSpades"), RankValue.Eight, Suit.Spades);
            SSEngine.DeckSprites["NineClub"]     = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/NineClub"), RankValue.Nine, Suit.Club);
            SSEngine.DeckSprites["NineDiamond"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/NineDiamond"), RankValue.Nine, Suit.Diamond);
            SSEngine.DeckSprites["NineHearts"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/NineHearts"), RankValue.Nine, Suit.Hearts);
            SSEngine.DeckSprites["NineSpades"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/NineSpades"), RankValue.Nine, Suit.Spades);
            SSEngine.DeckSprites["TenClub"]      = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/TenClub"), RankValue.Ten, Suit.Club);
            SSEngine.DeckSprites["TenDiamond"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/TenDiamond"), RankValue.Ten, Suit.Diamond);
            SSEngine.DeckSprites["TenHearts"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/TenHearts"), RankValue.Ten, Suit.Hearts);
            SSEngine.DeckSprites["TenSpades"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/TenSpades"), RankValue.Ten, Suit.Spades);
            SSEngine.DeckSprites["JackClub"]     = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/JackClub"), RankValue.Jack, Suit.Club);
            SSEngine.DeckSprites["JackDiamond"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/JackDiamond"), RankValue.Jack, Suit.Diamond);
            SSEngine.DeckSprites["JackHearts"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/JackHearts"), RankValue.Jack, Suit.Hearts);
            SSEngine.DeckSprites["JackSpades"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/JackSpades"), RankValue.Jack, Suit.Spades);
            SSEngine.DeckSprites["QueenClub"]    = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/QueenClub"), RankValue.Queen, Suit.Club);
            SSEngine.DeckSprites["QueenDiamond"] = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/QueenDiamond"), RankValue.Queen, Suit.Diamond);
            SSEngine.DeckSprites["QueenHearts"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/QueenHearts"), RankValue.Queen, Suit.Hearts);
            SSEngine.DeckSprites["QueenSpades"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/QueenSpades"), RankValue.Queen, Suit.Spades);
            SSEngine.DeckSprites["KingClub"]     = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/KingClub"), RankValue.King, Suit.Club);
            SSEngine.DeckSprites["KingDiamond"]  = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/KingDiamond"), RankValue.King, Suit.Diamond);
            SSEngine.DeckSprites["KingHearts"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/KingHearts"), RankValue.King, Suit.Hearts);
            SSEngine.DeckSprites["KingSpades"]   = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/KingSpades"), RankValue.King, Suit.Spades);

            CardSprite cardBack        = new CardSprite(Game.Content.Load <Texture2D>(@"DeckOfCards/CardBack"));
            Vector2    discardPosition = new Vector2(3 * SSEngine.QuarterSceenWidth - 2 * cardBack.Texture.Width,
                                                     2 * SSEngine.QuarterSceenHeight - cardBack.Texture.Height / 2);
            CardSprite discardpileSprite = new CardSprite(Game.Content.Load <Texture2D>("DiscardPile"), discardPosition);

            discardPile  = new DiscardPile(discardpileSprite);
            deckPosition = new Vector2(3 * SSEngine.QuarterSceenWidth - discardpileSprite.Texture.Width / 2,
                                       2 * SSEngine.QuarterSceenHeight - discardpileSprite.Texture.Height / 2);
            CardSprite  deckSprite = new CardSprite(Game.Content.Load <Texture2D>("DeckPile"), deckPosition);
            SoundEffect setSound   = Game.Content.Load <SoundEffect>(@"Audio\CardSet");

            deckPile = new DeckPile(deckSprite, cardBack, Game.Content.Load <SoundEffect>(@"Audio\CardShuffle"),
                                    Game.Content.Load <SoundEffect>(@"Audio\DrawCard"), setSound);
            deckPile.ShuffleDeck();
            playerCards1 = new PlayerHand(Game.Content.Load <Texture2D>(@"Hand\ArrowButtonL"),
                                          Game.Content.Load <Texture2D>(@"Hand\ArrowButtonCoverL"), Game.Content.Load <Texture2D>(@"Hand\ArrowButtonR"),
                                          Game.Content.Load <Texture2D>(@"Hand\ArrowButtonCoverR"), cardBack.Texture, setSound);
            playerCards2 = new AIHand(cardBack.Texture, setSound);
            font         = Game.Content.Load <SpriteFont>(@"Fonts\GameFont");
            Texture2D overlay = Game.Content.Load <Texture2D>(@"Buttons\backBtnCover");

            backButton    = new SSButton(Game.Content.Load <Texture2D>(@"Buttons\SuitBackButton"), new Vector2(20f, 20f), overlay, MenuStage.Play);
            overlay       = Game.Content.Load <Texture2D>(@"Buttons\ButtonCover");
            endTurnButton = new Button(Game.Content.Load <Texture2D>(@"Buttons\SuitEndTurnButton"),
                                       new Vector2(3 * SSEngine.QuarterSceenWidth + discardpileSprite.Texture.Width,
                                                   2 * SSEngine.QuarterSceenHeight - overlay.Height / 2), overlay);
            panel = new SelectPanel(Game.Content, "Change To");
            base.LoadContent();
        }
Beispiel #11
0
 public bool AddingCardsToHand(GameTime gameTime, DiscardPile discardPile, IHand hand)
 {
     ShuffleDeck(discardPile);
     return(UpdateDeckPile(gameTime, hand));
 }
        public bool UpdateHand(GameTime gameTime, MouseState mouse, DiscardPile discardPile, Suit?changedSuit, ref string cardAbility)
        {
            for (int i = end - 1; i >= start; i--)
            {
                if (hand[i].CollisionRectangle.Contains(mouse.X, mouse.Y))
                {
                    cardsAbility(hand[i], ref cardAbility);
                }

                if (!SSEngine.IsACardMoving)
                {
                    if (mouse.LeftButton == ButtonState.Pressed &&
                        hand[i].CollisionRectangle.Contains(mouse.X, mouse.Y) &&
                        handChecking(hand[i], discardPile, changedSuit, ref cardAbility))
                    {
                        SSEngine.IsACardMoving = true;
                        hand[i].IsMoving       = true;
                        hand[i].CourseToCard(discardPile.GetDiscardSprite());
                        elaspedTime = gameTime.TotalGameTime.TotalMilliseconds;
                        cardAbility = String.Empty;
                        if (SSEngine.VersionStage == MenuStage.LAN)
                        {
                            SSEngine.LANClient.Send((byte)NetGame.Set, (byte)i);
                        }
                        else if (SSEngine.VersionStage == MenuStage.Online)
                        {
                            NetOutgoingMessage msg = SSEngine.Peer.CreateMessage();
                            msg.Write((byte)NetGame.Set);
                            msg.Write((byte)i);
                            SSEngine.Peer.SendMessage(msg, SSEngine.Peer.Connections[0], NetDeliveryMethod.ReliableOrdered);
                        }
                    }

                    if (leftButton.UpdateButton(mouse, gameTime) && start != 0)
                    {
                        if (start > 0)
                        {
                            start--;
                            end--;
                            for (int k = start, j = 0; k < end; k++, j++)
                            {
                                hand[k].Position = positions[j];
                            }
                        }
                    }
                    else if (rightButton.UpdateButton(mouse, gameTime) && hand.Count > end)
                    {
                        if (hand.Count - end > 0)
                        {
                            start++;
                            end++;
                            for (int k = start, j = 0; k < end; k++, j++)
                            {
                                hand[k].Position = positions[j];
                            }
                        }
                    }
                }
                else if (hand[i].Time >= gameTime.TotalGameTime.TotalMilliseconds - elaspedTime && hand[i].IsMoving)
                {
                    hand[i].Move(gameTime);
                }
                else if (hand[i].Time < gameTime.TotalGameTime.TotalMilliseconds - elaspedTime && hand[i].IsMoving)
                {
                    discardPile.DiscardList.Add(hand[i].Clone(discardPile.GetDiscardSprite().Position));
                    SSEngine.IsACardMoving = false;
                    hand[i].IsMoving       = false;
                    elaspedTime            = 0.0;
                    RemoveCardFromHand(i);
                    setEffect.Play();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #13
0
        private static int computerVersion3(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
        {
            int card = -1;

            if (discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank == RankValue.Deuce)
            {
                card = playerCards2.Find(c => c.Rank == RankValue.Deuce);
                if (card != -1)
                {
                    return(card);
                }
            }

            card = playerCards2.Find(c => c.Rank == RankValue.Three && c.CardSuit == changedSuit);
            if (card != -1)
            {
                int count = playerCards2.FindCount(c => changedSuit == c.CardSuit);
                if (count > 2)
                {
                    return(card);
                }

                count = playerCards2.FindCount(c => c.Rank == RankValue.Three);
                if (count > 1)
                {
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == RankValue.Three && c.CardSuit != changedSuit);
                    foreach (int found in indexes)
                    {
                        count = playerCards2.FindCount(c => c.CardSuit == playerCards2[found].CardSuit);
                        if (count > 2)
                        {
                            return(card);
                        }
                    }
                }
            }

            card = playerCards2.Find(c => c.Rank == RankValue.Four && c.CardSuit == changedSuit);
            if (card != -1)
            {
                int counts = playerCards2.FindCount(c => changedSuit == c.CardSuit && c.Rank != RankValue.Three);
                if (counts > 1 && discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank != RankValue.Three)
                {
                    return(card);
                }

                counts = playerCards2.FindCount(c => c.Rank == RankValue.Four);
                if (counts > 1)
                {
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == RankValue.Four && c.CardSuit != changedSuit);
                    foreach (int found in indexes)
                    {
                        counts = playerCards2.FindCount(c => c.CardSuit == playerCards2[found].CardSuit && c.Rank != RankValue.Three);
                        if (counts > 1)
                        {
                            return(card);
                        }
                    }
                }
            }

            card = playerCards2.Find(c => c.Rank == RankValue.Deuce && c.CardSuit == changedSuit &&
                                     discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank != RankValue.Three);
            if (card != -1)
            {
                return(card);
            }

            card = checkHandHasThirdRank(playerCards2, discardPile, changedSuit);
            if (card != -1)
            {
                return(card);
            }

            card = checkHandSameRank(playerCards2, discardPile, changedSuit);
            if (card != -1)
            {
                return(card);
            }

            card = playerCards2.Find(c => c.CardSuit == changedSuit && c.Rank != RankValue.Three && c.Rank != RankValue.Four);
            if (card != -1)
            {
                return(card);
            }

            card = checkHandDiscardRank(playerCards2, discardPile, changedSuit);
            if (card != -1)
            {
                return(card);
            }

            card = playerCards2.Find(c => c.Rank == RankValue.Eight);
            if (card != -1)
            {
                return(card);
            }

            return(-1);
        }
Beispiel #14
0
        private static int computerVersion5(AIHand playerCards2, DiscardPile discardPile, Suit?changedSuit)
        {
            int count = 0;
            int index = 0;

            if (discardPile.Count > 0 && discardPile[discardPile.Count - 1] == SSEngine.DeckSprites["QueenSpades"])
            {
                index = playerCards2.Find(c => c == SSEngine.DeckSprites["DeuceSpades"]);
                if (index != -1)
                {
                    return(index);
                }
            }

            if (discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank == RankValue.Deuce)
            {
                count = playerCards2.FindCount(c => c.Rank == RankValue.Deuce);
                if (count == 1)
                {
                    return(playerCards2.Find(c => c.Rank == RankValue.Deuce));
                }
                else if (count > 1)
                {
                    List <byte> sortCount = playerCards2.GetSelectSuitCounts(c => c.Rank == RankValue.Deuce);
                    byte[]      suitCount = new byte[sortCount.Count];
                    sortCount.CopyTo(suitCount);
                    sortCount.Sort();
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == RankValue.Deuce);
                    for (int i = 0; i < count; i++)
                    {
                        if (suitCount[i] == sortCount[sortCount.Count - 1])
                        {
                            return(indexes[i]);
                        }
                    }
                }
            }

            index = playerCards2.Find(c => c.Rank == RankValue.Three && c.CardSuit == changedSuit);
            if (index != -1)
            {
                count = playerCards2.FindCount(c => (changedSuit == c.CardSuit &&
                                                     c.Rank != RankValue.Four) || c.Rank == RankValue.Eight);
                if (count > 2)
                {
                    return(index);
                }

                count = playerCards2.FindCount(c => c.Rank == RankValue.Three);
                if (count > 1)
                {
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == RankValue.Three && c.CardSuit != changedSuit);
                    foreach (int found in indexes)
                    {
                        count = playerCards2.FindCount(c => c.CardSuit == playerCards2[found].CardSuit && c.Rank != RankValue.Four);
                        if (count > 2)
                        {
                            return(index);
                        }
                    }
                }
            }

            index = playerCards2.Find(c => c.Rank == RankValue.Four && c.CardSuit == changedSuit);
            if (index != -1)
            {
                count = playerCards2.FindCount(c => changedSuit == c.CardSuit &&
                                               (c.Rank != RankValue.Three || c.Rank == RankValue.Eight));
                if (count > 1 && discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank != RankValue.Three)
                {
                    return(index);
                }

                count = playerCards2.FindCount(c => c.Rank == RankValue.Four);
                if (count > 1)
                {
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == RankValue.Four && c.CardSuit != changedSuit);
                    foreach (int found in indexes)
                    {
                        count = playerCards2.FindCount(c => c.CardSuit == playerCards2[found].CardSuit && c.Rank != RankValue.Three);
                        if (count > 1)
                        {
                            return(index);
                        }
                    }
                }
            }

            if (discardPile.Count > 0 && discardPile[discardPile.Count - 1] != SSEngine.DeckSprites["ThreeSpades"] &&
                changedSuit == Suit.Spades)
            {
                index = playerCards2.Find(c => c == SSEngine.DeckSprites["QueenSpades"]);
                if (index != -1)
                {
                    return(index);
                }
            }

            if (discardPile.Count > 0 && discardPile[discardPile.Count - 1].Rank != RankValue.Three)
            {
                index = playerCards2.Find(c => c.Rank == RankValue.Deuce && c.CardSuit == changedSuit);
                if (index != -1)
                {
                    return(index);
                }
            }

            index = checkHandHasThirdRank(playerCards2, discardPile, changedSuit);
            if (index != -1)
            {
                return(index);
            }

            index = checkHandSameRank(playerCards2, discardPile, changedSuit);
            if (index != -1)
            {
                return(index);
            }

            index = playerCards2.Find(c => c.Rank == RankValue.Ace && c.CardSuit == changedSuit);
            if (index != -1)
            {
                Suit suit = Suit.Club;
                switch (changedSuit)
                {
                case Suit.Club:
                    suit = Suit.Spades; break;

                case Suit.Spades:
                    suit = Suit.Club; break;

                case Suit.Hearts:
                    suit = Suit.Diamond; break;

                case Suit.Diamond:
                    suit = Suit.Hearts; break;
                }
                int suitCount        = playerCards2.FindCount(c => c.CardSuit == changedSuit);
                int flippedSuitCount = playerCards2.FindCount(c => c.CardSuit == suit);
                if (flippedSuitCount > suitCount || suitCount == 1)
                {
                    return(index);
                }
            }

            index = playerCards2.Find(c => c.CardSuit == changedSuit &&
                                      c.Rank != RankValue.Ace && c.Rank != RankValue.Deuce && c.Rank != RankValue.Three && c.Rank != RankValue.Four &&
                                      c.Rank != RankValue.Eight);
            if (index != -1)
            {
                return(index);
            }

            if (discardPile.Count > 0)
            {
                count = playerCards2.FindCount(c => c.Rank == discardPile[discardPile.Count - 1].Rank);
                if (count > 1)
                {
                    List <byte> sortCount = playerCards2.GetSelectSuitCounts(c => c.Rank == discardPile[discardPile.Count - 1].Rank);
                    byte[]      suitCount = new byte[sortCount.Count];
                    sortCount.CopyTo(suitCount);
                    sortCount.Sort();
                    int[] indexes = playerCards2.FindAllIndex(c => c.Rank == discardPile[discardPile.Count - 1].Rank);
                    for (int i = 0; i < count; i++)
                    {
                        if (suitCount[i] == sortCount[sortCount.Count - 1])
                        {
                            return(indexes[i]);
                        }
                    }
                }
            }

            index = playerCards2.Find(c => c.Rank == RankValue.Eight);
            if (index != -1)
            {
                return(index);
            }

            index = checkHandDiscardRank(playerCards2, discardPile, changedSuit);
            if (index != -1)
            {
                return(index);
            }

            return(-1);
        }