Example #1
0
 public void MonopolyChosen(int resource, Player monopolyPlayer)
 {
     foreach (Player px in OurGame.players)
     {
         if (px != monopolyPlayer)
         {
             int amountOfResource;
             amountOfResource = px.intToResource(resource, px);
             for (int i = amountOfResource; i > 0; i--)
             {
                 px.decResource(resource, px);
                 monopolyPlayer.incResource(resource);
             }
         }
         px.ResourceSum();
     }
     monopolyPlayer.devCards[7]--;
     monopolyPlayer.cardsAvailable[7]--;
     monopolyPlayer.ResourceSum();
     monopolyPlayer.SetBuildBools();
     if (monopolyPlayer == OurGame.humanPlayer)
         DrawHud.playedCard = true;
 }
Example #2
0
        //bank idx is what you want to exchange with the bank
        //bank trade shoudl be good all the time, so return false because you
        //dont want to trade with the other players
        public void tradeWithBank(Player theTrader, SettlersOfCatan game, int bankIdx)
        {
            //Get a list of the nodes you own
            List<GameNode> ownedNodes = game.gameBoard.getPlayerNodes(theTrader);
            Trade myTrade = new Trade();
            int[] currentResources = resourcesToArray(theTrader);
            int resourceOffer;

            //Yuck
            foreach (GameNode gn in ownedNodes)
            {
                //Trade 2:1 for a brick
                if ((gn.brickPort) && (bankIdx == 0))
                {
                    resourceOffer = indexOfMostResource(theTrader, new int[1] { 0 });
                    myTrade = buildBankTrade(theTrader, 0, resourceOffer, 2);
                }
                //Trade 2:1 for a wheat
                else if ((gn.grainPort) && (bankIdx == 1))
                {
                    resourceOffer = indexOfMostResource(theTrader, new int[1] { 1 });
                    myTrade = buildBankTrade(theTrader, 1, resourceOffer, 2);
                }
                //Trade 2:1 for a wood
                else if ((gn.woodPort) && (bankIdx == 2))
                {
                    resourceOffer = indexOfMostResource(theTrader, new int[1] { 2 });
                    myTrade = buildBankTrade(theTrader, 2, resourceOffer, 2);
                }
                //Trade 2:1 for a wool
                else if ((gn.woolPort) && (bankIdx == 3))
                {
                    resourceOffer = indexOfMostResource(theTrader, new int[1] { 3 });
                    myTrade = buildBankTrade(theTrader, 3, resourceOffer, 2);
                }
                //Trade 2:1 for an ore
                else if ((gn.orePort) && (bankIdx == 4))
                {
                    resourceOffer = indexOfMostResource(theTrader, new int[1] { 4 });
                    myTrade = buildBankTrade(theTrader, 4, resourceOffer, 2);
                }
                //Trade 3:1 for anything except what you want
                else if (gn.threePort)
                {
                    resourceOffer = indexOfMostResource(theTrader);
                    if ((currentResources[resourceOffer] > 3) && (resourceOffer != bankIdx))
                        myTrade = buildBankTrade(theTrader, bankIdx, resourceOffer, 3);
                }
                //Trade 4:1 for anything
                else
                {
                    resourceOffer = indexOfMostResource(theTrader);
                    if ((currentResources[resourceOffer] > 4) && (bankIdx != resourceOffer))
                        myTrade = buildBankTrade(theTrader, bankIdx, resourceOffer, 4);
                }

                if (myTrade != null)
                    break;

            }

            if (myTrade != null)
            {
                //Console.WriteLine("Trading With The Bank: " + theTrader.brick.ToString() + " " + theTrader.wheat.ToString() + " " + theTrader.wood.ToString() + " " + theTrader.wool.ToString() + " " + theTrader.ore.ToString());
                for (int x = 0; x < 5; x++)
                {
                    if(myTrade.tradeOffer[x] != 0)
                    {
                        for (int y = 0; y < myTrade.tradeOffer[x]; y++)
                        {
                            theTrader.decResource(x, theTrader);
                        }
                    }
                }

                for(int x = 0; x<5; x++)
                {
                    if (myTrade.tradeRequest[x] != 0)
                    {
                        for (int y = 0; y < myTrade.tradeRequest[x]; y++)
                        {
                            theTrader.incResource(x);
                        }
                    }
                }
                //Console.WriteLine("Traded With The Bank: " + theTrader.brick.ToString() + " " + theTrader.wheat.ToString() + " " + theTrader.wood.ToString() + " " + theTrader.wool.ToString() + " " + theTrader.ore.ToString());
                //PlayingState ps = (PlayingState)game.PlayingState;
                //ps.currentTrade = myTrade;
            }
        }
Example #3
0
        //Switch around resources between the two AIs
        public void processTrade(Player traderOfferer, Player traderAcceptor, SettlersOfCatan game)
        {
            PlayingState ps = (PlayingState)game.PlayingState;

            //Loop through tradeRequest and add those to tradeOfferer and remove from tradeAccepter
            for (int x = 0; x < 5; x++)
            {
                if (ps.currentTrade.tradeRequest[x] != 0)
                {
                    for(int y=0; y< ps.currentTrade.tradeRequest[x]; y++)
                    {
                        traderOfferer.incResource(x);
                        traderOfferer.decResource(x, traderAcceptor);
                    }
                }
            }

            //Loop through tradeOffer and add those to tradeAccepter and remove from tradeOfferer
            for (int x = 0; x < 5; x++)
            {
                if (ps.currentTrade.tradeOffer[x] != 0)
                {
                    for (int y = 0; y < ps.currentTrade.tradeOffer[x]; y++)
                    {
                        traderAcceptor.incResource(x);
                        traderAcceptor.decResource(x, traderOfferer);
                    }
                }

            }
        }
Example #4
0
        /***************************************************************************************
         *
         *                     Robber Related Functions Goes Below Here
         *
         ***************************************************************************************/
        //Purpose:  Handle all functionality for the AI to move the Robber
        //Params:   px - the Player that is moving the Robber
        //          game - the overall game object
        //Return:   None
        public void handleRobber(Player px, SettlersOfCatan game)
        {
            //Get the Player with the most victory points
            Player highestOpponent = highestScoringOpponent(px.playerNumber, game.players);
            //Get a list of possible locations to move the Robber to
            List<GameHex> locations = possibleLocations(game, px.playerNumber, highestOpponent, false);

            //Randomly pick one of those locations
            Random rdm = new Random();
            game.gameBoard.setRobber(locations[rdm.Next(0, locations.Count())]);

            //Steal resource card
            int resourceType = px.stealRandomCard(highestOpponent);
            px.incResource(resourceType);

            px.SetBuildBools();
            px.ResourceSum();
        }
Example #5
0
 //Purpose: increments/decrements appropriate resources for the two players trading
 public void humanTradeWithAI(Player humanPlayer, Player aiTradingWith)
 {
     for (int j = 0; j < 5; j++)
     {
         if (tradeOffer[j] > 0)
         {
             while (tradeOffer[j] > 0)
             {
                 humanPlayer.decResource(j, humanPlayer);
                 aiTradingWith.incResource(j);
                 tradeOffer[j]--;
             }
         }
         if (tradeRequest[j] > 0)
         {
             while (tradeRequest[j] > 0)
             {
                 humanPlayer.incResource(j);
                 aiTradingWith.decResource(j, aiTradingWith);
                 tradeRequest[j]--;
             }
         }
     }
 }
Example #6
0
 //Purpose: Gives resources requested from year of plenty trade
 public void yopTrade(Player px)
 {
     for (int j = 0; j < yopRequest.Length; j++)
     {
         if (yopRequest[j] == 1)
         {
             px.incResource(j);
         }
         if (yopRequest[j] == 2)
         {
             px.incResource(j);
             px.incResource(j);
         }
     }
 }
Example #7
0
        //Purpose: to see if trade to bank was valid, if so decrements player cards offered and increments player cards desired
        //Returns: boolean to determine whether the offer was a valid trade offer
        public bool isBankTradeValid(Player px)
        {
            bool tradeComplete = false;

            if (px.hasBrick && tradeOffer[0] > 1 && px.brick > 1)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tradeRequest[j] > 0)
                    {
                        if (j != 0)
                        {
                            px.decResource(0, px);
                            px.decResource(0, px);
                            px.incResource(j);
                            tradeComplete = true;
                            return tradeComplete;
                        }
                    }
                }
            }
            if (px.hasGrain && tradeOffer[1] > 1 && px.wheat > 1)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tradeRequest[j] > 0)
                    {
                        if (j != 1)
                        {
                            px.decResource(1, px);
                            px.decResource(1, px);
                            px.incResource(j);
                            tradeComplete = true;
                            return tradeComplete;
                        }
                    }
                }
            }
            if (px.hasLumber && tradeOffer[2] > 1 && px.wood > 1)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tradeRequest[j] > 0)
                    {
                        if (j != 2)
                        {
                            px.decResource(2, px);
                            px.decResource(2, px);
                            px.incResource(j);
                            tradeComplete = true;
                            return tradeComplete;
                        }
                    }
                }
            }
            if (px.hasWool && tradeOffer[3] > 1 && px.wool > 1)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tradeRequest[j] > 0)
                    {
                        if (j != 4)
                        {
                            px.decResource(3, px);
                            px.decResource(3, px);
                            px.incResource(j);
                            tradeComplete = true;
                            return tradeComplete;
                        }
                    }
                }
            }
            if (px.hasOre && tradeOffer[4] > 1 && px.ore > 1)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tradeRequest[j] > 0)
                    {
                        if (j != 3)
                        {
                            px.decResource(4, px);
                            px.decResource(4, px);
                            px.incResource(j);
                            tradeComplete = true;
                            return tradeComplete;
                        }
                    }
                }
            }
            if (px.hasThree)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (tradeOffer[i] > 2)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            if (tradeRequest[j] > 0)
                            {
                                if (j != i)
                                {
                                    px.decResource(i, px);
                                    px.decResource(i, px);
                                    px.decResource(i, px);
                                    px.incResource(j);
                                    tradeComplete = true;
                                    return tradeComplete;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    if (tradeOffer[i] > 3)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            if (tradeRequest[j] > 0)
                            {
                                if (j != i)
                                {
                                    px.decResource(i, px);
                                    px.decResource(i, px);
                                    px.decResource(i, px);
                                    px.decResource(i, px);
                                    px.incResource(j);
                                    tradeComplete = true;
                                    return tradeComplete;
                                }
                            }
                        }
                    }
                }
            }
            return tradeComplete;
        }