예제 #1
0
 //Constructor
 public GameCard(SettlersOfCatan game , PlayingState state)
 {
     OurGame = (SettlersOfCatan)game;
     playingState = (PlayingState)state;
     //Randomize the deck
     randomGameCard();
 }
예제 #2
0
        //Build a city, any city
        public bool buildCity(Player px, SettlersOfCatan game)
        {
            //Get our current settlements
            List<GameNode> settlements = game.gameBoard.placesForCities(px);
            GameNode buildHere = null;
            int maxProb = 0;

            foreach (GameNode gn in settlements)
            {
                string gh1 = gn.hex1.hexType;
                string gh2 = gn.hex2.hexType;
                string gh3 = gn.hex3.hexType;

                if (gh1 == "Ocean" || gh2 == "Ocean" || gh3 == "Ocean") { /*ignore, it sits on a port so no real benefit to improving that one */ }
                else
                {
                    int tempProb = getProbability(gn.hex1.hexNumber) + getProbability(gn.hex2.hexNumber) + getProbability(gn.hex3.hexNumber);
                    if (tempProb > maxProb)
                    {
                        maxProb = tempProb;
                        buildHere = gn;
                    }
                }
            }

            if (buildHere != null)
            {
                PlayingState ps = (PlayingState)game.PlayingState;
                ps.AddingCity(buildHere, px);
                return true;
            }
            return false;
        }
예제 #3
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (SettlersOfCatan game = new SettlersOfCatan())
     {
         game.Run();
     }
 }
예제 #4
0
 public DrawGameBoard3D(Game game, GameBoard gameBoard)
     : base(game)
 {
     ourGame = (SettlersOfCatan)game;
     socGameBoard = (GameBoard)gameBoard;
     screenWidth = ourGame.width;
     screenHeight = ourGame.height;
     screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
 }
예제 #5
0
        public LongestRoad(SettlersOfCatan game, PlayingState state)
        {
            OurGame = (SettlersOfCatan)game;
            playingState = (PlayingState)state;
            roadBoard= OurGame.gameBoard;

            leftTotal = 0;
            rightTotal = 0;
        }
예제 #6
0
        //Purpose:  Get a list of GameHexs that are possible places to put the robber. Ideally, you place
        //          the Robber on a hex that won't affect you, only your opponents.
        //Params:   game - the overall game object
        //          aiPlayerNumber - the current AI's playerNumber
        //          highestOpponent - the Player (not including the current AI) with the highest victory points total
        //          leastObjectionable - a boolean indicating whether to accept a non-ideal return list
        //Return:   A List of GameHexs that are possible locations to move the Robber to
        public List<GameHex> possibleLocations(SettlersOfCatan game, int aiPlayerNumber, Player highestOpponent, bool leastObjectionable)
        {
            List<GameHex> possibilities = new List<GameHex>();
            List<GameNode> surroundings = null;
            bool addMe = false;
            bool filled = false;

            while (!filled)
            {
                foreach (GameHex gh in game.gameBoard.gameHexes)
                {
                    addMe = false;
                    surroundings = game.gameBoard.nodesSurroundingHex(gh);
                    foreach (GameNode gn in surroundings)
                    {
                        if (!leastObjectionable)
                        {
                            //Dont place the robber on a hex current AI touches
                            if (gn.owner == aiPlayerNumber)
                            {
                                addMe = false;
                                break;
                            }
                            //Do want to place the robber on a hex with the highest scoring player
                            else if (gn.owner == highestOpponent.playerNumber)
                                addMe = true;
                        }
                        else
                        {
                            //Find any hex with that the highest scorer touches
                            if (gn.owner == highestOpponent.playerNumber)
                            {
                                addMe = true;
                                break;
                            }
                        }
                    }

                    //Met criteria so add it to the list of possible hexes to move to
                    if (addMe)
                        possibilities.Add(gh);
                }

                //Dont return until there is at least 1 hex in the List
                if (possibilities.Count() > 0)
                    filled = true;
                else
                {
                    possibilities = possibleLocations(game, aiPlayerNumber, highestOpponent, true);
                    filled = true;
                }
            }

            return possibilities;
        }
예제 #7
0
        /***************************************************************************************
         *
         *                      Game Initializing Goes Below Here
         *
         ***************************************************************************************/
        /*
         * Purpose: Called to place settlements for the first time. Places settlement at
         *          the intersection with the highest combined probabiltiy of rolling the
         *          adjacent hex numbers.
         * Params:  px - the player rolling
         *          game - the SOC object for board access
         * Return:  None
         */
        public void placeSettlement(Player px, SettlersOfCatan game)
        {
            int maxProb = 0;
            GameNode placeHere = null;
            PlayingState ps = (PlayingState)game.PlayingState;

            List<GameNode> gns = game.gameBoard.placesForSettlements();
            foreach (GameNode gn in gns)
            {
                GameHex p1 = gn.hex1;
                GameHex p2 = gn.hex2;
                GameHex p3 = gn.hex3;

                int probCount = getProbability(p1.hexNumber) + getProbability(p2.hexNumber) + getProbability(p3.hexNumber);
                if (probCount > maxProb)
                {
                    placeHere = gn;
                    maxProb = probCount;
                }

            }

            //Claim that spot
            ps.AddingSettlement(placeHere, px);
            placeRoad(px, placeHere, game.gameBoard.boardArray);
        }
예제 #8
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();
        }
예제 #9
0
        public void discardHalf(Player px, SettlersOfCatan game)
        {
            int mustDiscard = (px.brick + px.wood + px.wool + px.ore + px.wheat) / 2;
            int discarded = 0;
            int[] discardedCards = new int[5];
            int[] currentResources = new int[5] { px.brick, px.wheat, px.wood, px.wool, px.ore };
            bool keepGoing = true;

            while (keepGoing)
            {
                int idxOfMost = indexOfMostResource(px, currentResources);
                discardedCards[idxOfMost]++;
                currentResources[idxOfMost]--;

                discarded++;

                if (mustDiscard == discarded)
                    keepGoing = false;
            }

            //actually remove everything in the discardedCards
            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < discardedCards[x]; y++)
                {
                    px.decResource(x, px);
                }
            }
        }
예제 #10
0
 public BaseGameState(Game game)
     : base(game)
 {
     Content = game.Content;
     OurGame = (SettlersOfCatan)game;
 }
예제 #11
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;
            }
        }
예제 #12
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;
        }
예제 #13
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;
        }
예제 #14
0
 //Buy a dev card
 public bool buildDevCard(Player px, SettlersOfCatan game)
 {
     if (px.canBuildDevCard)
     {
         PlayingState ps = (PlayingState)game.PlayingState;
         px = ps.gameCard.getCard(px); //does game card return somthing if you cant buy? if so check
         return true;
     }
     return false;
 }
예제 #15
0
 //Get a list of players that have settlements around the hex provided
 public IEnumerable<Player> eligibleVictims(GameHex gh, SettlersOfCatan game, Player mover)
 {
     List<Player> playerList = new List<Player>();
     List<GameNode> surroundSettles = nodesSurroundingHex(gh);
     foreach (GameNode gn in surroundSettles)
     {
         foreach (Player px in game.players)
         {
             if ((px.playerNumber == gn.owner) && (mover.playerNumber != px.playerNumber))
             {
                 playerList.Add(px);
             }
         }
     }
     IEnumerable<Player> players = playerList.Distinct();
     return players;
 }
예제 #16
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);
                    }
                }

            }
        }
예제 #17
0
        //Tries to trade for a resource type depending on int tradeFor
        public bool proposeTrade(Player theTrader, SettlersOfCatan game, int tradeFor)
        {
            Trade myTrade = null;
            switch (tradeFor)
            {
                case 0:
                    myTrade = tradeForSettlement(theTrader);
                    break;
                case 1:
                    myTrade = tradeForCity(theTrader);
                    break;
                case 2:
                    myTrade = tradeForRoad(theTrader);
                    break;
                case 3:
                    myTrade = tradeForCard(theTrader);
                    break;
            }

            if (myTrade != null)
            {
                PlayingState ps = (PlayingState)game.PlayingState;
                myTrade.tradeOffer.CopyTo(ps.currentTrade.tradeOffer, 0);
                myTrade.tradeRequest.CopyTo(ps.currentTrade.tradeRequest, 0);
                ps.currentTrade.requestingPlayer = theTrader;
                return true;
            }
            return false;
        }
예제 #18
0
        //Build a road, any road
        public bool buildRoad(Player px, SettlersOfCatan game)
        {
            List<GameRoad> grl = new List<GameRoad>();
            List<object> objList = game.gameBoard.getPlayerNodesAndRoads(px);
            GameRoad buildHere = null;

            foreach (object o in objList)
            {
                if (o is GameNode)
                {
                    GameNode tmp = (GameNode)o;
                    List<GameRoad> options = game.gameBoard.getConnectingRoads(tmp);
                    foreach (GameRoad gr in options)
                    {
                        if (gr.owner == 0)
                            grl.Add(gr);
                    }
                }
                else if (o is GameRoad)
                {
                    GameRoad gr = (GameRoad)o;
                    if (gr.Node1.owner == 0)
                    {
                        List<GameRoad> moreOptions = game.gameBoard.getConnectingRoads(gr.Node1);
                        foreach (GameRoad gr2 in moreOptions)
                        {
                            if (gr2.owner == 0)
                                grl.Add(gr2);
                        }
                    }
                    else if (gr.Node2.owner == 0)
                    {
                        List<GameRoad> moreOptions = game.gameBoard.getConnectingRoads(gr.Node2);
                        foreach (GameRoad gr2 in moreOptions)
                        {
                            if (gr2.owner == 0)
                                grl.Add(gr2);
                        }
                    }
                }
            }

            IEnumerable<GameRoad> distinctRoads = grl.Distinct();
            if (buildHere == null)
            {
                List<GameRoad> distincts = distinctRoads.ToList<GameRoad>();
                Random rnd = new Random();
                buildHere = distincts[rnd.Next(0, distincts.Count())];
                buildHere.owner = px.playerNumber;

                PlayingState ps = (PlayingState)game.PlayingState;
                ps.AddingRoad(buildHere, px);
                return true;
            }
            return false;
        }
예제 #19
0
 //Constructor
 public DrawGameBoard2D(Game game, PlayingState state)
     : base(game)
 {
     ourGame = (SettlersOfCatan)game;
     playingState = (PlayingState)state;
     screenWidth = ourGame.width;
     screenHeight = ourGame.height;
     halfWidth = screenWidth / 2;
     halfHeight = screenHeight / 2;
     screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
 }
예제 #20
0
        /***************************************************************************************
        *
        *                     Building Methods Go Below Here....Yikes
        *
        ***************************************************************************************/
        //Purpose:  Called to build settlements.
        //Params:   px - the player rolling
        //          game - the game
        //Return:   None
        public bool buildSettlement(Player px, SettlersOfCatan game)
        {
            List<GameNode> available = game.gameBoard.placesForSettlements(px);
            List<GameNode> otherOptions = new List<GameNode>();
            GameNode buildHere = null;
            int maxProb = 0;
            bool foundOne;
            string resourceType = intToType(indexOfFewestResource(px, 4));

            //Try to find your ideal spot
            foreach (GameNode gn in available)
            {
                //buildHere = gn;
                GameHex h1 = gn.hex1;
                GameHex h2 = gn.hex2;
                GameHex h3 = gn.hex3;
                foundOne = false;
                int prob = getProbability(h1.hexNumber) + getProbability(h2.hexNumber) + getProbability(h3.hexNumber);

                //Place for Settlements and Roads
                if (strategyType == 0)
                {
                    //Not interested in getting ore, so if any of them is rock then just move on
                    if ((h1.hexType == "Rock") || (h2.hexType == "Rock") || (h3.hexType == "Rock"))
                        foundOne = false;
                    //We've found a Node that has no Rock hexes and at least 1 of our minimum resource
                    else if ((h1.hexType == resourceType) || (h2.hexType == resourceType) || (h3.hexType == resourceType))
                        foundOne = true;
                    else
                        otherOptions.Add(gn);
                }
                //Place for Cities and Armies
                else if (strategyType == 1)
                {
                    //All accepted, emphasis on Ore and Wheat
                    if ((h1.hexType == "Rock") || (h1.hexType == "Grain") || (h2.hexType == "Rock") || (h2.hexType == "Grain") || (h3.hexType == "Rock") || (h3.hexType == "Grain"))
                        foundOne = true;
                    else if (prob > maxProb)
                        foundOne = true;
                    else
                        otherOptions.Add(gn);
                }

                //If we haven't set anything yet, simply set buildHere to the current Node
                //Or if prob is greater than maxProb set it to current Node
                if (foundOne)
                {
                    if ((buildHere == null) || (prob > maxProb))
                    {
                        buildHere = gn;
                        maxProb = prob;
                    }
                }

            }

            //If buildHere is still null, we didn't hit on a desired outcome, randomly choose
            if (buildHere == null)
            {
                if (otherOptions.Count() > 0)
                {
                    Random rnd = new Random();
                    buildHere = otherOptions[rnd.Next(0, otherOptions.Count())];

                    //Claim that settlement for Player px
                    PlayingState ps = (PlayingState)game.PlayingState;
                    ps.AddingSettlement(buildHere, px);
                    return true; //built something
                }
            }
            return false; //no build
        }