From: Michael A. <out...@gm...> - 2013-08-26 03:33:56
|
diff --git a/rails/game/specific/_1880/BuyStartItem_1880.java b/rails/game/specific/_1880/BuyStartItem_1880.java index b97d733..5036509 100644 --- a/rails/game/specific/_1880/BuyStartItem_1880.java +++ b/rails/game/specific/_1880/BuyStartItem_1880.java @@ -21,6 +21,8 @@ private BitSet buildingRights; private BitSet associatedBuildingRight; + + private int parSlotIndex = 0; /** * @param startItem * @param price @@ -167,5 +169,14 @@ } return "None"; } + + + public void setParSlotIndex(int index) { + parSlotIndex = index; + } + + public int getParSlotIndex() { + return parSlotIndex; + } } \ No newline at end of file diff --git a/rails/game/specific/_1880/GameManager_1880.java b/rails/game/specific/_1880/GameManager_1880.java index a8c5f37..c3ed260 100644 --- a/rails/game/specific/_1880/GameManager_1880.java +++ b/rails/game/specific/_1880/GameManager_1880.java @@ -31,6 +31,7 @@ public IntegerState numOfORs = new IntegerState("numOfORs"); //Keeps track of the company that purchased the last train private PublicCompany_1880 lastTrainBuyingCompany; + private ParSlots_1880 parSlots = new ParSlots_1880(); /** * */ @@ -142,5 +143,9 @@ super.finishShareSellingRound(); } + + public ParSlots_1880 getParSlots() { + return parSlots; + } } diff --git a/rails/game/specific/_1880/OperatingRound_1880.java b/rails/game/specific/_1880/OperatingRound_1880.java index f573a95..df1cb8f 100644 --- a/rails/game/specific/_1880/OperatingRound_1880.java +++ b/rails/game/specific/_1880/OperatingRound_1880.java @@ -509,30 +509,25 @@ @Override public List<PublicCompanyI> setOperatingCompanies() { Map<Integer, PublicCompanyI> operatingCompanies = new TreeMap<Integer, PublicCompanyI>(); - int space = 100; - int key; - int minorNo = 0; + int key = 1; + + // Put in Foreign Investors first for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { if (!canCompanyOperateThisRound(company)) continue; - if (! company.hasFloated()) continue; - // Key must put companies in reverse operating order, because sort - // is ascending. - if (company.hasStockPrice()) { - space = company.getStartSpace().getPrice(); - //Corps operate in descending Startprice - //Corps with the same Start price operate in the order they were floated - //Start price will inherently be in the right order - //subtracting the formation order index will put it at the right point to operate - //This wouldn't work if there are lots of corps at the same price - //there are not too many corps in each banding for this to be an issue in 1825 even with all 3 units - key = 1000000 - (space - ((PublicCompany_1880) company).getOperationSlotIndex()); - operatingCompanies.put(new Integer(key), company); - } - else { - key = 50 + ++minorNo; - operatingCompanies.put(new Integer(key), company); + if (!company.hasFloated()) continue; + if (!company.hasStockPrice()) { + operatingCompanies.put(new Integer(key++), company); } } + + // Now the share companies in par slot order + List<PublicCompanyI> companies = ((GameManager_1880) gameManager).getParSlots().getCompaniesInOperatingOrder(); + for (PublicCompanyI company : companies) { + if (!canCompanyOperateThisRound(company)) continue; + if (!company.hasFloated()) continue; + operatingCompanies.put(new Integer(key++), company); + } + return new ArrayList<PublicCompanyI>(operatingCompanies.values()); } diff --git a/rails/game/specific/_1880/ParSlot_1880.java b/rails/game/specific/_1880/ParSlot_1880.java new file mode 100644 index 0000000..6678235 --- /dev/null +++ b/rails/game/specific/_1880/ParSlot_1880.java @@ -0,0 +1,35 @@ +package rails.game.specific._1880; + +/** + * @author Michael Alexander + * + */ +import rails.game.PublicCompanyI; + +public class ParSlot_1880 { + private int index = -1; + private int price = -1; + private PublicCompanyI company = null; + + public ParSlot_1880(int index, int price) { + this.index = index; + this.price = price; + } + + public void setCompany(PublicCompanyI company) { + this.company = company; + } + + public int getIndex() { + return index; + } + + public int getPrice() { + return price; + } + + public PublicCompanyI getCompany() { + return company; + } + +} diff --git a/rails/game/specific/_1880/ParSlots_1880.java b/rails/game/specific/_1880/ParSlots_1880.java new file mode 100644 index 0000000..a7d54b4 --- /dev/null +++ b/rails/game/specific/_1880/ParSlots_1880.java @@ -0,0 +1,62 @@ +package rails.game.specific._1880; + +/** + * @author Michael Alexander + * + */ + +import java.util.ArrayList; +import java.util.List; + +import rails.game.PublicCompanyI; + +public class ParSlots_1880 { + + private List<ParSlot_1880> parSlots = new ArrayList<ParSlot_1880>(); + + public ParSlots_1880() { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + parSlots.add(new ParSlot_1880(i*4+j, 100-(10*i))); + } + } + } + + public List<ParSlot_1880> getEmptyParSlotsAtPrice(int price) { + List<ParSlot_1880> emptySlots = new ArrayList<ParSlot_1880>(); + for (ParSlot_1880 slot : parSlots) { + if ((slot.getCompany() == null) && (slot.getPrice() == price)) { + emptySlots.add(slot); + } + } + return emptySlots; + } + + public boolean freeSlotAtPrice(int price) { + for (ParSlot_1880 slot : parSlots) { + if ((slot.getCompany() == null) && (slot.getPrice() == price)) { + return true; + } + } + return false; + } + + public void setCompanyAtSlot(PublicCompanyI company, int index) { + for (ParSlot_1880 slot : parSlots) { + if (slot.getIndex() == index) { + slot.setCompany(company); + break; + } + } + } + + public List<PublicCompanyI> getCompaniesInOperatingOrder() { + List<PublicCompanyI> companies = new ArrayList<PublicCompanyI>(); + for (ParSlot_1880 slot : parSlots) { + if (slot.getCompany() != null) { + companies.add(slot.getCompany()); + } + } + return companies; + } +} diff --git a/rails/game/specific/_1880/PublicCompany_1880.java b/rails/game/specific/_1880/PublicCompany_1880.java index 0a85c62..da09f38 100644 --- a/rails/game/specific/_1880/PublicCompany_1880.java +++ b/rails/game/specific/_1880/PublicCompany_1880.java @@ -65,7 +65,6 @@ protected IntegerState operationSlotIndex = new IntegerState ("OperatingSlot, 0"); - /** * */ @@ -378,18 +377,5 @@ } } */ - /** - * @return the operationSlotIndex - */ - public int getOperationSlotIndex() { - return operationSlotIndex.intValue(); - } - - /** - * @param operationSlotIndex the operationSlotIndex to set - */ - public void setOperationSlotIndex(int operationSlotIndex) { - this.operationSlotIndex.add(operationSlotIndex); - } } diff --git a/rails/game/specific/_1880/StartCompany_1880.java b/rails/game/specific/_1880/StartCompany_1880.java index 7e02cc6..073d399 100644 --- a/rails/game/specific/_1880/StartCompany_1880.java +++ b/rails/game/specific/_1880/StartCompany_1880.java @@ -6,12 +6,12 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; +import java.util.Collections; import java.util.List; -import rails.game.CompanyManagerI; import rails.game.PublicCompanyI; -import rails.game.StockSpace; import rails.game.StockSpaceI; import rails.game.action.StartCompany; @@ -121,9 +121,9 @@ // TODO Auto-generated method stub // make sure that all exhausted price Slots will not be returned as valid prices anymore... startPrices2 = super.getStartPrices(); - for (int e =0 ; e< 4 ; e++) - { - if ( ((StockMarket_1880) gameManager.getStockMarket()).getParSlot(startPrices2[e])== true) //free slot found + for (int e = 0 ; e < startPrices2.length ; e++) + { + if (((GameManager_1880) gameManager).getParSlots().freeSlotAtPrice(startPrices2[e])) //free slot found { startPrices_new.add(startPrices2[e]); } @@ -133,6 +133,26 @@ startPrices2_new[i] = startPrices_new.get(i).intValue(); return startPrices2_new; } + + public List<ParSlot_1880> getStartParSlots() { + List<ParSlot_1880> startParSlots = new ArrayList<ParSlot_1880>(); + int []startPrices = super.getStartPrices(); + Integer []startPrices2 = new Integer[startPrices.length]; + ParSlots_1880 parSlots = ((GameManager_1880) gameManager).getParSlots(); + + for (int i = 0; i < startPrices.length ; i++) { + startPrices2[i] = startPrices[i]; + } + Arrays.sort(startPrices2, Collections.reverseOrder()); + + for (int i = 0; i < startPrices2.length ; i++) { + List<ParSlot_1880> emptySlotsAtThisPrice = parSlots.getEmptyParSlotsAtPrice(startPrices2[i]); + for (ParSlot_1880 slot : emptySlotsAtThisPrice) { + startParSlots.add(slot); + } + } + return startParSlots; + } /* (non-Javadoc) * @see rails.game.action.StartCompany#setStartPrice(int) @@ -140,7 +160,6 @@ public void setStartPrice(int startPrice, int index) { StockSpaceI parPrice=gameManager.getStockMarket().getStartSpace(startPrice); this.getCompany().setParSpace(parPrice); - ((StockMarket_1880) gameManager.getStockMarket()).setParSlot(index); } /** Deserialize */ @@ -191,8 +210,7 @@ return "None"; } - public void setOperatingSlot(int index) { - ((PublicCompany_1880) this.getCompany()).setOperationSlotIndex(index); - + public void setParSlotIndex(int index) { + ((GameManager_1880) gameManager).getParSlots().setCompanyAtSlot(this.getCompany(), index); } } diff --git a/rails/game/specific/_1880/StartRound_1880.java b/rails/game/specific/_1880/StartRound_1880.java index 69d5fd5..39055e9 100644 --- a/rails/game/specific/_1880/StartRound_1880.java +++ b/rails/game/specific/_1880/StartRound_1880.java @@ -4,6 +4,8 @@ package rails.game.specific._1880; import java.util.BitSet; +import java.util.List; +import java.util.Vector; import rails.common.DisplayBuffer; import rails.common.LocalText; @@ -41,6 +43,8 @@ /** A company in need for a par price. */ PublicCompanyI companyNeedingPrice = null; + + private final List<Player> playersPassed = new Vector<Player>(); /** @@ -83,6 +87,7 @@ if (currentItem == null || currentItem.get() != item ) { // we haven't seen this item before numPasses.set(0); // new round so cancel all previous passes ! playersActed.set(0); + playersPassed.clear(); currentItem.set(item); item.setStatus(StartItem.BIDDABLE); item.setStatus(StartItem.BUYABLE); @@ -138,6 +143,7 @@ // Can't bid: Autopass numPasses.add(1); playersActed.add(1); + playersPassed.add(currentPlayer); return false; } } else { // Item is not a private ! should be a major or minor in 1880 special rules apply. @@ -262,6 +268,7 @@ auctionItemState.set(null); numPasses.set(0); playersActed.set(0); + playersPassed.clear(); setNextStartingPlayer(); return true; } else { @@ -303,6 +310,7 @@ numPasses.add(1); playersActed.add(1); + playersPassed.add(player); if (numPasses.intValue() >= numPlayers) { // All players have passed. @@ -318,6 +326,7 @@ Bank.format(startPacket.getFirstItem().getBasePrice()) )); numPasses.set(0); playersActed.set(0); + playersPassed.clear(); if (auctionItem.getBasePrice() == 0) { assignItem((Player)startingPlayer.get(), auctionItem, 0, 0); @@ -327,6 +336,7 @@ } else { numPasses.set(0); playersActed.set(0); + playersPassed.clear(); finishRound(); } @@ -346,6 +356,7 @@ auctionItemState.set(null); numPasses.set(0); playersActed.set(0); + playersPassed.clear(); setNextStartingPlayer(); return true; } else { @@ -371,26 +382,11 @@ } private void setNextBiddingPlayer(StartItem item, int currentIndex) { - boolean bidState = false; for (int i = currentIndex + 1; i < currentIndex + gameManager.getNumberOfPlayers(); i++) { - /* - * Ok we need to make sure that every one has at least the chance to bid once. - * We need to make sure that everyone that has passed cant bid again. - * Unfortunately getBid() or hasBid() return 0 so they cant be of use here until the second bidding round ! - * Now we only need a status indicator how many people have acted already.... - */ - if (playersActed.intValue() == numPlayers) { - bidState = item.hasBid(gameManager.getPlayerByIndex(i)); - if (bidState == true) { - setCurrentPlayerIndex(i); - break; - } else { - continue; - } - } else { - setCurrentPlayerIndex(i); - break; + if (playersPassed.contains(gameManager.getPlayerByIndex(i)) == false) { + setCurrentPlayerIndex(i); + break; } } } @@ -479,6 +475,7 @@ int sharePrice = 0; String shareCompName = ""; BitSet buildingRights = new BitSet(5); + int parSlotIndex = 0; BuyStartItem_1880 boughtItem_1880 = (BuyStartItem_1880) boughtItem; while (true) { @@ -503,6 +500,7 @@ shareCompName = boughtItem_1880.getCompanyToSetPriceFor(); sharePrice = boughtItem_1880.getAssociatedSharePrice(); buildingRights = boughtItem_1880.getAssociatedBuildingRight(); + parSlotIndex = boughtItem_1880.getParSlotIndex(); if (sharePrice == 0) { errMsg = @@ -522,6 +520,7 @@ shareCompName ); break; } + // TODO: Add check for ParSlot validity } break; } @@ -536,14 +535,22 @@ moveStack.start(false); - assignItem(player, item, price, sharePrice, buildingRights); + assignItem(player, item, price, sharePrice, buildingRights, parSlotIndex); // Set priority (only if the item was not auctioned) // ASSUMPTION: getting an item in auction mode never changes priority if (lastBid == 0) { gameManager.setPriorityPlayer(); } - setNextPlayer(); + + // If this item is the "IG" (BCR), then we are still in the "auction" portion + // of the stock round, and the next player is based on the current player + // (not the current player). + if (item == StartItem.getByName("IG")) { + setCurrentPlayerIndex(((Player) startingPlayer.get()).getIndex()); + } else { + setNextPlayer(); + } auctionItemState.set(null); numPasses.set(0); @@ -559,7 +566,7 @@ * @param buildingRights */ private void assignItem(Player player, StartItem item, int price, - int sharePrice, BitSet buildingRights) { + int sharePrice, BitSet buildingRights, int parSlotIndex) { Certificate primary = item.getPrimary(); ReportBuffer.add(LocalText.getText("BuysItemFor", player.getName(), @@ -567,14 +574,14 @@ Bank.format(price) )); pay (player, bank, price); transferCertificate (primary, player.getPortfolio()); - checksOnBuying(primary, sharePrice, buildingRights); + checksOnBuying(primary, sharePrice, buildingRights, parSlotIndex); if (item.hasSecondary()) { Certificate extra = item.getSecondary(); ReportBuffer.add(LocalText.getText("ALSO_GETS", player.getName(), extra.getName() )); transferCertificate (extra, player.getPortfolio()); - checksOnBuying(extra, sharePrice, buildingRights); + checksOnBuying(extra, sharePrice, buildingRights, parSlotIndex); } item.setSold(player, price); @@ -585,7 +592,7 @@ * @param buildingRights */ private void checksOnBuying(Certificate cert, int sharePrice, - BitSet buildingRights) { + BitSet buildingRights, int parSlot) { if (cert instanceof PublicCertificateI) { PublicCertificateI pubCert = (PublicCertificateI) cert; PublicCompany_1880 comp = (PublicCompany_1880) pubCert.getCompany(); @@ -600,6 +607,7 @@ comp.start(sharePrice); //Building Rights are also set.. comp.setBuildingRights(buildingRights); + ((GameManager_1880) gameManager).getParSlots().setCompanyAtSlot(comp, parSlot); comp.setRight("BuildingRight",buildingRightToString(buildingRights)); } else { log.error("No start price for " + comp.getName()); diff --git a/rails/game/specific/_1880/StockMarket_1880.java b/rails/game/specific/_1880/StockMarket_1880.java index 91a2304..5a311c1 100644 --- a/rails/game/specific/_1880/StockMarket_1880.java +++ b/rails/game/specific/_1880/StockMarket_1880.java @@ -29,11 +29,7 @@ public IntegerState parPlace_80; public IntegerState parPlace_70; - - protected int parSlots[]= new int [16]; - - private int freeParSlots [] = new int [16]; - + GameManagerI gameManager; /** @@ -171,115 +167,5 @@ comp.getStartSpace().addFixedStartPrice(comp); } } - } - - /** - * @return all free parSlots - */ - public int[] getParSlots() { - - int i = 0; - for (int e: parSlots ) - { - if (parSlots[e] == 0) - { - freeParSlots[i] = e+1; - i++; - } - } - return freeParSlots; - } - - public int [] getParSlots(int price){ - int [] freeParSlotsPerPrice= new int [4]; - int i =0; - switch (price) { - case 70: - for (int e=0 ; e< 4; e++ ) - { - if ( parSlots[e] == 0) - freeParSlotsPerPrice[e] =e+1; - } - - break; - case 80: - for (int e=4 ; e< 8; e++ ) - { - if ( parSlots[e] == 0) { - i = e % 4; - freeParSlotsPerPrice[i] =e+1; - } - } - break; - case 90: - for (int e=8 ; e< 12; e++ ) - { - if ( parSlots[e] == 0) - { - i = e % 4; - freeParSlotsPerPrice[i] =e+1; - } - } - break; - case 100: - for (int e=12 ; e< 16; e++ ) - { - if ( parSlots[e] == 0){ - i = e % 4; - freeParSlotsPerPrice[i] =e+1; - } - } - default: - return freeParSlotsPerPrice; - } - return freeParSlotsPerPrice; - } - /** - * @param parSlots the parSlots to set - */ - public void setParSlots(int[] parSlots) { - this.parSlots = parSlots; - } - - public boolean setParSlot(int position) { - - if (this.parSlots[position] > 0) { - return false; - } else { - this.parSlots[position] = 1; - return true; - } - } - - public boolean getParSlot(int price) { - switch (price) { - case 70: - for (int e=0 ; e< 4; e++ ) - if ( parSlots[e] == 0) - return true; - break; - case 80: - for (int e=4 ; e< 8; e++ ) - if ( parSlots[e] == 0) - return true; - break; - case 90: - for (int e=8 ; e< 12; e++ ) - if ( parSlots[e] == 0) - return true; - break; - case 100: - for (int e=12 ; e< 16; e++ ) - if ( parSlots[e] == 0) - return true; - break; - default: - return false; - } - return false; - } - - public boolean getParSlot(int price, int position) { - return true; } } diff --git a/rails/game/specific/_1880/StockRound_1880.java b/rails/game/specific/_1880/StockRound_1880.java index 8ed6669..be75bd4 100644 --- a/rails/game/specific/_1880/StockRound_1880.java +++ b/rails/game/specific/_1880/StockRound_1880.java @@ -274,7 +274,7 @@ } else if (!comp.hasStarted()) { List<Integer> startPrices = new ArrayList<Integer>(); for (int startPrice : stockMarket.getStartPrices()) { - if ((startPrice * shares <= playerCash) && (((StockMarket_1880) gameManager.getStockMarket()).getParSlot(startPrice))) { + if ((startPrice * shares <= playerCash) && (((GameManager_1880) gameManager).getParSlots().freeSlotAtPrice(startPrice))) { startPrices.add(startPrice); } } |