From: <ste...@us...> - 2010-08-12 20:58:12
|
Revision: 1381 http://rails.svn.sourceforge.net/rails/?rev=1381&view=rev Author: stefanfrey Date: 2010-08-12 20:58:05 +0000 (Thu, 12 Aug 2010) Log Message: ----------- Fixed and updated implementation of blocked token lays Modified Paths: -------------- trunk/18xx/data/1830/CompanyManager.xml trunk/18xx/rails/game/GameManager.java trunk/18xx/rails/game/MapHex.java Modified: trunk/18xx/data/1830/CompanyManager.xml =================================================================== --- trunk/18xx/data/1830/CompanyManager.xml 2010-08-12 18:46:08 UTC (rev 1380) +++ trunk/18xx/data/1830/CompanyManager.xml 2010-08-12 20:58:05 UTC (rev 1381) @@ -89,7 +89,7 @@ longname="Erie Railroad"> <!-- city = 0 implies that this is not yet decided (OO-tiles), blocks means that in each city one slot has to be available --> - <Home hex="E11" city="0" AllCitiesBlocked="yes"/> + <Home hex="E11" city="0" allCitiesBlocked="yes"/> </Company> <Company name="B&M" type="Public" tokens="2" fgColour="000000" bgColour="60E060" longname="Boston & Maine"> @@ -106,7 +106,7 @@ <IfOption name="Variant" value="Pere Marquette"> <Company name="PM" type="Public" tokens="3" fgColour="FFFF00" bgColour="000080" longname="Pere Marquette"> - <Home hex="E5" city="0" AllCitiesBlocked="yes" /> + <Home hex="E5" city="0" allCitiesBlocked="yes" /> </Company> </IfOption> <StartPacket roundClass="rails.game.StartRound_1830"> Modified: trunk/18xx/rails/game/GameManager.java =================================================================== --- trunk/18xx/rails/game/GameManager.java 2010-08-12 18:46:08 UTC (rev 1380) +++ trunk/18xx/rails/game/GameManager.java 2010-08-12 20:58:05 UTC (rev 1381) @@ -879,14 +879,14 @@ result = save(gameAction); break; case GameAction.UNDO: - moveStack.undoMoveSet(true); + moveStack.undoMoveSet(false); result = true; break; case GameAction.FORCED_UNDO: if (index != -1) { moveStack.gotoIndex(index); } else { - moveStack.undoMoveSet(false); + moveStack.undoMoveSet(true); } result = true; break; Modified: trunk/18xx/rails/game/MapHex.java =================================================================== --- trunk/18xx/rails/game/MapHex.java 2010-08-12 18:46:08 UTC (rev 1380) +++ trunk/18xx/rails/game/MapHex.java 2010-08-12 20:58:05 UTC (rev 1381) @@ -1047,26 +1047,44 @@ // Return MapHex attribute if defined return isBlockedForTokenLays.booleanValue(); } else if (homes != null && !homes.isEmpty()) { - // Check if this token lay does not block an unlaid home base + City cityToLay = this.getCity(cityNumber); + if (cityToLay == null) { // city does not exist, this does not block itself + return false; + } + // check if the city is potential home for other companies + int allBlockCompanies = 0; + int anyBlockCompanies = 0; + int cityBlockCompanies = 0; for (PublicCompanyI comp : homes.keySet()) { if (comp.hasLaidHomeBaseTokens() || comp.isClosed()) continue; - // home base not laid yet, define list of cities to check - List<City> citiesToCheck = new ArrayList<City>(); + // home base not laid yet City homeCity = homes.get(comp); - if (homeCity != null) { - citiesToCheck.add(homeCity); + if (homeCity == null) { + if (comp.isHomeBlockedForAllCities()) { + allBlockCompanies ++; // undecided companies that block all cities + } else { + anyBlockCompanies ++; // undecided companies that block any cities + } + } else if (cityToLay == homeCity) { + cityBlockCompanies ++; // companies which are located in the city in question } else { - citiesToCheck.addAll(cities); + anyBlockCompanies ++; // companies which are located somewhere else } - int tokenSlotsLeft = 0; - for (City city:cities) { - tokenSlotsLeft += city.getTokenSlotsLeft(); - if (comp.isHomeBlockedForAllCities() & city.getTokenSlotsLeft() < 2) { - return true; - } - } - if (tokenSlotsLeft < 2) return true; // not enough tokens left, assume only one company } + log.debug("IsBlockedForTokenLays: allBlockCompanies = " + allBlockCompanies + + ", anyBlockCompanies = " + anyBlockCompanies + " , cityBlockCompanies = " + cityBlockCompanies); + // check if there are sufficient individual city slots + if (allBlockCompanies + cityBlockCompanies + 1 > cityToLay.getTokenSlotsLeft()) { + return true; // the additional token exceeds the number of available slots + } + // check if the overall hex slots are sufficient + int allTokenSlotsLeft = 0; + for (City city:cities) { + allTokenSlotsLeft += city.getTokenSlotsLeft(); + } + if (allBlockCompanies + anyBlockCompanies + cityBlockCompanies + 1 > allTokenSlotsLeft) { + return true; // all located companies plus the additonal token exceeds the available slots + } } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |