From: Erik V. <ev...@us...> - 2011-11-21 16:42:21
|
LocalisedText.properties | 4 ++-- rails/game/StockRound.java | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) New commits: commit cd74aa6bf8943b56ce719db283e90fa0bac4e275 Author: Erik Vos <eri...@xs...> Date: Mon Nov 21 17:40:58 2011 +0100 Fixed presidency dumping issues after previous commit. Added 5 test cases for share selling and nationalisation issues. diff --git a/LocalisedText.properties b/LocalisedText.properties index d957c20..5d32604 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -557,8 +557,8 @@ SelectStationForToken={0}, select a station on hex {1} for the {2} home base tok SelectStationForTokenOption=Place token in station {0} with tracks to {1} SelectForAuctioning={0} selects {1} for auctioning SELL=Sell -SELL_SHARE_LOG={0} sells a {1}% share of {2} to Pool for {3}. -SELL_SHARES_LOG={0} sells {1} {2}% shares ({3}%) of {4} to Pool for {5}. +SELL_SHARE_LOG={0} sells a {1}% certificate of {2} to Pool for {3}. +SELL_SHARES_LOG={0} sells {1} {2}% certificates ({3}%) of {4} to Pool for {5}. SellHowManyShares=Sell how many shares? SellShares=Sell {0} {1}% certificates(s) ({2}%) of {3} for {4} SellSharesWithSwap=Sell {0} {1}% certificates(s) ({2}%) of {3} for {4}, swapping president for {5} {6}% certificate(s). diff --git a/rails/game/StockRound.java b/rails/game/StockRound.java index 4ee9c7b..3bbc525 100644 --- a/rails/game/StockRound.java +++ b/rails/game/StockRound.java @@ -353,8 +353,9 @@ public class StockRound extends Round { String compName; int price; int number; - int share, shareUnit, maxShareToSell; + int ownedShare, shareUnit, maxShareToSell; int dumpThreshold = 0; + int extraSingleShares = 0; boolean choiceOfPresidentExchangeCerts = false; Portfolio playerPortfolio = currentPlayer.getPortfolio(); @@ -367,7 +368,7 @@ public class StockRound extends Round { // Check if shares of this company can be sold at all if (!mayPlayerSellShareOfCompany(company)) continue; - share = maxShareToSell = playerPortfolio.getShare(company); + ownedShare = maxShareToSell = playerPortfolio.getShare(company); shareUnit = company.getShareUnit(); if (maxShareToSell == 0) continue; @@ -385,7 +386,7 @@ public class StockRound extends Round { if (company.getPresident() == currentPlayer) { int presidentShare = company.getCertificates().get(0).getShare(); - if (maxShareToSell > share - presidentShare) { + if (maxShareToSell > ownedShare - presidentShare) { int playerShare; // Check in correct player sequence, because we must also check // whether we must offer a choice for the Pres.cert exchange @@ -408,7 +409,7 @@ public class StockRound extends Round { dumpedPlayerShare = playerShare; // From what share sold are we dumping? - dumpThreshold = share - playerShare + shareUnit; + dumpThreshold = ownedShare - playerShare + shareUnit; // Check if the potential dumpee has a choice of return certs int[] uniqueCertsCount = player.getPortfolio().getCertificateTypeCountsPerCompany(company.getName(), false); @@ -416,10 +417,15 @@ public class StockRound extends Round { // and double shares for now. choiceOfPresidentExchangeCerts = uniqueCertsCount[1] > 1 && uniqueCertsCount[2] > 0; + // If a presidency dump is possible, extra (single) share(s) may be sold + // that aren't even owned + extraSingleShares = Math.min( + presidentShare/shareUnit, + (maxShareToSell-dumpThreshold)/shareUnit+1); } // What number of shares can we sell if we cannot dump? - if (dumpThreshold == 0) maxShareToSell = share - presidentShare; + if (dumpThreshold == 0) maxShareToSell = ownedShare - presidentShare; } } @@ -431,7 +437,7 @@ public class StockRound extends Round { */ // Take care for max. 4 share units per share compName = company.getName(); - int[] shareCountPerUnit = playerPortfolio.getCertificateTypeCountsPerCompany(compName, true); + int[] shareCountPerUnit = playerPortfolio.getCertificateTypeCountsPerCompany(compName, false); // Check the price. If a cert was sold before this turn, the original price is still valid. price = getCurrentSellPrice(company); @@ -440,6 +446,9 @@ public class StockRound extends Round { number = shareCountPerUnit[shareSize]; if (number == 0) continue; + // If you can dump a presidency, you may sell additional single shares that you don't own + if (shareSize == 1) number += extraSingleShares; + /* In some games (1856), a just bought share may not be sold */ // This code ignores the possibility of different share units if ((Boolean)gameManager.getGameParameter(GameDef.Parm.NO_SALE_OF_JUST_BOUGHT_CERT) @@ -448,18 +457,19 @@ public class StockRound extends Round { } if (number <= 0) continue; - // Check against the share% already in the pool - number = - Math.min(number, maxShareToSell - / (shareSize * company.getShareUnit())); + // Check against the maximum share that can be sold + number = Math.min(number, maxShareToSell / (shareSize * shareUnit)); if (number <= 0) continue; for (int i=1; i<=number; i++) { if (dumpThreshold > 0 && i*shareSize*shareUnit >= dumpThreshold && choiceOfPresidentExchangeCerts) { - // Also offer the alternative president exchange for a double share possibleActions.add(new SellShares(compName, shareSize, i, price, 1)); - possibleActions.add(new SellShares(compName, shareSize, i, price, 2)); + // Also offer the alternative president exchange for a double share, + // unless the remaining share would be less than a double share + if (ownedShare/shareUnit - i*shareSize >= 2) { + possibleActions.add(new SellShares(compName, shareSize, i, price, 2)); + } } else { possibleActions.add(new SellShares(compName, shareSize, i, price, 0)); } |