Пример #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;
 }
Пример #2
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();
        }
Пример #3
0
        /***************************************************************************************
         *
         *                      Trade Related Functions Below Here
         *
         ***************************************************************************************/
        //consider returning an int and then decrementing / incrementing resouces in the playing state if thats easier
        //Purpose:	Try to trade for something
        //Param:	px - the Player
        //            game - the Game
        //Return:	False for no trade, true if you're proposing a trade
        public bool tryToTrade(Player px, SettlersOfCatan game)
        {
            int[] currentResources = resourcesToArray(px);
            int least = indexOfFewestResource(px);
            int most = indexOfMostResource(px);

            //Bank Trade First
            if (currentResources[most] > 4) //not perfect, could have a port that would change that...
            {
                tradeWithBank(px, game, least); //straight up trade dont screw arounds with proposeTrade()
                px.SetBuildBools();
                px.ResourceSum();
                return false;
            }
            else
            {
                Random rdm = new Random();
                int option = rdm.Next(0, 4); //random number to decide which way to trade
                return proposeTrade(px, game, option); //propose trade
            }
            return false;
        }
Пример #4
0
 //Purpose: Get resources from surrounding nodes after settlement is placed during game startup
 public void GameStartSettlementUpdate(GameNode gn, Player px)
 {
     if (gn.hex1.hexType == "Wood")
     {
         px.wood++;
         px.ResourceSum();
     }
     if (gn.hex1.hexType == "Sheep")
     {
         px.wool++;
         px.ResourceSum();
     }
     if (gn.hex1.hexType == "Rock")
     {
         px.ore++;
         px.ResourceSum();
     }
     if (gn.hex1.hexType == "Grain")
     {
         px.wheat++;
         px.ResourceSum();
     }
     if (gn.hex1.hexType == "Clay")
     {
         px.brick++;
         px.ResourceSum();
     }
     if (gn.hex2.hexType == "Wood")
     {
         px.wood++;
         px.ResourceSum();
     }
     if (gn.hex2.hexType == "Sheep")
     {
         px.wool++;
         px.ResourceSum();
     }
     if (gn.hex2.hexType == "Rock")
     {
         px.ore++;
         px.ResourceSum();
     }
     if (gn.hex2.hexType == "Grain")
     {
         px.wheat++;
         px.ResourceSum();
     }
     if (gn.hex2.hexType == "Clay")
     {
         px.brick++;
         px.ResourceSum();
     }
     if (gn.hex3.hexType == "Wood")
     {
         px.wood++;
         px.ResourceSum();
     }
     if (gn.hex3.hexType == "Sheep")
     {
         px.wool++;
         px.ResourceSum();
     }
     if (gn.hex3.hexType == "Rock")
     {
         px.ore++;
         px.ResourceSum();
     }
     if (gn.hex3.hexType == "Grain")
     {
         px.wheat++;
         px.ResourceSum();
     }
     if (gn.hex3.hexType == "Clay")
     {
         px.brick++;
         px.ResourceSum();
     }
 }
Пример #5
0
        //Purpose: Control the actions of the AI for the AI player turn
        private void AIMove(Player px)
        {
            //Small pause so that AI turns aren't super duper fast
            if (turnWaitCounter > 1)
            {
                //During regular game if it's the aiTurn
                if (!gameStartMode && aiTurn)
                {
                    //AI move during regular turn
                    if (!rolledDice)
                    {
                        OurGame.gameDice.rollDice();
                        DrawHud.drawDice = true;
                        rolledDice = true;
                    }
                    if (!aiRequestsTradeFromHuman && !robberGiveAway)  //skip all this if requesting trade (not actually necessary but speeds it up a bit)
                    {
                        if (turnWaitCounter > 2)
                        {

                            OurGame.gameBoard.getResources(OurGame.players, OurGame.gameDice.sumDice());
                            if (OurGame.gameDice.sumDice() == 7)
                            {
                                ai.handleRobber(px, OurGame);
                                if (OurGame.humanPlayer.totalResources > 7)
                                    robberGiveAway = true;

                                if (OurGame.aiPlayer1.totalResources > 7)
                                    ai.discardHalf(OurGame.aiPlayer1, OurGame);

                                if (OurGame.aiPlayer2.totalResources > 7)
                                    ai.discardHalf(OurGame.aiPlayer2, OurGame);
                            }
                            px.SetBuildBools();
                            px.ResourceSum();

                            if (!robberGiveAway)
                            {
                                //Start Turn
                                if (!humanResponded)  //check to make sure this isn't run again if a trade was requested
                                {
                                    //Try to build, if unsuccessful we want to trade
                                    aiDesiresTrade = ai.tryToBuild(px, OurGame);
                                    if (aiDesiresTrade)
                                        aiRequestsTradeFromHuman = ai.tryToTrade(px, OurGame);  //If AI wants to trade with human set requestsTradeFromHuman = true
                                }

                                //If the human has responded and it accepts try to build again
                                if (humanResponded && humanAcceptsTrade)
                                {
                                    Player otherAI = null;
                                    if (px == OurGame.aiPlayer1)
                                        otherAI = OurGame.aiPlayer2;
                                    else
                                        otherAI = OurGame.aiPlayer1;

                                    //Get the response from the other AI to the trade
                                    bool doesOtherAIAccept = ai.evaluateTradeProposal(otherAI, currentTrade);

                                    //If both the Human and AI accept the trade
                                    if (humanAcceptsTrade && doesOtherAIAccept)
                                    {
                                        //If the Human has more VP, trade with AI
                                        if (OurGame.humanPlayer.victoryPoints > otherAI.victoryPoints)
                                            ai.processTrade(px, otherAI, OurGame);
                                        //If the AI has more VP, trade with Human
                                        else if (otherAI.victoryPoints < OurGame.humanPlayer.victoryPoints)
                                            ai.processTrade(px, OurGame.humanPlayer, OurGame);
                                        //Equal VP, just do AI for now
                                        else
                                            ai.processTrade(px, otherAI, OurGame);
                                    }
                                    //If just the human accepts the trade
                                    else if (humanAcceptsTrade)
                                        ai.processTrade(px, OurGame.humanPlayer, OurGame);
                                    //If just the AI accepts the trade
                                    else if (doesOtherAIAccept)
                                        ai.processTrade(px, otherAI, OurGame);

                                    px.ResourceSum();
                                    otherAI.ResourceSum();
                                    OurGame.humanPlayer.ResourceSum();

                                    px.SetBuildBools();
                                    otherAI.SetBuildBools();
                                    OurGame.humanPlayer.SetBuildBools();

                                    aiRequestsTradeFromHuman = ai.tryToBuild(px, OurGame);
                                    humanResponded = false;
                                    humanAcceptsTrade = false;  //Reset booleans
                                }
                                else if (humanResponded && !humanAcceptsTrade) // if the human has responded but rejects offer, just reset booleans
                                {
                                    humanResponded = false;
                                    humanAcceptsTrade = false;  //Reset booleans
                                }

                                px.SetBuildBools();
                                px.ResourceSum();

                                if (!aiRequestsTradeFromHuman) //Make sure the playerTurn isn't updated unless there is no trade requested
                                {
                                    //Check what player is next and set playerTurn and aiTurn based on that
                                    if (px.playerNumber == 3)
                                    {
                                        playerTurn = 1;
                                        if (OurGame.humanPlayer.playerNumber == 1)
                                        {
                                            aiTurn = false;
                                        }
                                    }
                                    else
                                    {
                                        playerTurn++;
                                        if ((px.playerNumber + 1) == OurGame.humanPlayer.playerNumber)
                                        {
                                            aiTurn = false;
                                        }
                                    }
                                    rolledDice = false;
                                    turnWaitCounter = 0;
                                }
                            }
                        }
                    }
                }
                //During start of game mode AI turn
                else if (gameStartMode)
                {
                    //Set settlement and road
                    ai.placeSettlement(px, OurGame);
                    //Check what turn is going and determine what player is next based on start of game progression
                    if (px.playerNumber == 1)
                    {
                        if (firstTimeThrough)
                            playerTurn++;
                        else
                            gameStartMode = false;
                    }
                    else if (px.playerNumber == 2)
                    {
                        if (firstTimeThrough)
                            playerTurn++;
                        else
                            playerTurn--;
                    }
                    else if (px.playerNumber == 3)
                    {
                        if (firstTimeThrough)
                            firstTimeThrough = false;
                        else
                            playerTurn--;
                    }
                    turnWaitCounter = 0;
                }
            }
        }
Пример #6
0
 //Purpose: Steals a random card from the player.  Used for taking a card
 //         when moving the robber
 //Params: None
 //Return: An int that represents which resource to increment for the stealing player.
 //        0 = brick
 //        1 = wheat
 //        2 = wood
 //        3 = wool
 //        4 = ore
 public int stealRandomCard(Player takeFromMe)
 {
     Random rdm = new Random();
     bool cont = true;
     int rdmRes = -1;
     if (takeFromMe.totalResources > 0)
     {
         while (cont)
         {
             rdmRes = rdm.Next(0, 5);
             int takeThis = intToResource(rdmRes, takeFromMe);
             if (takeThis > 0)
             {
                 cont = false;
                 decResource(rdmRes, takeFromMe);
                 takeFromMe.ResourceSum();
                 takeFromMe.SetBuildBools();
             }
         }
     }
     return rdmRes;
 }