コード例 #1
0
ファイル: Player.cs プロジェクト: Gabino3/socAI
    private bool evaluateTradeRequest(GameState gamestate, TradeOffer trade)
    {
        bool acceptTradeRequest = false;

        if(!isAI)
        {
            // Allow player to accept / reject / modify trade
        }
        else
        {
            List<AIEngine.Objective> objectives = AIEngine.GetObjectives(this, gamestate.getGamestateBoard(), gamestate);

            foreach(AIEngine.Objective objective in objectives)
            {
                PlayerHand thisPlayerNeedResources = objective.GetCardDifferential();

                PlayerHand thisPlayerGiveResources = trade.convertGetResourcesToPlayerHand();	// tradeHost gets the resources that this Player gives
                PlayerHand thisPlayerGetResources = trade.convertGiveResourcesToPlayerHand();	// tradeHost gives the resources that this Player gets

                if(debugMessages)
                {
                    GameEngine.print (objective.GetObjectiveScore() + ": OBJECTIVE SCORE");
                    GameEngine.print ("PLAYER " + this.id + " GIVES TO TRADEHOST:" +
                                      "GIVE " + trade.getBrick + " BRICK, " +
                                      "GIVE " + trade.getOre + " ORE, " +
                                      "GIVE " + trade.getWood + " WOOD, " +
                                      "GIVE " + trade.getGrain + " GRAIN, " +
                                      "GIVE " + trade.getSheep + " SHEEP");

                    GameEngine.print ("FOR " + trade.giveBrick + " BRICK, " +
                                      "FOR " + trade.giveOre + " ORE, " +
                                      "FOR " + trade.giveWood + " WOOD, " +
                                      "FOR " + trade.giveGrain + " GRAIN, " +
                                      "FOR " + trade.giveSheep + " SHEEP");

                    int[] x = thisPlayerNeedResources.ToArray();
                    GameEngine.print ("PLAYER " + this.id + " (SELLER) NEEDS:" +
                                      x[0] + " BRICK, " +
                                      x[1] + " ORE, " +
                                      x[2] + " WOOD, " +
                                      x[3] + " GRAIN, " +
                                      x[4] + " SHEEP");
                }

                bool resourcesNeededOverlapsWithResourcesReceived = false;
                // Compare Cards Received with Cards Needed
                for(int i = 0; i < 5; i++)
                {
                    if(thisPlayerNeedResources.GetResourceQuantity(i) < 0 && thisPlayerGetResources.GetResourceQuantity(i) > 0)
                    {
                        resourcesNeededOverlapsWithResourcesReceived = true;
                    }
                }

                bool resourcesNeededOverlapsWithResourcesGiven = false;
                for(int i = 0; i < 5; i++)
                {
                    if(thisPlayerNeedResources.GetResourceQuantity(i) >= 0 && thisPlayerNeedResources.GetResourceQuantity(i) - thisPlayerGiveResources.GetResourceQuantity(i) < 0)
                    {
                        resourcesNeededOverlapsWithResourcesGiven = true;
                    }
                }

                if(debugMessages)
                {
                    // If any resources needed and received overlap && any resources needed and given do not overlap
                    GameEngine.print ("NEEDS OVERLAPS WITH GET?: " + resourcesNeededOverlapsWithResourcesReceived + "(-true-), " +
                                      "NEEDS OVERLAPS WITH GIVE?: " + resourcesNeededOverlapsWithResourcesGiven + " (-false-)");
                }

                if(resourcesNeededOverlapsWithResourcesReceived && !resourcesNeededOverlapsWithResourcesGiven)
                {
                    if(debugMessages)
                    {
                        GameEngine.print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GET NEEDED RESOURCES & ONLY TRADE SURPLUS RESOURCES @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                    }

                    if(trade.IsFairTrade() || trade.isGoodTradeForSeller())
                    {
                        acceptTradeRequest = true;
                    }
                    else
                    {
                        System.Random rand = new System.Random();

                        if(rand.Next (100) < 25)			// 25% Chance to accept an unfair trade (technically could be better for them, but sometimes worse for them)
                        {
                            acceptTradeRequest = true;
                        }
                    }
                }

                if(acceptTradeRequest)
                {
                    if(debugMessages)
                    {
                        GameEngine.print ("# # # # # # # # # # # # # # # # # # # # # # # # # # # ACCEPT TRADE # # # # # # # # # # # # # # # # # # # # # # # # # # #");
                    }

                    break;
                }
            }
        }

        return acceptTradeRequest;
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: KRLacey/socAI
    private bool evaluateTradeRequest(GameState gamestate, TradeOffer trade)
    {
        bool acceptTradeRequest = false;

        if (!isAI)
        {
            // Allow player to accept / reject / modify trade
        }
        else
        {
            List <AIEngine.Objective> objectives = AIEngine.GetObjectives(this, gamestate.getGamestateBoard(), gamestate);

            foreach (AIEngine.Objective objective in objectives)
            {
                PlayerHand thisPlayerNeedResources = objective.GetCardDifferential();

                PlayerHand thisPlayerGiveResources = trade.convertGetResourcesToPlayerHand();                   // tradeHost gets the resources that this Player gives
                PlayerHand thisPlayerGetResources  = trade.convertGiveResourcesToPlayerHand();                  // tradeHost gives the resources that this Player gets

                if (debugMessages)
                {
                    GameEngine.print(objective.GetObjectiveScore() + ": OBJECTIVE SCORE");
                    GameEngine.print("PLAYER " + this.id + " GIVES TO TRADEHOST:" +
                                     "GIVE " + trade.getBrick + " BRICK, " +
                                     "GIVE " + trade.getOre + " ORE, " +
                                     "GIVE " + trade.getWood + " WOOD, " +
                                     "GIVE " + trade.getGrain + " GRAIN, " +
                                     "GIVE " + trade.getSheep + " SHEEP");

                    GameEngine.print("FOR " + trade.giveBrick + " BRICK, " +
                                     "FOR " + trade.giveOre + " ORE, " +
                                     "FOR " + trade.giveWood + " WOOD, " +
                                     "FOR " + trade.giveGrain + " GRAIN, " +
                                     "FOR " + trade.giveSheep + " SHEEP");

                    int[] x = thisPlayerNeedResources.ToArray();
                    GameEngine.print("PLAYER " + this.id + " (SELLER) NEEDS:" +
                                     x[0] + " BRICK, " +
                                     x[1] + " ORE, " +
                                     x[2] + " WOOD, " +
                                     x[3] + " GRAIN, " +
                                     x[4] + " SHEEP");
                }

                bool resourcesNeededOverlapsWithResourcesReceived = false;
                // Compare Cards Received with Cards Needed
                for (int i = 0; i < 5; i++)
                {
                    if (thisPlayerNeedResources.GetResourceQuantity(i) < 0 && thisPlayerGetResources.GetResourceQuantity(i) > 0)
                    {
                        resourcesNeededOverlapsWithResourcesReceived = true;
                    }
                }

                bool resourcesNeededOverlapsWithResourcesGiven = false;
                for (int i = 0; i < 5; i++)
                {
                    if (thisPlayerNeedResources.GetResourceQuantity(i) >= 0 && thisPlayerNeedResources.GetResourceQuantity(i) - thisPlayerGiveResources.GetResourceQuantity(i) < 0)
                    {
                        resourcesNeededOverlapsWithResourcesGiven = true;
                    }
                }

                if (debugMessages)
                {
                    // If any resources needed and received overlap && any resources needed and given do not overlap
                    GameEngine.print("NEEDS OVERLAPS WITH GET?: " + resourcesNeededOverlapsWithResourcesReceived + "(-true-), " +
                                     "NEEDS OVERLAPS WITH GIVE?: " + resourcesNeededOverlapsWithResourcesGiven + " (-false-)");
                }

                if (resourcesNeededOverlapsWithResourcesReceived && !resourcesNeededOverlapsWithResourcesGiven)
                {
                    if (debugMessages)
                    {
                        GameEngine.print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GET NEEDED RESOURCES & ONLY TRADE SURPLUS RESOURCES @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                    }

                    if (trade.IsFairTrade() || trade.isGoodTradeForSeller())
                    {
                        acceptTradeRequest = true;
                    }
                    else
                    {
                        System.Random rand = new System.Random();

                        if (rand.Next(100) < 25)                                                // 25% Chance to accept an unfair trade (technically could be better for them, but sometimes worse for them)
                        {
                            acceptTradeRequest = true;
                        }
                    }
                }

                if (acceptTradeRequest)
                {
                    if (debugMessages)
                    {
                        GameEngine.print("# # # # # # # # # # # # # # # # # # # # # # # # # # # ACCEPT TRADE # # # # # # # # # # # # # # # # # # # # # # # # # # #");
                    }

                    break;
                }
            }
        }

        return(acceptTradeRequest);
    }