示例#1
0
 public Trade buildBankTrade(Player theTrader, int resourceRequestIdx, int resourceOfferIdx, int offerAmount)
 {
     int[] myOffer = new int[5];
     myOffer[resourceOfferIdx] = offerAmount;
     int[] myReqest = new int[5];
     myReqest[resourceRequestIdx] = 1;
     Trade myTrade = new Trade(theTrader, myOffer, myReqest);
     return myTrade;
 }
示例#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;
            }
        }
示例#3
0
        //Purpose:  trade for resources that help build settlements
        //          if you can get rid of ore do it, other wise get rid of
        //          whatever you have the most of
        //Params:   theTrader - the Player that is proposing the trade
        //Return:   A Trade object representing the proposed Trade
        public Trade tradeForSettlement(Player theTrader)
        {
            int[] currentResourceAry = resourcesToArray(theTrader);
            int[] myRequest = fillSettlementRequest(currentResourceAry);
            int[] myOffer = new int[5];

            //You have ore, try to unload it
            if (currentResourceAry[4] > 0)
            {
                if (currentResourceAry[4] == 1)
                    myOffer[4] = 1;
                else if ((currentResourceAry[4] == 2) || (currentResourceAry[4] == 3))
                    myOffer[4] = 2;
                else if (currentResourceAry[4] > 3)
                    myOffer[4] = 3;
            }
            //You don't have ore so try to trade 1:1 or 2:1 with your most plentiful
            else
            {
                int mostIDX = indexOfMostResource(theTrader, new int[1] { 4 });

                //No point in trading 1 resource you need for 1 resource you need, so dont check it
                if (currentResourceAry[mostIDX] == 2)
                    myOffer[mostIDX] = 1;
                else if (currentResourceAry[mostIDX] == 3)
                    myOffer[mostIDX] = 2;
                else if (currentResourceAry[mostIDX] > 3)
                    myOffer[mostIDX] = 3;

            }

            Trade myTrade = new Trade(theTrader, myOffer, myRequest);
            if (myTrade.isValid())
                return myTrade;
            else
                return null;
        }
示例#4
0
        public Trade tradeForRoad(Player theTrader)
        {
            int[] currentResourceAry = resourcesToArray(theTrader);
            int[] myRequest = fillRoadRequest(currentResourceAry);
            int[] myOffer = new int[5];

            //Road building is more likely to come from strategyType 0 where ore isn't important
            if (currentResourceAry[4] > 0)
            {
                if (currentResourceAry[4] == 1)
                    myOffer[4] = 1;
                else if ((currentResourceAry[4] == 2) || (currentResourceAry[4] == 3))
                    myOffer[4] = 2;
                else if (currentResourceAry[4] > 3)
                    myOffer[4] = 3;
            }
            else
            {
                int mostIDX = indexOfMostResource(theTrader, new int[1] { 4 });

                //No point in trading 1 resource you need for 1 resource you need, so dont check it
                if (currentResourceAry[mostIDX] == 2)
                    myOffer[mostIDX] = 1;
                else if (currentResourceAry[mostIDX] == 3)
                    myOffer[mostIDX] = 2;
                else if (currentResourceAry[mostIDX] > 3)
                    myOffer[mostIDX] = 3;
            }

            Trade myTrade = new Trade(theTrader, myOffer, myRequest);
            if (myTrade.isValid())
                return myTrade;
            else
                return null;
        }
示例#5
0
        public Trade tradeForCity(Player theTrader)
        {
            int[] currentResourceAry = resourcesToArray(theTrader);
            int[] myRequest = fillCityRequest(currentResourceAry);
            int[] myOffer = new int[5];

            //Hang on to your ore [4] and grain [2]
            int mostIDX = indexOfMostResource(theTrader, new int[2] { 2, 4 });

            //No point in trading 1 resource you need for 1 resource you need, so dont check it
            if (currentResourceAry[mostIDX] == 1)
                myOffer[mostIDX] = 1;
            if (currentResourceAry[mostIDX] == 2)
                myOffer[mostIDX] = 1;
            else if (currentResourceAry[mostIDX] == 3)
                myOffer[mostIDX] = 2;
            else if (currentResourceAry[mostIDX] > 3)
                myOffer[mostIDX] = 3;

            Trade myTrade = new Trade(theTrader, myOffer, myRequest);
            if (myTrade.isValid())
                return myTrade;
            else
                return null;
        }
示例#6
0
        //px is the ai player number
        //t is the trade being offered
        public bool evaluateTradeProposal(Player px, Trade t)
        {
            int[] playersResources = resourcesToArray(px);
            int numberOfRequests = 0;
            int numberOfAccepts = 0;

            for (int x = 0; x < 5; x++)
            {
                //If TradeRequest is greater than zero, the player is requesting that resource
                if (t.tradeRequest[x] > 0)
                {
                    numberOfRequests++;
                    //The Computer <i>can<i> make the trade
                    if (playersResources[x] >= t.tradeRequest[x])
                        numberOfAccepts++;
                }
            }

            bool agree = false;
            if (numberOfRequests == numberOfAccepts)
                agree = doResourcesHelp(t);

            return agree;
        }
示例#7
0
        //Purpose:  Determine if it makes sense to do the trade
        //Params:   t - the Trade being offered
        //Return:   true if you agree, false otherwise
        public bool doResourcesHelp(Trade t)
        {
            bool agreeToTrade = true;

            //Roads and Settlements
            //You need everything but ore, so just reject all trades that have that
            if (strategyType == 0)
            {
                if (t.tradeOffer[4] > 0)
                    agreeToTrade = false;
            }
            //Cities and Army
            //Everything benefits you, so agree to all trades
            else if (strategyType == 1)
            {
                agreeToTrade = true;
            }
            //Hybrid
            //Not implemented, so don't agree to trades
            else if (strategyType == 2)
                agreeToTrade = true;
            //If we get here, an error occurred, so don't agree
            else
                agreeToTrade = false;

            return agreeToTrade;
        }
示例#8
0
        //Purpose: Set up the start of the game, including game board, dice, playingstates, etc..
        public void StartGame()
        {
            //Create gameDoard
            OurGame.gameBoard = new GameBoard(OurGame.gameType);
            //Create gameDice
            OurGame.gameDice = new Dice();
            ai = new AI();
            currentTrade = new Trade();
            gameCard = new GameCard(OurGame, this);
            lr = new LongestRoad(OurGame, this);

            //Create players array and randomize
            OurGame.players = new List<Player>();
            OurGame.players.Add(new Player(1, OurGame.gameBoard));
            OurGame.players.Add(new Player(2, OurGame.gameBoard));
            OurGame.players.Add(new Player(3, OurGame.gameBoard));

            //Randomize players List
            Random rnd = new Random();
            int n = OurGame.players.Count;
            while (n > 1)
            {
                n--;
                int k = rnd.Next(n + 1);
                Player value = OurGame.players[k];
                OurGame.players[k] = OurGame.players[n];
                OurGame.players[n] = value;
            }
            //Assign players
            OurGame.aiPlayer1 = OurGame.players[0];
            OurGame.aiPlayer2 = OurGame.players[1];
            OurGame.humanPlayer = OurGame.players[2];

            rolledDice = false;
            humanPlayerTurn = false;
            aiTurn = false;
            turnWaitCounter = 0;
            roadCardCounter = 1;

            //Create the GUIs for the game
            gameBoardGraphics = new DrawGameBoard2D(Game, this);
            Game.Components.Add(gameBoardGraphics);

            gameHud = new DrawHud(Game, this);
            Game.Components.Add(gameHud);

            //Set game playing state booleans
            movingRobber = false;
            chooseTheft = false;
            gameStartMode = true;
            firstTimeThrough = true;
            monopolyMode = false;
            yearOfPlentyMode = false;
            roadCard = false;

            //Set trading booleans
            aiOneResponse = false;
            aiTwoResponse = false;
            aiResponded = false;

            aiDesiresTrade = false;
            aiRequestsTradeFromHuman = false;
            humanResponded = false;
            humanAcceptsTrade = false;

            robberGiveAway = false;

            //Set Bools for building actions
            buildingSettlement = false;
            buildingCity = false;
            buildingRoad = false;

            playerTurn = 1;
        }