private bool GetPermissionToRetryTradeRequest(int currentTurn, TradeOffer trade) { bool permission = false; String key = trade.GenerateTradeKey(); int lastRequestTurn = 0; recentTradeRequests.TryGetValue(key, out lastRequestTurn); // replaces lastRequestTurn w/ value found in dictionary, untouched if key not found if (debugMessages) { GameEngine.print("REQUEST KEY: " + key + "$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$"); GameEngine.print("TURN LAST REQUESTED: " + lastRequestTurn); } if (lastRequestTurn < currentTurn) // request not yet made this turn { if (debugMessages) { GameEngine.print("OVERWRITE KEY; FORMERLY " + lastRequestTurn + ", NOW: " + currentTurn); } if (lastRequestTurn != 0) { recentTradeRequests.Remove(key); } recentTradeRequests.Add(key, currentTurn); permission = true; } else { if (trade.TotalGetResources() > 1) { trade.dropGetCard(); trade.EqualizeTrade(); if (debugMessages) { GameEngine.print("{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{-- REATTEMPT WITH FEWER CARDS REQUESTED --}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}"); } permission = GetPermissionToRetryTradeRequest(currentTurn, trade); } } return(permission); }
// Returns a TradeOffer if the trade is valid (an identical request has not recently been made); If this is not true, returns null public TradeOffer generateAITradeRequest(int currentTurn, AIEngine.Objective objective) { TradeOffer trade = BuildFairTrade(currentTurn, objective.GetCardDifferential()); if (trade.TotalGetResources() > 1 && trade.TotalGiveResources() > 1) { trade.RandomUnequalizeTrade(); // Introduces an element of randomness to the trade algorithm } if (debugMessages) { GameEngine.print("PLAYER HAND: \n" + hand.brick + " BRICK\n" + hand.ore + " ORE\n" + hand.wood + " WOOD\n" + hand.grain + " GRAIN\n" + hand.sheep + " SHEEP"); GameEngine.print("CARDS NEEDED: \n" + objective.GetCardsNeeded().brick + " BRICK\n" + objective.GetCardsNeeded().ore + " ORE\n" + objective.GetCardsNeeded().wood + " WOOD\n" + objective.GetCardsNeeded().grain + " GRAIN\n" + objective.GetCardsNeeded().sheep + " SHEEP"); GameEngine.print("CARD DIFFERENTIAL: \n" + objective.GetCardsNeeded().GetHandSize() + " CARDS NEEDED\n" + objective.GetCardDifferential().brick + " BRICK\n" + objective.GetCardDifferential().ore + " ORE\n" + objective.GetCardDifferential().wood + " WOOD\n" + objective.GetCardDifferential().grain + " GRAIN\n" + objective.GetCardDifferential().sheep + " SHEEP"); } if (GetPermissionToRetryTradeRequest(currentTurn, trade)) { return(trade); } return(null); }
private bool GetPermissionToRetryTradeRequest(int currentTurn, TradeOffer trade) { bool permission = false; String key = trade.GenerateTradeKey (); int lastRequestTurn = 0; recentTradeRequests.TryGetValue (key, out lastRequestTurn); // replaces lastRequestTurn w/ value found in dictionary, untouched if key not found if(debugMessages) { GameEngine.print ("REQUEST KEY: " + key + "$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$"); GameEngine.print ("TURN LAST REQUESTED: " + lastRequestTurn); } if(lastRequestTurn < currentTurn) // request not yet made this turn { if(debugMessages) { GameEngine.print("OVERWRITE KEY; FORMERLY " + lastRequestTurn + ", NOW: " + currentTurn); } if(lastRequestTurn != 0) { recentTradeRequests.Remove(key); } recentTradeRequests.Add(key, currentTurn); permission = true; } else { if(trade.TotalGetResources() > 1) { trade.dropGetCard(); trade.EqualizeTrade(); if(debugMessages) { GameEngine.print ("{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{-- REATTEMPT WITH FEWER CARDS REQUESTED --}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}"); } permission = GetPermissionToRetryTradeRequest(currentTurn, trade); } } return permission; }