Exemple #1
0
        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Canvas c = (Canvas)board.getGrid().Children[1];
            Label  l = (Label)c.Children[90];

            l.Content = " " + you.getCoins();
            this.Close();
        }
 //CoinTransaction Check
 public bool canAfford(PlayerState p)
 {
     if (p.getCoins() < (coinTransactions[0] + coinTransactions[1]))
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
 public void CheckingCoins(PlayerState p, Card c)
 {
     if (Log(p))
     {
         Console.WriteLine("[{0}] Checking to see if we have enough coins: Cost {1} Has {2}"
                           , _class.GetType().Name
                           , c.getCoinCost()
                           , p.getCoins());
     }
 }
        /*
         * Input: A Player and a Card
         *
         *
         * Output: True or False -> Does the player have enough resources to play given card already?
         */
        public bool ValidateCard(PlayerState p, Card c)
        {
            //_logger.ValidatingCard(p, c);
            //_logger.CheckDictionary(p,hashtable);
            //c.toString();
            //Check for duplicity
            for (int i = 0; i < p.getPlayedCards().Count; i++)
            {
                if (c.getCardName() == p.getPlayedCards()[i].getCardName())
                {
                    if (p.getName().Equals("P0"))
                    {
                        System.Console.WriteLine("!Can't play card with the same name!");
                    }
                    return(false);
                }
            }

            //Check for precards
            if (preCardCheck(p, c))
            {
                return(true);
            }

            // First check what the coin costs and total resource cost are
            if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0)
            {
                //_logger.print(p,"Card dosn't cost anything");
                UpdateResources(p, c);
                return(true);
            }

            // If the coin cost is not equal to 0 then does the player have enoguh coins ?
            if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0)
            {
                //_logger.CheckingCoins(p, c);
                if (c.getCoinCost() <= p.getCoins())
                {
                    UpdateResources(p, c);
                    p.updateCoins(-c.getCoinCost());
                    //  _logger.CheckingPlayersCoins(p);
                    return(true);
                }
                return(false);
            }

            if (c.getTotalResourceCost() != 0)
            {
                //_logger.print(p,"Now we are working on the players Resources");
                return(CheckResourceCost(p, c.getCost()));
            }

            return(false);
        }
        //please the primary card for the type baes AIs
        public Card playPrimary(PlayerState p, List <Card> hand)
        {
            int trade;

            for (int i = 0; i < hand.Count; i++)
            {
                if (hand[i].getType() == strategy)
                {
                    if (ResourceManager.GetInstance().ValidateCard(p, hand[i]))
                    {
                        //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]);
                        p.addPlayedCards(hand[i]);
                        return(hand[i]);
                    }

                    trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 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(hand[i]);
                        return(hand[i]);
                    }
                    trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 1);

                    if ((trade > 0) && (p.getCoins() >= trade))
                    {
                        //Console.WriteLine(p.getName() + " trading for " + trade);
                        p.updateCoins(-trade);
                        ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                        p.addPlayedCards(hand[i]);
                        return(hand[i]);
                    }
                }
            }
            return(null);
        }
        private bool TradeCard(PlayerState p, Card c)
        {
            int trade = ResourceManager.GetInstance().validateTrade(p, c, 0);

            if ((trade > 0) && (p.getCoins() >= trade))
            {
                p.updateCoins(-trade);
                ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade);
                p.addPlayedCards(c);
                return(true);
            }
            trade = ResourceManager.GetInstance().validateTrade(p, c, 1);

            if ((trade > 0) && (p.getCoins() >= trade))
            {
                p.updateCoins(-trade);
                ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                p.addPlayedCards(c);
                return(true);
            }
            return(false);
        }
Exemple #7
0
        //please the primary card for the type baes AIs
        public Card playPrimary(PlayerState p, List<Card> hand)
        {
            int trade;
            for (int i = 0; i < hand.Count; i++)
            {
                if (hand[i].getType() == strategy)
                {
                    if (ResourceManager.GetInstance().ValidateCard(p, hand[i]))
                    {
                        //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]);
                        p.addPlayedCards(hand[i]);
                        return hand[i];
                    }

                    trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 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(hand[i]);
                        return hand[i];
                    }
                    trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 1);

                    if ((trade > 0) && (p.getCoins() >= trade))
                    {
                        //Console.WriteLine(p.getName() + " trading for " + trade);
                        p.updateCoins(-trade);
                        ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                        p.addPlayedCards(hand[i]);
                        return hand[i];
                    }
                }
            }
            return null;
        }
//the amount of money each player has
        private void updateMoney()
        {
            int money = player.getCoins();

            Label label = new Label();

            label.Content    = " " + money;
            label.Height     = 50;
            label.Width      = 50;
            label.FontSize   = 30;
            label.Foreground = new SolidColorBrush(Colors.White);
            label.Background = new ImageBrush(new BitmapImage(
                                                  new Uri(@"pack://application:,,,/Images/geld3.png", UriKind.RelativeOrAbsolute)));
            Canvas.SetLeft(label, 35);
            Canvas.SetTop(label, 250);
            playBoard.Children.Add(label);
        }
Exemple #9
0
 private int treasuryScore(PlayerState p) { return (p.getCoins() / 3); }
Exemple #10
0
 public void CheckingCoins(PlayerState p, Card c)
 {
     if (Log(p))
         Console.WriteLine("[{0}] Checking to see if we have enough coins: Cost {1} Has {2}"
                          , _class.GetType().Name
                          , c.getCoinCost()
                          , p.getCoins());
 }
Exemple #11
0
 public void CheckingPlayersCoins(PlayerState p)
 {
     if (Log(p))
         System.Console.WriteLine("[{0}] Player now has {1} coins", _class.GetType().Name, p.getCoins());     
 }
Exemple #12
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);
        }
Exemple #13
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));
        }
 public int getTempCoins(PlayerState p)
 {
     return(p.getCoins() - (coinTransactions[0] + coinTransactions[1]));
 }
        public bool ValidateCard (PlayerState p, Card c)
        {
           //_logger.ValidatingCard(p, c);
           //_logger.CheckDictionary(p,hashtable);

            //Get a list of preCards
            int[] preCard = c.getPreCard();
            //Go through list of preCards
            for (int i = 0; i < preCard.Length; i++)
            {
                //Check if preCard Value is valid
                if (preCard[i] < 150)
                {
                    //cycle through player's playedcards
                    for (int j = 0; j < p.getPlayedCards().Count; j++)
                    {//if the cards match then return true
                        if (p.getPlayedCards()[j].getNumber() == preCard[i]) { return true; }
                    }
                }
            }

            // First check what the coin costs and total resource cost are            
            if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.print(p,"Card dosn't cost anything");
                UpdateResources(p, c);
                return true;
            }

            // If the coin cost is not equal to 0 then does the player have enoguh coins ?
            if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.CheckingCoins(p, c);                
                if (c.getCoinCost() <= p.getCoins())
                {
                    UpdateResources(p, c);
                    p.updateCoins(-c.getCoinCost());
                 //  _logger.CheckingPlayersCoins(p);                    
                    return true;
                }
                return false;
            }

            if (c.getTotalResourceCost() != 0)
            {
               //_logger.print(p,"Now we are working on the players Resources");
                return CheckResourceCost(p,c);
            }

            return false;
        }
Exemple #16
0
 private int TreasuryScore(PlayerState p)
 {
     return(p.getCoins() / 3);
 }
Exemple #17
0
        private bool TradeCard(PlayerState p, Card c)
        {
            int trade = ResourceManager.GetInstance().validateTrade(p, c, 0);

            if ((trade > 0) && (p.getCoins() >= trade))
            {
                p.updateCoins(-trade);
                ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade);
                p.addPlayedCards(c);
                return true;
            }
            trade = ResourceManager.GetInstance().validateTrade(p, c, 1);

            if ((trade > 0) && (p.getCoins() >= trade))
            {
                p.updateCoins(-trade);
                ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                p.addPlayedCards(c);
                return true;
            }
            return false;
        }
        //Initial call to check for card validity
        public bool ValidateCard (PlayerState p, Card c)
        {
            //_logger.ValidatingCard(p, c);
            //_logger.CheckDictionary(p,hashtable);

            //Check for precards
            if (preCardCheck(p, c)) { return true; }

            // First check what the coin costs and total resource cost are            
            if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.print(p,"Card dosn't cost anything");
                UpdateResources(p, c);
                return true;
            }

            // If the coin cost is not equal to 0 then does the player have enoguh coins ?
            if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.CheckingCoins(p, c);                
                if (c.getCoinCost() <= p.getCoins())
                {
                    UpdateResources(p, c);
                    p.updateCoins(-c.getCoinCost());
                 //  _logger.CheckingPlayersCoins(p);                    
                    return true;
                }
                return false;
            }

            if (c.getTotalResourceCost() != 0)
            {
               //_logger.print(p,"Now we are working on the players Resources");
                return CheckResourceCost(p,c.getCost());
            }

            return false;
        }
Exemple #19
0
        /*
        * Input: A Player and a Card
        *
        * 
        * Output: True or False -> Does the player have enough resources to play given card already? 
        */
        public bool ValidateCard (PlayerState p, Card c)
        {
            //_logger.ValidatingCard(p, c);
            //_logger.CheckDictionary(p,hashtable);
            //c.toString();
            //Check for duplicity
            for (int i = 0; i < p.getPlayedCards().Count; i++)
            {
                if (c.getCardName() == p.getPlayedCards()[i].getCardName())
                {
                    if (p.getName().Equals("P0"))
                    {
                        System.Console.WriteLine("!Can't play card with the same name!");
                    }
                    return false; 
                }
            }

            //Check for precards
            if (preCardCheck(p, c)) { return true; }

            // First check what the coin costs and total resource cost are            
            if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.print(p,"Card dosn't cost anything");
                UpdateResources(p, c);
                return true;
            }

            // If the coin cost is not equal to 0 then does the player have enoguh coins ?
            if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0)
            {
               //_logger.CheckingCoins(p, c);                
                if (c.getCoinCost() <= p.getCoins())
                {
                    UpdateResources(p, c);
                    p.updateCoins(-c.getCoinCost());
                 //  _logger.CheckingPlayersCoins(p);                    
                    return true;
                }
                return false;
            }

            if (c.getTotalResourceCost() != 0)
            {
               //_logger.print(p,"Now we are working on the players Resources");
                return CheckResourceCost(p,c.getCost());
            }

            return false;
        }
Exemple #20
0
 public void CheckingPlayersCoins(PlayerState p)
 {
     if (Log(p))
     {
         System.Console.WriteLine("[{0}] Player now has {1} coins", _class.GetType().Name, p.getCoins());
     }
 }
Exemple #21
0
 //CoinTransaction Check
 public bool canAfford(PlayerState p)
 {
     if (p.getCoins() < (coinTransactions[0] + coinTransactions[1]))
     {
         return false;
     }
     return true;
 }
Exemple #22
0
        public Card getNextCard(PlayerState p, List<Card> hand)
        {

            Random random = new Random();
            int randomNumber;
         
            Card c = null;
            if (ResourceManager.GetInstance().ValidateWonder(p))
            {
                randomNumber = random.Next(0, 2);
                Console.WriteLine("attempting to play wonder " + randomNumber);
                if (randomNumber == 1)
                {
                    Console.WriteLine("playing wonder " + randomNumber);
                    randomNumber = random.Next(0, hand.Count - 1);
                    c = hand[randomNumber];
                    p.setWonderCards(c);
                    p.getBoard().incrementWonderLevel(p);
                    
                }
            }

            List<int> availCards = new List<int>();
            for (int i = 0; i < hand.Count; i++)
            {
                availCards.Add(i);
            }

            int trade;
            //selects a card to play
            for (int i = 0; i < hand.Count; i++)
            {
                randomNumber = random.Next(0, availCards.Count - 1);
                c = hand[availCards[randomNumber]];
                if (ResourceManager.GetInstance().ValidateCard(p, c))
                {
                    p.addPlayedCards(c);
                    return c;
                    //Console.WriteLine("===================== CHECKED CARD ===========================");
                }
                trade = ResourceManager.GetInstance().validateTrade(p, c, 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(c);
                    return c;
                }
                trade = ResourceManager.GetInstance().validateTrade(p, c, 1);

                if ((trade > 0) && (p.getCoins() >= trade))
                {
                    //Console.WriteLine(p.getName() + " trading for " + trade);
                    p.updateCoins(-trade);
                    p.addPlayedCards(c);
                    ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                    return c;
                }
                availCards.Remove(randomNumber);
                //Console.Write("RANDOM STRATEGY:: AGE :: ");
                //Console.WriteLine(ResourceManager.GetInstance().getGameState().getAge());

            }
            return null;
        }
Exemple #23
0
        public Card getNextCard(PlayerState p, List <Card> hand)
        {
            Random random = new Random();
            int    randomNumber;

            Card c = null;

            if (ResourceManager.GetInstance().ValidateWonder(p))
            {
                randomNumber = random.Next(0, 2);
                Console.WriteLine("attempting to play wonder " + randomNumber);
                if (randomNumber == 1)
                {
                    Console.WriteLine("playing wonder " + randomNumber);
                    randomNumber = random.Next(0, hand.Count - 1);
                    c            = hand[randomNumber];
                    p.setWonderCards(c);
                    p.getBoard().incrementWonderLevel(p);
                }
            }

            List <int> availCards = new List <int>();

            for (int i = 0; i < hand.Count; i++)
            {
                availCards.Add(i);
            }

            int trade;

            //selects a card to play
            for (int i = 0; i < hand.Count; i++)
            {
                randomNumber = random.Next(0, availCards.Count - 1);
                c            = hand[availCards[randomNumber]];
                if (ResourceManager.GetInstance().ValidateCard(p, c))
                {
                    p.addPlayedCards(c);
                    return(c);
                    //Console.WriteLine("===================== CHECKED CARD ===========================");
                }
                trade = ResourceManager.GetInstance().validateTrade(p, c, 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(c);
                    return(c);
                }
                trade = ResourceManager.GetInstance().validateTrade(p, c, 1);

                if ((trade > 0) && (p.getCoins() >= trade))
                {
                    //Console.WriteLine(p.getName() + " trading for " + trade);
                    p.updateCoins(-trade);
                    p.addPlayedCards(c);
                    ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade);
                    return(c);
                }
                availCards.Remove(randomNumber);
                //Console.Write("RANDOM STRATEGY:: AGE :: ");
                //Console.WriteLine(ResourceManager.GetInstance().getGameState().getAge());
            }
            return(null);
        }