Ejemplo n.º 1
0
    public void ShowHideTrade(bool makingOffer = true, TradeOffer offer = null)
    {
        tradeThisDiscription.renderer.enabled = !tradeThisDiscription.renderer.enabled;

        forThisDiscription.renderer.enabled = !forThisDiscription.renderer.enabled;

        offerTradeButton.renderer.enabled = !offerTradeButton.renderer.enabled;
        offerTradeButton.collider.enabled = !offerTradeButton.collider.enabled;

        offerTradeButtonText.renderer.enabled = !offerTradeButtonText.renderer.enabled;

        endTradeButtonText.renderer.enabled = !endTradeButtonText.renderer.enabled;

        endTradeButton.renderer.enabled = !endTradeButton.renderer.enabled;
        endTradeButton.collider.enabled = !endTradeButton.collider.enabled;

        int[] getArray = {};
        int[] giveArray = {};

        if(!makingOffer){
            PlayerHand get = offer.convertGetResourcesToPlayerHand();
            getArray = get.ToArray ();

            PlayerHand give = offer.convertGiveResourcesToPlayerHand();
            giveArray = give.ToArray ();
        }

        GameObject[][] tradingObjects = {tradeThisText, forThisText, tradeThis, forThis};
        int counter = 0;
        int objCounter = 0;
        foreach (GameObject[] arr in tradingObjects) {
            counter = 0;
            foreach (GameObject obj in arr){

                obj.renderer.enabled = !obj.renderer.enabled;
                if (obj.collider != null) obj.collider.enabled = !obj.collider.enabled;

                if (obj.collider == null && makingOffer){
                    obj.GetComponent<TextMesh>().text = "0";
                } else if (obj.collider == null){
                    if(objCounter == 2) obj.GetComponent<TextMesh>().text = ""+giveArray[counter];
                    else obj.GetComponent<TextMesh>().text = ""+getArray[counter];
                    counter++;
                }

            }
            objCounter++;
        }

        //TODO make gui for trading offer
        if (makingOffer) {
            offerTradeButtonText.GetComponent<TextMesh> ().text = "Offer Trade!";
            endTradeButtonText.GetComponent<TextMesh> ().text = "End Trading";

        } else {
            offerTradeButtonText.GetComponent<TextMesh> ().text = "Accept Offer";
            endTradeButtonText.GetComponent<TextMesh> ().text = "Decline Offer";
        }
    }
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
    public void ShowHideTrade(bool makingOffer = true, TradeOffer offer = null)
    {
        tradeThisDiscription.renderer.enabled = !tradeThisDiscription.renderer.enabled;


        forThisDiscription.renderer.enabled = !forThisDiscription.renderer.enabled;


        offerTradeButton.renderer.enabled = !offerTradeButton.renderer.enabled;
        offerTradeButton.collider.enabled = !offerTradeButton.collider.enabled;

        offerTradeButtonText.renderer.enabled = !offerTradeButtonText.renderer.enabled;


        endTradeButtonText.renderer.enabled = !endTradeButtonText.renderer.enabled;


        endTradeButton.renderer.enabled = !endTradeButton.renderer.enabled;
        endTradeButton.collider.enabled = !endTradeButton.collider.enabled;

        int[] getArray  = {};
        int[] giveArray = {};

        if (!makingOffer)
        {
            PlayerHand get = offer.convertGetResourcesToPlayerHand();
            getArray = get.ToArray();

            PlayerHand give = offer.convertGiveResourcesToPlayerHand();
            giveArray = give.ToArray();
        }



        GameObject[][] tradingObjects = { tradeThisText, forThisText, tradeThis, forThis };
        int            counter        = 0;
        int            objCounter     = 0;

        foreach (GameObject[] arr in tradingObjects)
        {
            counter = 0;
            foreach (GameObject obj in arr)
            {
                obj.renderer.enabled = !obj.renderer.enabled;
                if (obj.collider != null)
                {
                    obj.collider.enabled = !obj.collider.enabled;
                }

                if (obj.collider == null && makingOffer)
                {
                    obj.GetComponent <TextMesh>().text = "0";
                }
                else if (obj.collider == null)
                {
                    if (objCounter == 2)
                    {
                        obj.GetComponent <TextMesh>().text = "" + giveArray[counter];
                    }
                    else
                    {
                        obj.GetComponent <TextMesh>().text = "" + getArray[counter];
                    }
                    counter++;
                }
            }
            objCounter++;
        }

        //TODO make gui for trading offer
        if (makingOffer)
        {
            offerTradeButtonText.GetComponent <TextMesh> ().text = "Offer Trade!";
            endTradeButtonText.GetComponent <TextMesh> ().text   = "End Trading";
        }
        else
        {
            offerTradeButtonText.GetComponent <TextMesh> ().text = "Accept Offer";
            endTradeButtonText.GetComponent <TextMesh> ().text   = "Decline Offer";
        }
    }
Ejemplo n.º 4
0
    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);
    }