//Purpose: set all city information and remove resources when a city is built
        //Param: gn - gamenode that is getting the city, px - player that is placing city
        public void AddingCity(GameNode gn, Player px)
        {
            px.hiddenVictoryPoints++;
            px.victoryPoints++;
            px.cityPieces++;
            px.settlementPieces--;

            OurGame.gameBoard.setNodeInfo(gn, 1, px);

            px.ore = px.ore - 3;
            px.wheat = px.wheat - 2;

            px.SetBuildBools();

            //CheckVictoryPoints();  Not implemented yet
        }
Beispiel #2
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;
 }
Beispiel #3
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();
        }
Beispiel #4
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;
        }
Beispiel #5
0
        /***************************************************************************************
        *
        *                         Strategy Controllers Go Below Here
        *
        ***************************************************************************************/
        //Strategy 1
        //return false if it built something, true otherwise
        public bool tryToBuild(Player px, SettlersOfCatan game)
        {
            px.SetBuildBools();
            Random rdm = new Random();
            bool successfulBuild = false;

            if (px.canBuildCity)
            {
                buildCity(px, game);
            }
            else if ((px.canBuildSettlement) && (px.canBuildRoad) && (px.canBuildDevCard))
            {
                int option = rdm.Next(0, 3);
                if (option == 0)
                    successfulBuild = buildSettlement(px, game);
                else if (option == 1)
                    successfulBuild = buildRoad(px, game);
                else if (option == 2)
                    successfulBuild = buildDevCard(px, game);
            }
            else if ((px.canBuildSettlement) && (px.canBuildRoad))
            {
                int option = rdm.Next(0, 2);
                if (option == 0)
                    successfulBuild = buildSettlement(px, game);
                else if (option == 1)
                    successfulBuild = buildRoad(px, game);
            }
            else if ((px.canBuildSettlement) && (px.canBuildDevCard))
            {
                int option = rdm.Next(0, 2);
                if (option == 0)
                    successfulBuild = buildSettlement(px, game);
                else if (option == 1)
                    successfulBuild = buildDevCard(px, game);
            }
            else if ((px.canBuildRoad) && (px.canBuildDevCard))
            {
                int option = rdm.Next(0, 2);
                if (option == 0)
                    successfulBuild = buildRoad(px, game);
                else if (option == 1)
                    successfulBuild = buildDevCard(px, game);
            }
            else if (px.canBuildSettlement)
                successfulBuild = buildSettlement(px, game);
            else if (px.canBuildRoad)
                successfulBuild = buildRoad(px, game);
            else if (px.canBuildDevCard)
                successfulBuild = buildDevCard(px, game);

            px.SetBuildBools();
            return !successfulBuild;
        }
 //Purpose: set all road information and remove resources when a settlement is road
 //Param: gr - gamenode that is getting the road, px - player that is placing road
 public void AddingRoad(GameRoad gr, Player px)
 {
     px.roadPieces++;
     if (gameStartMode)
     {
         OurGame.gameBoard.setRoadInfo(gr, px);
     }
     else if(roadCard)
     {
         if (roadCardCounter != 2)
         {
             buildingRoad = true;
             OurGame.gameBoard.setRoadInfo(gr, px);
             roadCardCounter++;
         }
         else
         {
             OurGame.gameBoard.setRoadInfo(gr, px);
             buildingRoad = false;
             roadCard = false;
             roadCardCounter = 1;
         }
     }
     else if (!gameStartMode) //need to also check against Road Card
     {
         OurGame.gameBoard.setRoadInfo(gr, px);
         px.wood--;
         px.brick--;
         px.SetBuildBools();
         //lr.longestRoad(gr.locx, gr.locy, px);
     }
 }
        //Purpose: Control the actions of a human player's turn
        //Params: px - the player (humanPlayer) that is taking the turn
        private void HumanMove(Player px)
        {
            //human player's actions when in regular game mode
            if (!gameStartMode)
            {
                px.SetBuildBools();
                //Start of human player turn, set up menus for player
                if (humanPlayerTurn == false && aiTurn == false)
                {
                    humanPlayerTurn = true;
                    OurGame.humanPlayer.canRollDice = true;
                }
                //when the human player's menus have been set up see if they have rolled and update the player information accordingly
                else if (humanPlayerTurn == true && aiTurn == false)
                {
                    if (rolledDice)
                    {
                        OurGame.gameBoard.getResources(OurGame.players, OurGame.gameDice.sumDice());
                        if (OurGame.gameDice.sumDice() == 7)
                        {
                            movingRobber = true;
                            if (OurGame.aiPlayer1.totalResources > 7)
                                ai.discardHalf(OurGame.aiPlayer1, OurGame);

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

                            if (OurGame.humanPlayer.totalResources > 7)
                            {
                                robberGiveAway = true;
                                movingRobber = false;
                            }
                        }
                        px.SetBuildBools();
                        //Update player turn information so next player can go
                        if (px.playerNumber == 3)
                            playerTurn = 1;
                        else
                            playerTurn++;
                        rolledDice = false;
                    }
                }
            }
            //human player's actions when in gamestart mode
            else if (gameStartMode)
            {
                if (!buildingRoad && !humanPlayerTurn)
                {
                    buildingSettlement = true;
                    humanPlayerTurn = true;
                }
                if (!buildingSettlement && !endHumanTurn)
                {
                    buildingRoad = true;
                    endHumanTurn = true;
                }
                if (endHumanTurn && !buildingRoad)
                {
                    endHumanTurn = false;
                    humanPlayerTurn = false;
                    if (px.playerNumber == 1)
                    {
                        if (firstTimeThrough)
                            playerTurn++;
                        else
                            gameStartMode = false;
                    }
                    else if (px.playerNumber == 2)
                    {
                        if (firstTimeThrough)
                            playerTurn++;
                        else
                            playerTurn--;
                        aiTurn = true;
                    }
                    else if (px.playerNumber == 3)
                    {
                        if (firstTimeThrough)
                            firstTimeThrough = false;
                        else
                            playerTurn--;
                        aiTurn = true;
                    }
                }
            }
            turnWaitCounter = 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;
                }
            }
        }
        //Purpose: remove resouces when a devcard is bought and update the player's devcard info with the new card they received
        //Params: px - player buying the devcard
        public void BoughtDevCard(Player px)
        {
            px.wool--;
            px.wheat--;
            px.ore--;

            px.SetBuildBools();
            gameCard.getCard(px);
        }
        //Purpose: set all settlement information and remove resources when a settlement is built
        //Param: gn - gamenode that is getting the settlement, px - player that is placing settlement
        public void AddingSettlement(GameNode gn, Player px)
        {
            px.victoryPoints++;
            px.hiddenVictoryPoints++;
            px.settlementPieces++;

            //Not changing settlement type from 0 to 1 because Dallas and I assumed settlementType 0 is settlement and settlementType 1 is City
            OurGame.gameBoard.setNodeInfo(gn, 0, px);

            if (gn.hasPort)
            {
                if (gn.threePort)
                    px.hasThree = true;
                else if (gn.brickPort)
                    px.hasBrick = true;
                else if (gn.grainPort)
                    px.hasGrain = true;
                else if (gn.woodPort)
                    px.hasLumber = true;
                else if (gn.orePort)
                    px.hasOre = true;
                else if (gn.woolPort)
                    px.hasWool = true;
            }

            if (!gameStartMode)
            {
                px.wheat--;
                px.brick--;
                px.wood--;
                px.wool--;
            }

            if (gameStartMode && !firstTimeThrough)
            {
                OurGame.gameBoard.GameStartSettlementUpdate(gn, px);
            }

            px.SetBuildBools();
        }
 //Purpose: set all road information and remove resources when a settlement is road
 //Param: gr - gamenode that is getting the road, px - player that is placing road
 public void AddingRoad(GameRoad gr, Player px)
 {
     if (!gameStartMode) //need to also check against Road Card
     {
         OurGame.gameBoard.setRoadInfo(gr, px);
         px.wood--;
         px.brick--;
         px.roadPieces++;
         px.SetBuildBools();
         //CheckLongestRoad(); Not implemented yet
     }
     //else if(roadCard)
        // {
        //
     //    if (roadCardCounter < 2)
     //        {
         //      buildingRoad = true;
        //         OurGame.gameBoard.setRoadInfo(gr, px);
      //            }
       //  }
     else if (gameStartMode)
     {
         OurGame.gameBoard.setRoadInfo(gr, px);
         px.roadPieces--;
     }
 }
        //Purpose: remove resouces when a devcard is bought and update the player's devcard info with the new card they received
        //Params: px - player buying the devcard
        public void BoughtDevCard(Player px)
        {
            px.wool--;
            px.wheat--;
            px.ore--;

            px.SetBuildBools();
            //Some Code to figure out just what dev card the player got and assign it to the player
        }
        //Purpose: set all settlement information and remove resources when a settlement is built
        //Param: gn - gamenode that is getting the settlement, px - player that is placing settlement
        public void AddingSettlement(GameNode gn, Player px)
        {
            px.hiddenVictoryPoints++;
            px.victoryPoints++;
            px.settlementPieces++;

            //Not changing settlement type from 0 to 1 because Dallas and I assumed settlementType 0 is settlement and settlementType 1 is City
            OurGame.gameBoard.setNodeInfo(gn, 0, px);

            if (!gameStartMode)
            {
                px.wheat--;
                px.brick--;
                px.wood--;
                px.wool--;
            }

            px.SetBuildBools();
            //CheckLongestRoad();  Not implemented yet
            //CheckVictoryPoints();  Not implemented yet
        }
Beispiel #14
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;
 }