// Returns a fair trade proposal private TradeOffer BuildFairTrade(int currentTurn, PlayerHand cardDifferential) { int[] resourceRequest = new int[5]; int[] resourceSurplus = new int[5]; for (int i = 0; i < 5; i++) { int cards = cardDifferential.GetResourceQuantity(i); if (cards < 0) { resourceRequest[i] = -cards; } else { resourceSurplus[i] = cards; } } TradeOffer trade = new TradeOffer(this, currentTurn, resourceSurplus, resourceRequest); trade.EqualizeTrade(); return(trade); }
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); }
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 fair trade proposal private TradeOffer BuildFairTrade(int currentTurn, PlayerHand cardDifferential) { int[] resourceRequest = new int[5]; int[] resourceSurplus = new int[5]; for(int i = 0; i < 5; i++) { int cards = cardDifferential.GetResourceQuantity(i); if(cards < 0) { resourceRequest[i] = - cards; } else { resourceSurplus[i] = cards; } } TradeOffer trade = new TradeOffer (this, currentTurn, resourceSurplus, resourceRequest); trade.EqualizeTrade (); return trade; }