Esempio n. 1
0
        private Card SetCivilianStrategy(PlayerState p, List <Card> hand)
        {
            for (int i = 0; i < hand.Count(); i++)
            {
                if (noOfPlayers == 3 || noOfPlayers == 7)
                {
                    if (hand[i].getName() == "C22" ||
                        hand[i].getName() == "C23" ||
                        hand[i].getName() == "C63" ||
                        hand[i].getName() == "C64")
                    {
                        if (ResourceManager.GetInstance().ValidateCard(p, hand[i]))
                        {
                            strategy = new CivilianStrategy();
                            p.addPlayedCards(hand[i]);
                            return(hand[i]);
                        }
                    }
                }

                if (noOfPlayers == 3 || noOfPlayers == 6)
                {
                    if (hand[i].getName() == "C24" ||
                        hand[i].getName() == "C25" ||
                        hand[i].getName() == "C108" ||
                        hand[i].getName() == "C109")
                    {
                        if (ResourceManager.GetInstance().ValidateCard(p, hand[i]))
                        {
                            strategy = new CivilianStrategy();
                            p.addPlayedCards(hand[i]);
                            return(hand[i]);
                        }
                    }
                }
            }

            int vc = 0, index = 0;

            for (int i = 0; i < hand.Count(); i++)
            {
                if (hand[i] is CivilianCard)
                {
                    CivilianCard c = (CivilianCard)hand[i];
                    if (c.getVictoryPoints() > vc)
                    {
                        vc    = c.getVictoryPoints();
                        index = i;
                    }
                }
            }

            if (index != 0)
            {
                if (ResourceManager.GetInstance().ValidateCard(p, hand[index]))
                {
                    strategy = new CivilianStrategy();
                    p.addPlayedCards(hand[index]);
                    return(hand[index]);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public Card getNextCard(PlayerState p, List <Card> hand)
        {
            List <CivilianCard> civCards = new List <CivilianCard>();

            for (int i = 0; i < hand.Count; i++)
            {
                if (hand[i].getType() == 3)
                {
                    System.Console.WriteLine("CivilianStrategy():: getNextCard({0})", hand[i]);
                    civCards.Add((CivilianCard)hand[i]);
                }
            }

            // && (ResourceManager.GetInstance().ValidateCard(p, hand[i]))
            int trade;

            while (civCards.Count != 0)
            {
                CivilianCard bestCard = civCards[0];

                for (int i = 1; i < civCards.Count; i++)
                {
                    if (bestCard.getVictoryPoints() < civCards[i].getVictoryPoints())
                    {
                        bestCard = civCards[i];
                    }
                }
                if (ResourceManager.GetInstance().ValidateCard(p, bestCard))
                {
                    p.addPlayedCards(bestCard);
                    return(bestCard);
                }

                trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 0);

                if ((trade > 0) && (p.getCoins() >= trade))
                {
                    //.WriteLine(p.getName() + " trading for " + trade);
                    p.updateCoins(-trade);
                    ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade);
                    p.addPlayedCards(bestCard);
                    return(bestCard);
                }

                trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 1);

                if ((trade > 0) && (p.getCoins() >= trade))
                {
                    //Console.WriteLine(p.getName() + " trading for " + trade);
                    p.updateCoins(-trade);
                    p.addPlayedCards(bestCard);
                    ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                    return(bestCard);
                }
                civCards.Remove(bestCard);
            }

            Card cur = ult.playSecondary(p, hand);

            if (cur != null)
            {
                return(cur);
            }

            cur = ult.buildWonder(p, hand);
            if (cur != null)
            {
                return(cur);
            }

            return(ult.playAnyCard(p, hand));
        }