You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(46) |
Dec
(57) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(51) |
Feb
(10) |
Mar
|
Apr
|
May
(14) |
Jun
|
Jul
(13) |
Aug
(30) |
Sep
(83) |
Oct
(56) |
Nov
(148) |
Dec
(107) |
2010 |
Jan
(260) |
Feb
(164) |
Mar
(183) |
Apr
(99) |
May
(160) |
Jun
(40) |
Jul
(33) |
Aug
(48) |
Sep
(22) |
Oct
(24) |
Nov
(1) |
Dec
(12) |
2011 |
Jan
(6) |
Feb
(15) |
Mar
(13) |
Apr
(37) |
May
(27) |
Jun
(29) |
Jul
(33) |
Aug
(20) |
Sep
(17) |
Oct
(20) |
Nov
(33) |
Dec
(17) |
2012 |
Jan
(39) |
Feb
(38) |
Mar
(20) |
Apr
(21) |
May
(17) |
Jun
(22) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(10) |
Nov
|
Dec
|
From: Stefan F. <ste...@us...> - 2010-05-23 18:10:52
|
Update of /cvsroot/rails/18xx/data/18AL In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23967/data/18AL Modified Files: Game.xml Log Message: Minor refactoring of RevenueManager and added NetworkGraphModifier and BirminghamTileModifier for 1851 Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/18AL/Game.xml,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Game.xml 20 May 2010 19:57:01 -0000 1.30 --- Game.xml 23 May 2010 18:10:44 -0000 1.31 *************** *** 105,109 **** </Component> <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> ! <StaticModifier class="rails.game.specific._18AL.NamedTrainRevenueModifier" /> </Component> </ComponentManager> \ No newline at end of file --- 105,109 ---- </Component> <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> ! <Modifier class="rails.game.specific._18AL.NamedTrainRevenueModifier" /> </Component> </ComponentManager> \ No newline at end of file |
From: Stefan F. <ste...@us...> - 2010-05-23 18:10:52
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23967/rails/algorithms Modified Files: RevenueManager.java NetworkVertex.java Added Files: NetworkGraphModifier.java Log Message: Minor refactoring of RevenueManager and added NetworkGraphModifier and BirminghamTileModifier for 1851 Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** NetworkVertex.java 21 May 2010 16:15:24 -0000 1.15 --- NetworkVertex.java 23 May 2010 18:10:44 -0000 1.16 *************** *** 394,397 **** --- 394,410 ---- } + /** + * Returns all vertices for a specified hex + */ + public static Set<NetworkVertex> getVerticesByHex(Collection<NetworkVertex> vertices, MapHex hex) { + Set<NetworkVertex> hexVertices = new HashSet<NetworkVertex>(); + for (NetworkVertex vertex:vertices) { + if (vertex.getHex() != null && hex == vertex.getHex()) { + hexVertices.add(vertex); + } + } + return hexVertices; + } + public static NetworkVertex getVertexByIdentifier(Collection<NetworkVertex> vertices, String identifier) { for (NetworkVertex vertex:vertices) { Index: RevenueManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RevenueManager.java 20 May 2010 23:13:21 -0000 1.3 --- RevenueManager.java 23 May 2010 18:10:44 -0000 1.4 *************** *** 29,44 **** Logger.getLogger(RevenueManager.class.getPackage().getName()); ! private Set<RevenueStaticModifier> staticModifiers; ! private Set<RevenueDynamicModifier> dynamicModifiers; public RevenueManager() { staticModifiers = new HashSet<RevenueStaticModifier>(); ! dynamicModifiers = new HashSet<RevenueDynamicModifier>(); } public void configureFromXML(Tag tag) throws ConfigurationException { ! // define static modifiers ! List<Tag> modifierTags = tag.getChildren("StaticModifier"); if (modifierTags != null) { --- 29,49 ---- Logger.getLogger(RevenueManager.class.getPackage().getName()); ! ! private final Set<NetworkGraphModifier> graphModifiers; ! private final Set<RevenueStaticModifier> staticModifiers; ! private final Set<RevenueDynamicModifier> dynamicModifiers; ! private final Set<ConfigurableComponentI> configurableModifiers; public RevenueManager() { + graphModifiers = new HashSet<NetworkGraphModifier>(); staticModifiers = new HashSet<RevenueStaticModifier>(); ! dynamicModifiers = new HashSet<RevenueDynamicModifier>(); ! configurableModifiers = new HashSet<ConfigurableComponentI>(); } public void configureFromXML(Tag tag) throws ConfigurationException { ! // define modifiers ! List<Tag> modifierTags = tag.getChildren("Modifier"); if (modifierTags != null) { *************** *** 48,55 **** if (className == null) { throw new ConfigurationException(LocalText.getText( ! "ComponentHasNoClass", "StaticModifier")); } // create modifier ! RevenueStaticModifier modifier; try { modifier = (RevenueStaticModifier) Class.forName(className).newInstance(); --- 53,60 ---- if (className == null) { throw new ConfigurationException(LocalText.getText( ! "ComponentHasNoClass", "Modifier")); } // create modifier ! Object modifier; try { modifier = (RevenueStaticModifier) Class.forName(className).newInstance(); *************** *** 58,99 **** "ClassCannotBeInstantiated", className), e); } // add them to the revenueManager ! staticModifiers.add(modifier); ! log.info("Added modifier " + className); ! } ! } ! ! // define dynamic modifiers ! modifierTags = tag.getChildren("DynamicModifier"); ! ! if (modifierTags != null) { ! for (Tag modifierTag:modifierTags) { ! // get classname ! String className = modifierTag.getAttributeAsString("class"); ! if (className == null) { ! throw new ConfigurationException(LocalText.getText( ! "ComponentHasNoClass", "DynamicModifier")); } ! // create modifier ! RevenueDynamicModifier modifier; ! try { ! modifier = (RevenueDynamicModifier) Class.forName(className).newInstance(); ! } catch (Exception e) { throw new ConfigurationException(LocalText.getText( ! "ClassCannotBeInstantiated", className), e); } - // add them to the revenueManager - dynamicModifiers.add(modifier); - log.info("Added modifier " + className); } } } public void finishConfiguration(GameManagerI parent) throws ConfigurationException { ! for (RevenueStaticModifier modifier:staticModifiers) { ! if (modifier instanceof ConfigurableComponentI) { ! ((ConfigurableComponentI)modifier).finishConfiguration(parent); ! } } } --- 63,99 ---- "ClassCannotBeInstantiated", className), e); } + boolean isModifier = false; // add them to the revenueManager ! if (modifier instanceof NetworkGraphModifier) { ! graphModifiers.add((NetworkGraphModifier)modifier); ! isModifier = true; ! log.info("Added as graph modifier = " + className); } ! if (modifier instanceof RevenueStaticModifier) { ! staticModifiers.add((RevenueStaticModifier)modifier); ! isModifier = true; ! log.info("Added as static modifier = " + className); ! } ! if (modifier instanceof RevenueDynamicModifier) { ! dynamicModifiers.add((RevenueDynamicModifier)modifier); ! isModifier = true; ! log.info("Added as dynamic modifier = " + className); ! } ! if (!isModifier) { throw new ConfigurationException(LocalText.getText( ! "ClassIsNotAModifier", className)); ! } ! if (isModifier && modifier instanceof ConfigurableComponentI) { ! configurableModifiers.add((ConfigurableComponentI)modifier); } } } + } public void finishConfiguration(GameManagerI parent) throws ConfigurationException { ! for (ConfigurableComponentI modifier:configurableModifiers) { ! modifier.finishConfiguration(parent); } } *************** *** 101,105 **** public void addStaticModifier(RevenueStaticModifier modifier) { staticModifiers.add(modifier); ! log.info("Revenue Manager: Added modifier " + modifier); } --- 101,105 ---- public void addStaticModifier(RevenueStaticModifier modifier) { staticModifiers.add(modifier); ! log.info("Revenue Manager: Added static modifier " + modifier); } *************** *** 107,111 **** boolean result = staticModifiers.remove(modifier); if (result) { ! log.info("RevenueManager: Removed modifier " + modifier); } else { log.info("RevenueManager: Cannot remove" + modifier); --- 107,111 ---- boolean result = staticModifiers.remove(modifier); if (result) { ! log.info("RevenueManager: Removed static modifier " + modifier); } else { log.info("RevenueManager: Cannot remove" + modifier); *************** *** 114,123 **** } ! Set<RevenueStaticModifier> getStaticModifiers() { ! return staticModifiers; } ! Set<RevenueDynamicModifier> getDynamicModifiers() { ! return dynamicModifiers; } --- 114,151 ---- } ! public void addGraphModifier(NetworkGraphModifier modifier) { ! graphModifiers.add(modifier); ! log.info("Revenue Manager: Added graph modifier " + modifier); ! } ! ! public boolean removeGraphModifier(NetworkGraphModifier modifier) { ! boolean result = graphModifiers.remove(modifier); ! if (result) { ! log.info("RevenueManager: Removed graph modifier " + modifier); ! } else { ! log.info("RevenueManager: Cannot remove" + modifier); ! } ! return result; } ! public void addDynamicModifier(RevenueDynamicModifier modifier) { ! dynamicModifiers.add(modifier); ! log.info("Revenue Manager: Added dynamic modifier " + modifier); ! } ! ! public boolean removeDynamicModifier(RevenueDynamicModifier modifier) { ! boolean result = dynamicModifiers.remove(modifier); ! if (result) { ! log.info("RevenueManager: Removed dynamic modifier " + modifier); ! } else { ! log.info("RevenueManager: Cannot remove" + modifier); ! } ! return result; ! } ! ! void callGraphModifiers(NetworkGraphBuilder graphBuilder) { ! for (NetworkGraphModifier modifier:graphModifiers) { ! modifier.modifyGraph(graphBuilder); ! } } --- NEW FILE: NetworkGraphModifier.java --- package rails.algorithms; /** * Classes that change properties of the network graph * before both route evaluation and revenenue calculation starts * implement this interface. * * They have to register themselves to the RevenueManager via the GameManager instance. * @author freystef * */ public interface NetworkGraphModifier { public void modifyGraph(NetworkGraphBuilder graphBuilder); } |
From: Stefan F. <ste...@us...> - 2010-05-23 18:10:52
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1851 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23967/rails/game/specific/_1851 Added Files: BirminghamTileModifier.java Log Message: Minor refactoring of RevenueManager and added NetworkGraphModifier and BirminghamTileModifier for 1851 --- NEW FILE: BirminghamTileModifier.java --- package rails.game.specific._1851; import java.util.Set; import org.jgrapht.graph.SimpleGraph; import rails.algorithms.NetworkEdge; import rails.algorithms.NetworkGraphBuilder; import rails.algorithms.NetworkGraphModifier; import rails.algorithms.NetworkVertex; import rails.game.GameManager; import rails.game.GameManagerI; import rails.game.MapHex; public class BirminghamTileModifier implements NetworkGraphModifier { public void modifyGraph(NetworkGraphBuilder graphBuilder) { GameManagerI gm = GameManager.getInstance(); SimpleGraph<NetworkVertex, NetworkEdge> graph = graphBuilder.getMapGraph(); // 1. check Phase // this is a violation of the assumption that the track network only dependents on the map configuration // but not on other things (like phases) if (gm.getCurrentPhase().getIndex() >= 2 ) return; // 2. retrieve Birmingham vertices ... MapHex birmingHex = gm.getMapManager().getHex("J12"); Set<NetworkVertex> birmingVertices = NetworkVertex.getVerticesByHex(graph.vertexSet(), birmingHex); // 3 ... and remove them from the graph graph.removeAllVertices(birmingVertices); } } |
From: Erik V. <ev...@us...> - 2010-05-23 08:18:32
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23595/rails/game/specific/_18EU Modified Files: OperatingRound_18EU.java Log Message: 18EU bankruptcy rules (Phase 2) Index: OperatingRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OperatingRound_18EU.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** OperatingRound_18EU.java 15 May 2010 16:36:09 -0000 1.15 --- OperatingRound_18EU.java 23 May 2010 08:18:24 -0000 1.16 *************** *** 127,131 **** // Sort out which players preside over wich companies. for (PublicCompanyI c : operatingCompanies) { ! if (c == operatingCompany) continue; p = c.getPresident(); index = p.getIndex(); --- 127,131 ---- // Sort out which players preside over wich companies. for (PublicCompanyI c : operatingCompanies) { ! if (c == operatingCompany || c.isClosed()) continue; p = c.getPresident(); index = p.getIndex(); *************** *** 237,239 **** --- 237,249 ---- } + @Override + public void resume() { + if (getCurrentPlayer().isBankrupt()) { + // Do not complete the train buying action + savedAction = null; + finishTurn(); + } + super.resume(); + } + } |
From: Erik V. <ev...@us...> - 2010-05-23 08:18:32
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23595/rails/game Modified Files: ShareSellingRound.java OperatingRound.java Log Message: 18EU bankruptcy rules (Phase 2) Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.132 retrieving revision 1.133 diff -C2 -d -r1.132 -r1.133 *** OperatingRound.java 18 May 2010 22:07:18 -0000 1.132 --- OperatingRound.java 23 May 2010 08:18:24 -0000 1.133 *************** *** 1469,1480 **** protected void finishTurn() { ! operatingCompany.setOperated(); ! companiesOperatedThisRound.add(operatingCompany); ! ! // Check if any privates must be closed (now only applies to 1856 W&SR) ! // Copy list first to avoid concurrent modifications ! for (PrivateCompanyI priv : ! new ArrayList<PrivateCompanyI> (operatingCompany.getPortfolio().getPrivateCompanies())) { ! priv.checkClosingIfExercised(true); } --- 1469,1482 ---- protected void finishTurn() { ! if (!operatingCompany.isClosed()) { ! operatingCompany.setOperated(); ! companiesOperatedThisRound.add(operatingCompany); ! ! // Check if any privates must be closed (now only applies to 1856 W&SR) ! // Copy list first to avoid concurrent modifications ! for (PrivateCompanyI priv : ! new ArrayList<PrivateCompanyI> (operatingCompany.getPortfolio().getPrivateCompanies())) { ! priv.checkClosingIfExercised(true); ! } } Index: ShareSellingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ShareSellingRound.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ShareSellingRound.java 18 May 2010 22:07:18 -0000 1.32 --- ShareSellingRound.java 23 May 2010 08:18:24 -0000 1.33 *************** *** 23,26 **** --- 23,28 ---- IntegerState cashToRaise; PublicCompanyI unsellableCompany = null; + + private List<SellShares> sellableShares; /** *************** *** 54,58 **** this.unsellableCompany = unsellableCompany; setCurrentPlayerIndex(sellingPlayer.getIndex()); ! setPossibleActions(); } --- 56,60 ---- this.unsellableCompany = unsellableCompany; setCurrentPlayerIndex(sellingPlayer.getIndex()); ! getSellableShares(); } *************** *** 74,85 **** setSellableShares(); - if (possibleActions.isEmpty() && cashToRaise.intValue() > 0) { - DisplayBuffer.add(LocalText.getText("YouMustRaiseCashButCannot", - Bank.format(cashToRaise.intValue()))); - - gameManager.registerBankruptcy(); - if (gameManager.isGameOver()) return false; - } - for (PossibleAction pa : possibleActions.getList()) { log.debug(currentPlayer.getName() + " may: " + pa.toString()); --- 76,79 ---- *************** *** 89,100 **** } - /** - * Create a list of certificates that a player may sell in a Stock Round, - * taking all rules taken into account. - * - * @return List of sellable certificates. - */ @Override public void setSellableShares() { String compName; int price; --- 83,99 ---- } @Override public void setSellableShares() { + possibleActions.addAll(sellableShares); + } + + /** + * Create a list of certificates that a player may sell in an emergency + * share selling round, taking all rules taken into account. + */ + private List<SellShares> getSellableShares () { + + sellableShares = new ArrayList<SellShares> (); + String compName; int price; *************** *** 192,200 **** if (number > 0) { ! possibleActions.add(new SellShares(compName, i, number, price)); } } } } --- 191,200 ---- if (number > 0) { ! sellableShares.add(new SellShares(compName, i, number, price)); } } } + return sellableShares; } *************** *** 380,383 **** --- 380,388 ---- if (cashToRaise.intValue() <= 0) { gameManager.finishShareSellingRound(); + } else if (getSellableShares().isEmpty()) { + DisplayBuffer.add(LocalText.getText("YouMustRaiseCashButCannot", + Bank.format(cashToRaise.intValue()))); + + gameManager.registerBankruptcy(); } |
From: Stefan F. <ste...@us...> - 2010-05-22 18:42:36
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7661/rails/algorithms Modified Files: RevenueAdapter.java NetworkGraphBuilder.java Log Message: Some minor refactoring Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** RevenueAdapter.java 21 May 2010 07:36:10 -0000 1.19 --- RevenueAdapter.java 22 May 2010 18:42:26 -0000 1.20 *************** *** 19,22 **** --- 19,23 ---- import rails.game.GameManagerI; import rails.game.MapHex; + import rails.game.MapManager; import rails.game.PhaseI; import rails.game.PublicCompanyI; *************** *** 80,83 **** --- 81,94 ---- } + public static RevenueAdapter createRevenueAdapter(GameManagerI gm, PublicCompanyI company, PhaseI phase) { + MapManager mapManager = gm.getMapManager(); + NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); + nwGraph.generateGraph(mapManager.getHexesAsList()); + RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, phase); + ra.populateFromRails(); + return ra; + } + + public PublicCompanyI getCompany() { return company; Index: NetworkGraphBuilder.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkGraphBuilder.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** NetworkGraphBuilder.java 20 May 2010 19:57:01 -0000 1.11 --- NetworkGraphBuilder.java 22 May 2010 18:42:26 -0000 1.12 *************** *** 99,103 **** } else { mapGraph.addEdge(startVertex, endVertex, edge); ! log.info("Added edge " + edge.getConnection()); } } --- 99,103 ---- } else { mapGraph.addEdge(startVertex, endVertex, edge); ! log.info("Added non-greedy edge " + edge.getConnection()); } } *************** *** 143,147 **** mapGraph.addEdge(vertex, otherVertex, edge); ! log.info("Added edge " + edge.getConnection()); } } --- 143,147 ---- mapGraph.addEdge(vertex, otherVertex, edge); ! log.info("Added greedy edge " + edge.getConnection()); } } *************** *** 286,289 **** --- 286,290 ---- target.isSide() && graph.edgesOf(target).size() == 2 || target.isStation()) { edge.setGreedy(true); + log.info("Increased greedness for " + edge.getConnection()); } } *************** *** 302,307 **** Set<NetworkEdge> vertexEdges = graph.edgesOf(vertex); ! // remove singletons if (vertexEdges.size() == 0) { graph.removeVertex(vertex); removed = true; --- 303,309 ---- Set<NetworkEdge> vertexEdges = graph.edgesOf(vertex); ! // remove hermit if (vertexEdges.size() == 0) { + log.info("Remove hermit (no connection) = " + vertex); graph.removeVertex(vertex); removed = true; *************** *** 313,316 **** --- 315,319 ---- if (vertexEdges.size() == 1) { + log.info("Remove deadend side (single connection) = " + vertex); graph.removeVertex(vertex); removed = true; *************** *** 321,324 **** --- 324,328 ---- if (edges[0].isGreedy() == edges[1].isGreedy()) { if (!edges[0].isGreedy()) { + log.info("Remove deadend side (no greedy connection) = " + vertex); // two non greedy edges indicate a deadend graph.removeVertex(vertex); |
From: Stefan F. <ste...@us...> - 2010-05-22 18:42:34
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7661/rails/ui/swing Modified Files: ORPanel.java Log Message: Some minor refactoring Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ORPanel.java 20 May 2010 23:13:21 -0000 1.65 --- ORPanel.java 22 May 2010 18:42:26 -0000 1.66 *************** *** 591,599 **** MapManager mapManager = gm.getMapManager(); - NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); - nwGraph.generateGraph(mapManager.getHexesAsList()); - SimpleGraph<NetworkVertex, NetworkEdge> mapGraph = nwGraph.getMapGraph(); - if (companyName.equals("All")) { NetworkGraphBuilder.visualize(mapGraph, "Map Network"); mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); --- 591,599 ---- MapManager mapManager = gm.getMapManager(); if (companyName.equals("All")) { + NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); + nwGraph.generateGraph(mapManager.getHexesAsList()); + SimpleGraph<NetworkVertex, NetworkEdge> mapGraph = nwGraph.getMapGraph(); + NetworkGraphBuilder.visualize(mapGraph, "Map Network"); mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); *************** *** 606,611 **** RevenueAdapter ra = null; while (anotherTrain) { ! ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); for (String addTrain:addTrainList) { ra.addTrainByString(addTrain); --- 606,610 ---- RevenueAdapter ra = null; while (anotherTrain) { ! ra = RevenueAdapter.createRevenueAdapter(gm, company, gm.getCurrentPhase()); for (String addTrain:addTrainList) { ra.addTrainByString(addTrain); *************** *** 785,799 **** private RevenueAdapter initRevenueCalculation(PublicCompanyI company){ - GameManagerI gm = orUIManager.getGameUIManager().getGameManager(); ! MapManager mapManager = gm.getMapManager(); ! ! NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); ! nwGraph.generateGraph(mapManager.getHexesAsList()); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); ra.initRevenueCalculator(); ra.addRevenueListener(this); - return ra; } --- 784,791 ---- private RevenueAdapter initRevenueCalculation(PublicCompanyI company){ GameManagerI gm = orUIManager.getGameUIManager().getGameManager(); ! RevenueAdapter ra = RevenueAdapter.createRevenueAdapter(gm, company, gm.getCurrentPhase()); ra.initRevenueCalculator(); ra.addRevenueListener(this); return ra; } |
From: Stefan F. <ste...@us...> - 2010-05-21 16:30:40
|
Update of /cvsroot/rails/18xx/data/1851 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv16169/data/1851 Modified Files: Game.xml Log Message: 1851 revenue calculation support and removed configuration interface from offboard modifiers Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1851/Game.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Game.xml 21 Apr 2010 21:30:40 -0000 1.14 --- Game.xml 21 May 2010 16:30:32 -0000 1.15 *************** *** 103,105 **** --- 103,108 ---- </Phase> </Component> + <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> + <StaticModifier class="rails.game.specific._1851.OffBoardRevenueModifier" /> + </Component> </ComponentManager> \ No newline at end of file |
From: Stefan F. <ste...@us...> - 2010-05-21 16:30:40
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1851 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv16169/rails/game/specific/_1851 Added Files: OffBoardRevenueModifier.java Log Message: 1851 revenue calculation support and removed configuration interface from offboard modifiers --- NEW FILE: OffBoardRevenueModifier.java --- package rails.game.specific._1851; import java.util.HashSet; import java.util.Set; import rails.algorithms.NetworkVertex; import rails.algorithms.RevenueAdapter; import rails.algorithms.RevenueBonus; import rails.algorithms.RevenueStaticModifier; import rails.game.Station; public class OffBoardRevenueModifier implements RevenueStaticModifier { private static final int BONUS_VALUE = 10; public void modifyCalculator(RevenueAdapter revenueAdapter) { // 1. get all off-board type stations and all other stations Set<NetworkVertex> offBoard = new HashSet<NetworkVertex>(); Set<NetworkVertex> otherStations = new HashSet<NetworkVertex>(); for (NetworkVertex vertex:revenueAdapter.getVertices()) { if (vertex.isStation()) { if (vertex.getStation().getType().equals(Station.OFF_MAP_AREA)){ offBoard.add(vertex); } else { otherStations.add(vertex); } } } // 2. combine those to revenueBonuses // always two offboard areas and one other Set<NetworkVertex> destOffBoard = new HashSet<NetworkVertex>(offBoard); for (NetworkVertex offA:offBoard) { destOffBoard.remove(offA); for (NetworkVertex offB:destOffBoard) { for (NetworkVertex station:otherStations) { RevenueBonus bonus = new RevenueBonus(BONUS_VALUE, "OB/" + station.toString()); bonus.addVertex(offA); bonus.addVertex(offB); bonus.addVertex(station); revenueAdapter.addRevenueBonus(bonus); } } } } } |
From: Stefan F. <ste...@us...> - 2010-05-21 16:30:40
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv16169/rails/game/specific/_18EU Modified Files: OffBoardRevenueModifier.java Log Message: 1851 revenue calculation support and removed configuration interface from offboard modifiers Index: OffBoardRevenueModifier.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OffBoardRevenueModifier.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OffBoardRevenueModifier.java 20 May 2010 19:57:01 -0000 1.2 --- OffBoardRevenueModifier.java 21 May 2010 16:30:32 -0000 1.3 *************** *** 11,22 **** import rails.algorithms.RevenueStaticModifier; import rails.algorithms.RevenueAdapter.VertexVisit; - import rails.game.ConfigurableComponentI; - import rails.game.ConfigurationException; - import rails.game.GameManagerI; import rails.game.PhaseI; import rails.game.Station; - import rails.util.Tag; ! public class OffBoardRevenueModifier implements RevenueStaticModifier, ConfigurableComponentI { protected static Logger log = --- 11,18 ---- import rails.algorithms.RevenueStaticModifier; import rails.algorithms.RevenueAdapter.VertexVisit; import rails.game.PhaseI; import rails.game.Station; ! public class OffBoardRevenueModifier implements RevenueStaticModifier { protected static Logger log = *************** *** 24,36 **** - public void configureFromXML(Tag tag) throws ConfigurationException { - // does nothing - } - - public void finishConfiguration(GameManagerI parent) - throws ConfigurationException { - // does nothing - } - public void modifyCalculator(RevenueAdapter revenueAdapter) { --- 20,23 ---- |
From: Stefan F. <ste...@us...> - 2010-05-21 16:15:32
|
Update of /cvsroot/rails/18xx/data/18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14508/data/18EU Modified Files: Tiles.xml Log Message: Further minor fixes for revenue calculation (18EU) Index: Tiles.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/18EU/Tiles.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Tiles.xml 30 Apr 2010 15:26:32 -0000 1.10 --- Tiles.xml 21 May 2010 16:15:24 -0000 1.11 *************** *** 39,50 **** </Tile> <Tile colour="yellow" id="-3005" name="B/V"> ! <Station id="city1" position="102" slots="1" type="City" value="30"/> ! <Station id="city2" position="402" slots="1" type="City" value="30"/> <Track from="side3" gauge="normal" to="city2"/> <Track from="side0" gauge="normal" to="city1"/> </Tile> <Tile colour="yellow" id="-3006" name="Paris"> ! <Station id="city1" position="002" slots="1" type="City" value="40"/> ! <Station id="city2" position="302" slots="1" type="City" value="40"/> <Track from="city1" gauge="normal" to="side1"/> <Track from="city2" gauge="normal" to="side2"/> --- 39,50 ---- </Tile> <Tile colour="yellow" id="-3005" name="B/V"> ! <Station id="city1" position="102" slots="1" type="City" city="B/V" value="30"/> ! <Station id="city2" position="402" slots="1" type="City" city="B/V" value="30"/> <Track from="side3" gauge="normal" to="city2"/> <Track from="side0" gauge="normal" to="city1"/> </Tile> <Tile colour="yellow" id="-3006" name="Paris"> ! <Station id="city1" position="002" slots="1" type="City" city="Paris" value="40"/> ! <Station id="city2" position="302" slots="1" type="City" city="Paris" value="40"/> <Track from="city1" gauge="normal" to="side1"/> <Track from="city2" gauge="normal" to="side2"/> *************** *** 172,177 **** </Tile> <Tile colour="green" id="580" name="580"> ! <Station id="city1" position="052" slots="1" type="City" value="60"/> ! <Station id="city2" position="252" slots="1" type="City" value="60"/> <Track from="city1" gauge="normal" to="side1"/> <Track from="city1" gauge="normal" to="side0"/> --- 172,177 ---- </Tile> <Tile colour="green" id="580" name="580"> ! <Station id="city1" position="052" slots="1" type="City" city="Paris" value="60"/> ! <Station id="city2" position="252" slots="1" type="City" city="Paris" value="60"/> <Track from="city1" gauge="normal" to="side1"/> <Track from="city1" gauge="normal" to="side0"/> *************** *** 180,186 **** </Tile> <Tile colour="green" id="581" name="581"> ! <Station id="city1" position="152" slots="1" type="City" value="50"/> ! <Station id="city2" position="352" slots="1" type="City" value="50"/> ! <Station id="city3" position="552" slots="1" type="City" value="50"/> <Track from="city3" gauge="normal" to="side0"/> <Track from="city3" gauge="normal" to="side5"/> --- 180,186 ---- </Tile> <Tile colour="green" id="581" name="581"> ! <Station id="city1" position="152" slots="1" type="City" city="B/V" value="50"/> ! <Station id="city2" position="352" slots="1" type="City" city="B/V" value="50"/> ! <Station id="city3" position="552" slots="1" type="City" city="B/V" value="50"/> <Track from="city3" gauge="normal" to="side0"/> <Track from="city3" gauge="normal" to="side5"/> *************** *** 243,248 **** </Tile> <Tile colour="brown" id="583" name="583"> ! <Station id="city1" position="002" slots="2" type="City" value="80"/> ! <Station id="city2" position="302" slots="2" type="City" value="80"/> <Track from="city1" gauge="normal" to="side0"/> <Track from="city1" gauge="normal" to="side1"/> --- 243,248 ---- </Tile> <Tile colour="brown" id="583" name="583"> ! <Station id="city1" position="002" slots="2" type="City" city="Paris" value="80"/> ! <Station id="city2" position="302" slots="2" type="City" city="Paris" value="80"/> <Track from="city1" gauge="normal" to="side0"/> <Track from="city1" gauge="normal" to="side1"/> |
From: Stefan F. <ste...@us...> - 2010-05-21 16:15:32
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14508/rails/algorithms Modified Files: NetworkTrain.java NetworkVertex.java Log Message: Further minor fixes for revenue calculation (18EU) Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** NetworkVertex.java 20 May 2010 23:13:21 -0000 1.14 --- NetworkVertex.java 21 May 2010 16:15:24 -0000 1.15 *************** *** 247,254 **** // define locationName if (station.getType().equals(Station.OFF_MAP_AREA)) { ! cityName = hex.getCityName(); } else { ! cityName = station.getCityName(); } } --- 247,260 ---- // define locationName + cityName = null; if (station.getType().equals(Station.OFF_MAP_AREA)) { ! if (hex.getCityName() != null && !hex.getCityName().equals("")) { ! cityName = hex.getCityName(); ! } } else { ! if (hex.getCityName() != null && !hex.getCityName().equals("") ! && station.getCityName() != null && !station.getCityName().equals("")) { ! cityName = hex.getCityName() + "." + station.getCityName(); ! } } } Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** NetworkTrain.java 20 May 2010 23:13:21 -0000 1.9 --- NetworkTrain.java 21 May 2010 16:15:24 -0000 1.10 *************** *** 116,119 **** --- 116,121 ---- public TrainTypeI getRailsTrainType() { + if (railsTrain == null) return null; + return railsTrain.getType(); } |
From: Stefan F. <ste...@us...> - 2010-05-21 16:15:32
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14508/rails/game/specific/_18EU Modified Files: PullmanRevenueModifier.java Log Message: Further minor fixes for revenue calculation (18EU) Index: PullmanRevenueModifier.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/PullmanRevenueModifier.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PullmanRevenueModifier.java 20 May 2010 23:13:21 -0000 1.1 --- PullmanRevenueModifier.java 21 May 2010 16:15:24 -0000 1.2 *************** *** 20,24 **** List<NetworkTrain> trains = revenueAdapter.getTrains(); for (NetworkTrain train:trains) { ! if (train.getRailsTrainType().getName().equals("P")) { hasPullman = true; revenueAdapter.removeTrain(train); // remove from revenueAdapter --- 20,24 ---- List<NetworkTrain> trains = revenueAdapter.getTrains(); for (NetworkTrain train:trains) { ! if (train.getRailsTrainType() != null && train.getRailsTrainType().getName().equals("P")) { hasPullman = true; revenueAdapter.removeTrain(train); // remove from revenueAdapter |
From: Stefan F. <ste...@us...> - 2010-05-21 16:15:32
|
Update of /cvsroot/rails/18xx/tiles In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14508/tiles Modified Files: HandmadeTiles.xml Log Message: Further minor fixes for revenue calculation (18EU) Index: HandmadeTiles.xml =================================================================== RCS file: /cvsroot/rails/18xx/tiles/HandmadeTiles.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HandmadeTiles.xml 18 May 2010 04:13:27 -0000 1.2 --- HandmadeTiles.xml 21 May 2010 16:15:24 -0000 1.3 *************** *** 1,4 **** --- 1,16 ---- <?xml version="1.0" encoding="UTF-8" standalone="no"?> <Tiles> + <Tile colour="yellow" id="-3005" name="B/V"> + <Station id="city1" position="102" slots="1" type="City" city="B/V" value="30"/> + <Station id="city2" position="402" slots="1" type="City" city="B/V" value="30"/> + <Track from="side3" gauge="normal" to="city2"/> + <Track from="side0" gauge="normal" to="city1"/> + </Tile> + <Tile colour="yellow" id="-3006" name="Paris"> + <Station id="city1" position="002" slots="1" type="City" city="Paris" value="40"/> + <Station id="city2" position="302" slots="1" type="City" city="Paris" value="40"/> + <Track from="city1" gauge="normal" to="side1"/> + <Track from="city2" gauge="normal" to="side2"/> + </Tile> <Tile colour="red" id="-939" name="Goderich"> <Station id="city1" position="0" type="City" slots="0" value="-1"/> *************** *** 13,15 **** <Track from="city2" gauge="normal" to="side5"/> </Tile> ! </Tiles> --- 25,54 ---- <Track from="city2" gauge="normal" to="side5"/> </Tile> ! <Tile colour="green" id="580" name="580"> ! <Station id="city1" position="052" slots="1" type="City" city="Paris" value="60"/> ! <Station id="city2" position="252" slots="1" type="City" city="Paris" value="60"/> ! <Track from="city1" gauge="normal" to="side1"/> ! <Track from="city1" gauge="normal" to="side0"/> ! <Track from="city2" gauge="normal" to="side2"/> ! <Track from="city2" gauge="normal" to="side3"/> ! </Tile> ! <Tile colour="green" id="581" name="581"> ! <Station id="city1" position="152" slots="1" type="City" city="B/V" value="50"/> ! <Station id="city2" position="352" slots="1" type="City" city="B/V" value="50"/> ! <Station id="city3" position="552" slots="1" type="City" city="B/V" value="50"/> ! <Track from="city3" gauge="normal" to="side0"/> ! <Track from="city3" gauge="normal" to="side5"/> ! <Track from="city1" gauge="normal" to="side1"/> ! <Track from="city1" gauge="normal" to="side2"/> ! <Track from="city2" gauge="normal" to="side4"/> ! <Track from="city2" gauge="normal" to="side3"/> ! </Tile> ! <Tile colour="brown" id="583" name="583"> ! <Station id="city1" position="002" slots="2" type="City" city="Paris" value="80"/> ! <Station id="city2" position="302" slots="2" type="City" city="Paris" value="80"/> ! <Track from="city1" gauge="normal" to="side0"/> ! <Track from="city1" gauge="normal" to="side1"/> ! <Track from="city2" gauge="normal" to="side3"/> ! <Track from="city2" gauge="normal" to="side2"/> ! </Tile> ! </Tiles> |
From: Stefan F. <ste...@us...> - 2010-05-21 07:36:20
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv10924/rails/algorithms Modified Files: RevenueAdapter.java Log Message: Fixed minor bug Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** RevenueAdapter.java 20 May 2010 23:13:21 -0000 1.18 --- RevenueAdapter.java 21 May 2010 07:36:10 -0000 1.19 *************** *** 257,261 **** dynamicModifiers = gameManager.getRevenueManager().callDynamicModifiers(this); } else { ! dynamicModifiers = null; } --- 257,261 ---- dynamicModifiers = gameManager.getRevenueManager().callDynamicModifiers(this); } else { ! dynamicModifiers = new HashSet<RevenueDynamicModifier>(); } *************** *** 411,415 **** // activate dynamic modifiers ! rc.setDynamicModifiers(dynamicModifiers != null); } --- 411,415 ---- // activate dynamic modifiers ! rc.setDynamicModifiers(!dynamicModifiers.isEmpty()); } |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:32
|
Update of /cvsroot/rails/18xx/data/18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/data/18EU Modified Files: Game.xml Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/18EU/Game.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Game.xml 19 May 2010 20:14:13 -0000 1.22 --- Game.xml 20 May 2010 23:13:21 -0000 1.23 *************** *** 106,109 **** --- 106,110 ---- <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> <StaticModifier class="rails.game.specific._18EU.OffBoardRevenueModifier" /> + <DynamicModifier class="rails.game.specific._18EU.PullmanRevenueModifier" /> </Component> </ComponentManager> \ No newline at end of file |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:29
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/rails/algorithms Modified Files: NetworkTrain.java RevenueCalculator.java RevenueAdapter.java RevenueTrainRun.java RevenueManager.java NetworkVertex.java Added Files: RevenueDynamicModifier.java Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RevenueCalculator.java 20 May 2010 19:57:01 -0000 1.15 --- RevenueCalculator.java 20 May 2010 23:13:21 -0000 1.16 *************** *** 89,92 **** --- 89,95 ---- private RevenueAdapter revenueAdapter; + // activate dynamic revenue modifiers + private boolean callDynamicModifiers; + // termination results private static enum Terminated { *************** *** 155,158 **** --- 158,163 ---- useRevenuePrediction = false; + + callDynamicModifiers = false; } *************** *** 221,224 **** --- 226,233 ---- } + void setDynamicModifiers(boolean activate) { + callDynamicModifiers = activate; + } + int[][] getOptimalRun() { log.info("RC: currentBestRun = " + Arrays.deepToString(currentBestRun)); *************** *** 226,229 **** --- 235,253 ---- } + int[][] getCurrentRun() { + int[][] currentRun = new int[nbTrains][nbVertexes+1]; + for (int j = startTrainSet; j <= finalTrainSet; j++) { + for (int v = 0; v < nbVertexes + 1; v++) { + if (v < trainStackPos[j]) { + currentRun[j][v] = trainVertexStack[j][v]; + } else { + currentRun[j][v] = -1; // terminator + break; + } + } + } + return currentRun; + } + int getNumberOfEvaluations() { return nbEvaluations; *************** *** 680,683 **** --- 704,709 ---- // } } + + if (callDynamicModifiers) totalValue += revenueAdapter.dynamicEvaluation(); nbEvaluations++; *************** *** 747,750 **** --- 773,778 ---- } + if (callDynamicModifiers) totalValue += revenueAdapter.dynamicPrediction(); + nbPredictions++; --- NEW FILE: RevenueDynamicModifier.java --- package rails.algorithms; /** * Classes that change properties of the revenue calculation * after the actual calculation started implement the dynamic modifier. * * They have to register themselves to the RevenueManager via the GameManager instance. * @author freystef * */ public interface RevenueDynamicModifier { /** after the setup of the revenueAdapter, but before the actual calculation * if return is false => deactivate */ public boolean prepareModifier(RevenueAdapter revenueAdapter); /** returns the value used for prediction */ public int predictionValue(RevenueAdapter revenueAdapter); /** returns the value used for evaluation */ public int evaluationValue(RevenueAdapter revenueAdapter); /** returns the prettyPrintName */ public String prettyPrint(RevenueAdapter revenueAdapter); } Index: RevenueManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RevenueManager.java 18 May 2010 21:36:12 -0000 1.2 --- RevenueManager.java 20 May 2010 23:13:21 -0000 1.3 *************** *** 30,36 **** --- 30,38 ---- private Set<RevenueStaticModifier> staticModifiers; + private Set<RevenueDynamicModifier> dynamicModifiers; public RevenueManager() { staticModifiers = new HashSet<RevenueStaticModifier>(); + dynamicModifiers = new HashSet<RevenueDynamicModifier>(); } *************** *** 61,64 **** --- 63,91 ---- } } + + // define dynamic modifiers + modifierTags = tag.getChildren("DynamicModifier"); + + if (modifierTags != null) { + for (Tag modifierTag:modifierTags) { + // get classname + String className = modifierTag.getAttributeAsString("class"); + if (className == null) { + throw new ConfigurationException(LocalText.getText( + "ComponentHasNoClass", "DynamicModifier")); + } + // create modifier + RevenueDynamicModifier modifier; + try { + modifier = (RevenueDynamicModifier) Class.forName(className).newInstance(); + } catch (Exception e) { + throw new ConfigurationException(LocalText.getText( + "ClassCannotBeInstantiated", className), e); + } + // add them to the revenueManager + dynamicModifiers.add(modifier); + log.info("Added modifier " + className); + } + } } *************** *** 74,78 **** public void addStaticModifier(RevenueStaticModifier modifier) { staticModifiers.add(modifier); ! log.info("Added modifier " + modifier); } --- 101,123 ---- public void addStaticModifier(RevenueStaticModifier modifier) { staticModifiers.add(modifier); ! log.info("Revenue Manager: Added modifier " + modifier); ! } ! ! public boolean removeStaticModifier(RevenueStaticModifier modifier) { ! boolean result = staticModifiers.remove(modifier); ! if (result) { ! log.info("RevenueManager: Removed modifier " + modifier); ! } else { ! log.info("RevenueManager: Cannot remove" + modifier); ! } ! return result; ! } ! ! Set<RevenueStaticModifier> getStaticModifiers() { ! return staticModifiers; ! } ! ! Set<RevenueDynamicModifier> getDynamicModifiers() { ! return dynamicModifiers; } *************** *** 81,85 **** modifier.modifyCalculator(revenueAdapter); } ! } --- 126,138 ---- modifier.modifyCalculator(revenueAdapter); } ! } ! ! Set<RevenueDynamicModifier> callDynamicModifiers(RevenueAdapter revenueAdapter) { ! Set<RevenueDynamicModifier> activeModifiers = new HashSet<RevenueDynamicModifier>(); ! for (RevenueDynamicModifier modifier:dynamicModifiers) { ! if (modifier.prepareModifier(revenueAdapter)) ! activeModifiers.add(modifier); ! } ! return activeModifiers; } Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** NetworkVertex.java 20 May 2010 19:57:01 -0000 1.13 --- NetworkVertex.java 20 May 2010 23:13:21 -0000 1.14 *************** *** 298,301 **** --- 298,312 ---- } + /** + * Returns the maximum positive value (lower bound zero) + */ + public static int maxVertexValue(Collection<NetworkVertex> vertices) { + int maximum = 0; + for (NetworkVertex vertex:vertices) { + maximum = Math.max(maximum, vertex.getValue()); + } + return maximum; + } + public static void initAllRailsVertices(Collection<NetworkVertex> vertices, PublicCompanyI company, PhaseI phase) { Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RevenueAdapter.java 20 May 2010 19:57:01 -0000 1.17 --- RevenueAdapter.java 20 May 2010 23:13:21 -0000 1.18 *************** *** 3,7 **** import java.awt.EventQueue; import java.awt.geom.GeneralPath; - import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Arrays; --- 3,6 ---- *************** *** 61,64 **** --- 60,65 ---- private List<NetworkEdge> rcEdges; private List<RevenueTrainRun> optimalRun; + private Set<RevenueDynamicModifier> dynamicModifiers; + // revenue listener to communicate results *************** *** 135,138 **** --- 136,143 ---- } } + + public void removeTrain(NetworkTrain train) { + trains.remove(train); + } public boolean addTrainByString(String trainString) { *************** *** 194,198 **** --- 199,205 ---- gameManager.getRevenueManager().callStaticModifiers(this); } + } + private void defineVertexVisitSets() { // define map of all locationNames *************** *** 245,252 **** public void initRevenueCalculator(){ // optimize graph (optimizeGraph clones the graph) rcGraph = NetworkGraphBuilder.optimizeGraph(graph, protectedVertices); ! // define the vertices and edges lists rcVertices = new ArrayList<NetworkVertex>(rcGraph.vertexSet()); --- 252,266 ---- public void initRevenueCalculator(){ + + // add all dynamic modifiers + if (gameManager.getRevenueManager() != null) { + dynamicModifiers = gameManager.getRevenueManager().callDynamicModifiers(this); + } else { + dynamicModifiers = null; + } // optimize graph (optimizeGraph clones the graph) rcGraph = NetworkGraphBuilder.optimizeGraph(graph, protectedVertices); ! // define the vertices and edges lists rcVertices = new ArrayList<NetworkVertex>(rcGraph.vertexSet()); *************** *** 396,399 **** --- 410,415 ---- } + // activate dynamic modifiers + rc.setDynamicModifiers(dynamicModifiers != null); } *************** *** 458,464 **** --- 474,507 ---- return value; } + public List<RevenueTrainRun> getOptimalRun() { return optimalRun; } + + public List<RevenueTrainRun> getCurrentRun() { + return convertRcRun(rc.getCurrentRun()); + } + + /** + * is called by rc for dynamic evaluations + */ + int dynamicEvaluation() { + int value = 0; + for (RevenueDynamicModifier modifier:dynamicModifiers) { + value += modifier.evaluationValue(this); + } + return value; + } + + /** + * is called by rc for dynamic predictions + */ + int dynamicPrediction() { + int value = 0; + for (RevenueDynamicModifier modifier:dynamicModifiers) { + value += modifier.predictionValue(this); + } + return value; + } public void addRevenueListener(RevenueListener listener) { *************** *** 494,497 **** --- 537,545 ---- runPrettyPrint.append(run.prettyPrint()); } + // add dynamic Modifier + for (RevenueDynamicModifier modifier:dynamicModifiers) { + runPrettyPrint.append(modifier.prettyPrint(this)); + } + return runPrettyPrint.toString(); } Index: RevenueTrainRun.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueTrainRun.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RevenueTrainRun.java 20 May 2010 19:57:01 -0000 1.4 --- RevenueTrainRun.java 20 May 2010 23:13:21 -0000 1.5 *************** *** 36,41 **** } ! void addVertex(NetworkVertex vertex) { ! vertices.add(vertex); } --- 36,45 ---- } ! public List<NetworkVertex> getVertices() { ! return vertices; ! } ! ! public NetworkTrain getTrain() { ! return train; } *************** *** 57,60 **** --- 61,68 ---- } + void addVertex(NetworkVertex vertex) { + vertices.add(vertex); + } + private String prettyPrintHexName(NetworkVertex vertex) { if (vertex.isVirtual()) { Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** NetworkTrain.java 20 May 2010 19:57:01 -0000 1.8 --- NetworkTrain.java 20 May 2010 23:13:21 -0000 1.9 *************** *** 46,55 **** String trainName = railsTrain.getName(); ! if (majors == -1) { ! return null;// protection against pullman ! } else { ! return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, trainName, railsTrain); - } } --- 46,51 ---- String trainName = railsTrain.getName(); ! return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, trainName, railsTrain); } |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:29
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18AL In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/rails/game/specific/_18AL Modified Files: NamedTrainToken.java Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier Index: NamedTrainToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18AL/NamedTrainToken.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NamedTrainToken.java 20 May 2010 19:57:01 -0000 1.6 --- NamedTrainToken.java 20 May 2010 23:13:21 -0000 1.7 *************** *** 5,13 **** import org.apache.log4j.Logger; ! import rails.algorithms.NetworkVertex; ! import rails.algorithms.RevenueAdapter; ! import rails.algorithms.RevenueBonus; ! import rails.algorithms.RevenueManager; ! import rails.algorithms.RevenueStaticModifier; import rails.game.*; import rails.util.Tag; --- 5,13 ---- import org.apache.log4j.Logger; ! //import rails.algorithms.NetworkVertex; ! //import rails.algorithms.RevenueAdapter; ! //import rails.algorithms.RevenueBonus; ! //import rails.algorithms.RevenueManager; ! //import rails.algorithms.RevenueStaticModifier; import rails.game.*; import rails.util.Tag; |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:29
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/rails/game Modified Files: Bonus.java Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier Index: Bonus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Bonus.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Bonus.java 19 May 2010 20:14:13 -0000 1.10 --- Bonus.java 20 May 2010 23:13:21 -0000 1.11 *************** *** 5,9 **** import java.util.Set; - import org.apache.log4j.Logger; import rails.algorithms.NetworkVertex; --- 5,8 ---- *************** *** 84,89 **** */ public void close() { - owner.removeBonus(name); } --- 83,89 ---- */ public void close() { owner.removeBonus(name); + // remove it from the call list of the RevenueManager + GameManager.getInstance().getRevenueManager().removeStaticModifier(this); } |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:29
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/rails/game/specific/_18EU Added Files: PullmanRevenueModifier.java Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier --- NEW FILE: PullmanRevenueModifier.java --- package rails.game.specific._18EU; import java.util.Collection; import java.util.List; import rails.algorithms.NetworkTrain; import rails.algorithms.NetworkVertex; import rails.algorithms.RevenueAdapter; import rails.algorithms.RevenueDynamicModifier; import rails.algorithms.RevenueTrainRun; public class PullmanRevenueModifier implements RevenueDynamicModifier { private boolean hasPullman; private int maxValue; public boolean prepareModifier(RevenueAdapter revenueAdapter) { // 1. check if there is a Pullman in the train set hasPullman = false; List<NetworkTrain> trains = revenueAdapter.getTrains(); for (NetworkTrain train:trains) { if (train.getRailsTrainType().getName().equals("P")) { hasPullman = true; revenueAdapter.removeTrain(train); // remove from revenueAdapter break; } } if (!hasPullman) return false; // 2. find the maximum value of the vertices maxValue = maximumMajorValue(revenueAdapter.getVertices()); return true; } public int evaluationValue(RevenueAdapter revenueAdapter) { return pullmanValue(revenueAdapter.getCurrentRun()); } private int pullmanValue(List<RevenueTrainRun> trainRuns) { int maximum = 0; for (RevenueTrainRun trainRun:trainRuns) { maximum = Math.max(maximum, maximumMajorValue(trainRun.getVertices())); if (maximum == maxValue) break; } return maximum; } public int predictionValue(RevenueAdapter revenueAdapter) { return maxValue; } public String prettyPrint(RevenueAdapter revenueAdapter) { return "Pullman: " + pullmanValue(revenueAdapter.getOptimalRun()); } private int maximumMajorValue(Collection<NetworkVertex> vertices) { int maximum = 0; for (NetworkVertex vertex:vertices) { if (!vertex.isMajor()) continue; maximum= Math.max(maximum, vertex.getValue()); } return maximum; } } |
From: Stefan F. <ste...@us...> - 2010-05-20 23:13:29
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26538/rails/ui/swing Modified Files: ORPanel.java Log Message: Added support for 18EU Pullman, introduced RevenueDynamicModifier Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** ORPanel.java 15 May 2010 16:36:09 -0000 1.64 --- ORPanel.java 20 May 2010 23:13:21 -0000 1.65 *************** *** 4,7 **** --- 4,8 ---- import java.awt.*; import java.awt.event.*; + import java.util.ArrayList; import java.util.List; *************** *** 601,613 **** CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); ! boolean anotherTrain = true; while (anotherTrain) { ! int revenueValue; ra.initRevenueCalculator(); log.info("Revenue Adapter:" + ra); ! revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); log.info("Revenue Run:" + ra.getOptimalRunPrettyPrint()); --- 602,617 ---- CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! List<String> addTrainList = new ArrayList<String>(); boolean anotherTrain = true; + RevenueAdapter ra = null; while (anotherTrain) { ! ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); ! for (String addTrain:addTrainList) { ! ra.addTrainByString(addTrain); ! } ra.initRevenueCalculator(); log.info("Revenue Adapter:" + ra); ! int revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); log.info("Revenue Run:" + ra.getOptimalRunPrettyPrint()); *************** *** 617,629 **** "\nRevenueRun = \n" + ra.getOptimalRunPrettyPrint()); ! String trainsToAdd = JOptionPane.showInputDialog(orWindow, "Another train", "Add another train to run?", JOptionPane.QUESTION_MESSAGE); ! if (trainsToAdd == null || trainsToAdd.equals("")) { anotherTrain = false; } else { ! ra.addTrainByString(trainsToAdd); } } revenueAdapter = ra; --- 621,634 ---- "\nRevenueRun = \n" + ra.getOptimalRunPrettyPrint()); ! String trainString = JOptionPane.showInputDialog(orWindow, "Another train", "Add another train to run?", JOptionPane.QUESTION_MESSAGE); ! if (trainString == null || trainString.equals("")) { anotherTrain = false; } else { ! addTrainList.add(trainString); } + } revenueAdapter = ra; |
From: Stefan F. <ste...@us...> - 2010-05-20 19:57:10
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22874/rails/algorithms Modified Files: NetworkTrain.java RevenueCalculator.java RevenueAdapter.java RevenueTrainRun.java RevenueBonus.java NetworkVertex.java NetworkGraphBuilder.java Log Message: Revenue Calculator support for 18AL and various other fixes Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NetworkVertex.java 19 May 2010 20:14:13 -0000 1.12 --- NetworkVertex.java 20 May 2010 19:57:01 -0000 1.13 *************** *** 107,111 **** void addToRevenueCalculator(RevenueCalculator rc, int vertexId) { ! rc.setVertex(vertexId, major, minor); } --- 107,111 ---- void addToRevenueCalculator(RevenueCalculator rc, int vertexId) { ! rc.setVertex(vertexId, major, minor, sink); } *************** *** 259,263 **** // define value ! if (station.getType().equals(Station.OFF_MAP_AREA) || station.getValue() == -1) { value = hex.getCurrentOffBoardValue(phase); } else { --- 259,264 ---- // define value ! // if (station.getType().equals(Station.OFF_MAP_AREA) || station.getValue() == -1) { ! if (hex.hasOffBoardValues()) { value = hex.getCurrentOffBoardValue(phase); } else { *************** *** 334,338 **** if (addOldVertexAsHidden) hiddenVertices.add(vertex); hiddenVertices.addAll(edge.getHiddenVertexes()); ! NetworkEdge newEdge = new NetworkEdge(edge.getSource(), newVertex, edge.isGreedy(), edge.getDistance(), edge.getHiddenVertexes()); graph.addEdge(newEdge.getSource(), newVertex, newEdge); } --- 335,339 ---- if (addOldVertexAsHidden) hiddenVertices.add(vertex); hiddenVertices.addAll(edge.getHiddenVertexes()); ! NetworkEdge newEdge = new NetworkEdge(edge.getSource(), newVertex, edge.isGreedy(), edge.getDistance(), hiddenVertices); graph.addEdge(newEdge.getSource(), newVertex, newEdge); } Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RevenueCalculator.java 18 May 2010 04:12:22 -0000 1.14 --- RevenueCalculator.java 20 May 2010 19:57:01 -0000 1.15 *************** *** 16,19 **** --- 16,20 ---- private final boolean[] vertexMajor; private final boolean[] vertexMinor; + private final boolean[] vertexSink; private final int[] vertexNbNeighbors; private final int[] vertexNbVisitSets; *************** *** 38,41 **** --- 39,43 ---- private final int[] trainMaxMajors; private final int[] trainMaxMinors; + private final int[] trainMaxBonuses; private final boolean[] trainIgnoreMinors; *************** *** 44,50 **** private final int[] trainMajors; private final int[] trainMinors; private final boolean[][] trainVisited; private final int[][] trainVertexStack; ! private final int[][] trainEdgeStack; private final int[] trainStackPos; private final int [] trainBottomPos; --- 46,53 ---- private final int[] trainMajors; private final int[] trainMinors; + private final int[] trainBonuses; // counts the number of bonuses received private final boolean[][] trainVisited; private final int[][] trainVertexStack; ! // private final int[][] trainEdgeStack; private final int[] trainStackPos; private final int [] trainBottomPos; *************** *** 114,117 **** --- 117,121 ---- vertexMajor = new boolean[nbVertexes]; vertexMinor = new boolean[nbVertexes]; + vertexSink = new boolean[nbVertexes]; vertexNbNeighbors = new int[nbVertexes]; vertexNbVisitSets = new int[nbVertexes]; *************** *** 128,131 **** --- 132,136 ---- trainMaxMajors = new int[nbTrains]; trainMaxMinors = new int[nbTrains]; + trainMaxBonuses = new int[nbTrains]; // only required for revenue prediction trainIgnoreMinors = new boolean[nbTrains]; *************** *** 133,140 **** trainMajors = new int[nbTrains]; trainMinors = new int[nbTrains]; trainVisited = new boolean[nbTrains][nbVertexes]; trainVertexStack = new int[nbTrains][nbVertexes + 1]; // increase necessary due to buttom train ! trainEdgeStack = new int[nbTrains][nbVertexes + 1]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; --- 138,146 ---- trainMajors = new int[nbTrains]; trainMinors = new int[nbTrains]; + trainBonuses = new int[nbTrains]; trainVisited = new boolean[nbTrains][nbVertexes]; trainVertexStack = new int[nbTrains][nbVertexes + 1]; // increase necessary due to buttom train ! // trainEdgeStack = new int[nbTrains][nbVertexes + 1]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; *************** *** 151,157 **** } ! void setVertex(int id, boolean major, boolean minor) { vertexMajor[id] = major; vertexMinor[id] = minor; // default neighbors && visit and bonus sets vertexNbNeighbors[id] = 0; --- 157,164 ---- } ! void setVertex(int id, boolean major, boolean minor, boolean sink) { vertexMajor[id] = major; vertexMinor[id] = minor; + vertexSink[id] = sink; // default neighbors && visit and bonus sets vertexNbNeighbors[id] = 0; *************** *** 187,190 **** --- 194,198 ---- trainMaxMajors[id] = majors; trainMaxMinors[id] = minors; + trainMaxBonuses[id] = 0; trainIgnoreMinors[id] = ignoreMinors; } *************** *** 249,253 **** bestRevenues[j] = cumulatedRevenues; } ! log.info(Arrays.toString(bestRevenues)); return bestRevenues; } --- 257,261 ---- bestRevenues[j] = cumulatedRevenues; } ! log.debug("Best Revenues = " + Arrays.toString(bestRevenues)); return bestRevenues; } *************** *** 258,279 **** maxMajorRevenues = new int[nbTrains][nbVertexes]; maxMinorRevenues = new int[nbTrains][nbVertexes]; for (int t=startTrain; t <= finalTrain; t++) { int[] majorValues = new int[nbVertexes]; int[] minorValues = new int[nbVertexes]; ! int[] bonusValues = new int[nbVertexes]; int major = 0, minor = 0, bonus = 0; for (int v=0; v < nbVertexes; v++) { if (vertexValueByTrain[v][t] == 0) continue; ! if (vertexMajor[v]) majorValues[major++] = vertexValueByTrain[v][t]; ! else if (vertexMinor[v]) minorValues[minor++] = vertexValueByTrain[v][t]; ! else bonusValues[bonus++] = vertexValueByTrain[v][t]; } maxMajorRevenues[t] = bestRevenues(majorValues, trainMaxMajors[t]); maxMinorRevenues[t] = bestRevenues(minorValues, trainMaxMinors[t]); ! maxCumulatedTrainRevenues[t] = maxMajorRevenues[t][trainMaxMajors[t]] + maxMinorRevenues[t][trainMaxMinors[t]]; } } --- 266,305 ---- maxMajorRevenues = new int[nbTrains][nbVertexes]; maxMinorRevenues = new int[nbTrains][nbVertexes]; + maxBonusRevenues = new int[nbTrains][nbVertexes + nbBonuses]; + int cumulatedRevenues = 0; for (int t=startTrain; t <= finalTrain; t++) { int[] majorValues = new int[nbVertexes]; int[] minorValues = new int[nbVertexes]; ! int[] bonusValues = new int[nbVertexes + nbBonuses]; int major = 0, minor = 0, bonus = 0; + // scan vertices for values for (int v=0; v < nbVertexes; v++) { if (vertexValueByTrain[v][t] == 0) continue; ! if (vertexMajor[v]) { majorValues[major++] = vertexValueByTrain[v][t]; ! } else if (vertexMinor[v]) { minorValues[minor++] = vertexValueByTrain[v][t]; ! } else { // define it as bonus bonusValues[bonus++] = vertexValueByTrain[v][t]; + } } + // add the (complex) bonuses + for (int b=0; b < nbBonuses; b++) { + if (bonusValue[b] <= 0 || !bonusActiveForTrain[b][t]) continue; + bonusValues[bonus++] = bonusValue[b]; + } + trainMaxBonuses[t] = bonus; + maxMajorRevenues[t] = bestRevenues(majorValues, trainMaxMajors[t]); maxMinorRevenues[t] = bestRevenues(minorValues, trainMaxMinors[t]); ! maxBonusRevenues[t] = bestRevenues(bonusValues, trainMaxBonuses[t]); ! cumulatedRevenues += maxMajorRevenues[t][trainMaxMajors[t]] + maxMinorRevenues[t][trainMaxMinors[t]] ! + maxBonusRevenues[t][trainMaxBonuses[t]]; ! maxCumulatedTrainRevenues[t] = cumulatedRevenues; } + log.info("maxMajorRevenues = " + Arrays.deepToString(maxMajorRevenues)); + log.info("maxMinorRevenues = " + Arrays.deepToString(maxMinorRevenues)); + log.info("maxBonusRevenues = " + Arrays.deepToString(maxBonusRevenues)); + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); } *************** *** 313,316 **** --- 339,343 ---- maxCumulatedTrainRevenues[j] = cumulatedRevenues; } + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); if (startTrain == finalTrain - 1) return; *************** *** 326,329 **** --- 353,357 ---- maxCumulatedTrainRevenues[j] = currentBestValue; maxCumulatedTrainRevenues[j-1] = currentBestValue + maxSingleTrainRevenues[j-1]; + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); } } *************** *** 361,364 **** --- 389,393 ---- trainMajors[trainId] = trainMaxMajors[trainId]; trainMinors[trainId] = trainMaxMinors[trainId]; + trainBonuses[trainId] = trainMaxBonuses[trainId]; // initialize the positions *************** *** 393,396 **** --- 422,426 ---- // then try all edges of it + // for startVertices the sink property is ignored for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; *************** *** 405,408 **** --- 435,439 ---- trainStartEdge[trainId] = j; // store start edge nextVertex(trainId, neighborId, edgeGreedy[edgeId]); + returnEdge(edgeId); } } *************** *** 430,440 **** log.debug("RC: runBottom " +trainId); trainBottomPos[trainId] = trainStackPos[trainId]; // store the stack position where bottom starts log.debug("RC: Restart at bottom at stack position " + trainBottomPos[trainId]); - // use startvertex - int vertexId = trainVertexStack[trainId][0]; - trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; // push to stack - for (int j = trainStartEdge[trainId] + 1; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; --- 461,476 ---- log.debug("RC: runBottom " +trainId); + // use startvertex, check if it is a sink + int vertexId = trainVertexStack[trainId][0]; + if (vertexSink[vertexId]) { + log.debug("RC: startvertex is sink, finished bottom of " + trainId); + return; + } + + // push to stack trainBottomPos[trainId] = trainStackPos[trainId]; // store the stack position where bottom starts + trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; log.debug("RC: Restart at bottom at stack position " + trainBottomPos[trainId]); for (int j = trainStartEdge[trainId] + 1; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; *************** *** 448,451 **** --- 484,488 ---- if (travelEdge(trainId, edgeId, true)) { nextVertex(trainId, neighborId, edgeGreedy[edgeId]); + returnEdge(edgeId); } } *************** *** 471,492 **** // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); ! returnEdge(trainId); return; } } ! // 2a. visit neighbors, if train has not terminated if (trainTerminated == Terminated.NotYet) { ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int edgeId = vertexEdges[vertexId][j]; ! if (edgeUsed[edgeId]) continue; ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of " + vertexId + " is " + neighborId); ! if (trainVisited[trainId][neighborId]) { ! log.debug("RC: Hex already visited"); ! continue; ! } ! if (travelEdge(trainId, edgeId, previousGreedy)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); } } --- 508,532 ---- // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); ! // returnEdge(trainId); return; } } ! // 2a. visit neighbors, if train has not terminated and vertex is not a sink if (trainTerminated == Terminated.NotYet) { ! if (!vertexSink[vertexId]) { ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int edgeId = vertexEdges[vertexId][j]; ! if (edgeUsed[edgeId]) continue; ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of " + vertexId + " is " + neighborId); ! if (trainVisited[trainId][neighborId]) { ! log.debug("RC: Hex already visited"); ! continue; ! } ! if (travelEdge(trainId, edgeId, previousGreedy)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); ! returnEdge(edgeId); ! } } } *************** *** 503,507 **** // 4. then leave that vertex encounterVertex(trainId, vertexId, false); ! returnEdge(trainId); } --- 543,547 ---- // 4. then leave that vertex encounterVertex(trainId, vertexId, false); ! // returnEdge(trainId); } *************** *** 553,556 **** --- 593,597 ---- if (bonusTrainVertices[bonusId][trainId] == 0) { trainCurrentValue[trainId] += bonusValue[bonusId]; + if (bonusValue[bonusId] > 0) trainBonuses[trainId]--; log.debug("RC: Added bonus " + bonusId + " with value " + bonusValue[bonusId]); } *************** *** 558,561 **** --- 599,603 ---- if (bonusTrainVertices[bonusId][trainId] == 0) { trainCurrentValue[trainId] -= bonusValue[bonusId]; + if (bonusValue[bonusId] > 0) trainBonuses[trainId]++; log.debug("RC: Removed bonus " + bonusId + " with value " + bonusValue[bonusId]); } *************** *** 565,568 **** --- 607,611 ---- } + log.debug("RC: stationVertex = " + stationVertex); log.debug("RC: Count Visits = " + countVisits); return stationVertex; *************** *** 573,577 **** log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; ! trainEdgeStack[trainId][trainStackPos[trainId]] = edgeId; countEdges++; nbEdgesTravelled++; log.debug("RC: Count Edges = " + countEdges); --- 616,620 ---- log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; ! // trainEdgeStack[trainId][trainStackPos[trainId]] = edgeId; countEdges++; nbEdgesTravelled++; log.debug("RC: Count Edges = " + countEdges); *************** *** 583,601 **** } ! private void returnEdge(int trainId) { ! int stackPos = trainStackPos[trainId]; ! log.debug("RC: Tries to clear edge at stack position " + stackPos + " of train " + trainId); ! ! if (stackPos == 0) { ! log.debug("RC: Position zero has not to be cleared"); ! return; ! } ! ! if (stackPos == trainBottomPos[trainId]) { ! log.debug("RC: Replace start Vertex for bottom position"); ! } ! ! int edgeId = trainEdgeStack[trainId][stackPos]; ! if (edgeUsed[edgeId]) { edgeUsed[edgeId] = false; --- 626,630 ---- } ! private void returnEdge(int edgeId) { if (edgeUsed[edgeId]) { edgeUsed[edgeId] = false; *************** *** 604,608 **** log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug ("RC: Error return edge id used: " + edgeId); } } --- 633,637 ---- log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug("RC: Error return edge id used: " + edgeId); } } *************** *** 696,699 **** --- 725,732 ---- } } + // add potential bonuses + if (trainBonuses[trainId] != 0) { + trainValue += maxBonusRevenues[trainId][trainBonuses[trainId]]; + } log.debug("RC: Current train has predicted value of " + trainValue); Index: RevenueBonus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueBonus.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RevenueBonus.java 14 May 2010 15:19:57 -0000 1.2 --- RevenueBonus.java 20 May 2010 19:57:01 -0000 1.3 *************** *** 1,4 **** --- 1,5 ---- package rails.algorithms; + import java.util.Collection; import java.util.List; import java.util.ArrayList; *************** *** 7,10 **** --- 8,12 ---- import rails.game.PhaseI; + import rails.game.TrainI; import rails.game.TrainTypeI; *************** *** 23,26 **** --- 25,29 ---- private List<NetworkVertex> vertices; private List<TrainTypeI> trainTypes; + private List<TrainI> trains; private List<PhaseI> phases; *************** *** 31,34 **** --- 34,38 ---- vertices = new ArrayList<NetworkVertex>(); trainTypes = new ArrayList<TrainTypeI>(); + trains = new ArrayList<TrainI>(); phases = new ArrayList<PhaseI>(); } *************** *** 37,40 **** --- 41,48 ---- vertices.add(vertex); } + + public void addVertices(Collection<NetworkVertex> vertices) { + this.vertices.addAll(vertices); + } public void addTrainType(TrainTypeI trainType) { *************** *** 42,45 **** --- 50,57 ---- } + public void addTrain(TrainI train) { + trains.add(train); + } + public void addPhase(PhaseI phase) { phases.add(phase); *************** *** 62,65 **** --- 74,81 ---- } + public List<TrainI> getTrains() { + return trains; + } + public List<PhaseI> getPhases() { return phases; *************** *** 82,86 **** boolean[] trainsArray = new boolean[trains.size()]; for (int j=0; j < trains.size(); j++) { ! trainsArray[j] = checkConditions(trains.get(j).getRailsTrainType(), phase); } --- 98,102 ---- boolean[] trainsArray = new boolean[trains.size()]; for (int j=0; j < trains.size(); j++) { ! trainsArray[j] = checkConditions(trains.get(j).getRailsTrain(), phase); } *************** *** 92,101 **** } ! public boolean checkSimpleBonus(NetworkVertex vertex, TrainTypeI trainType, PhaseI phase) { ! return (isSimpleBonus() && vertices.contains(vertex) && checkConditions(trainType, phase)); } ! public boolean checkComplexBonus(List<NetworkVertex> visitVertices, TrainTypeI trainType, PhaseI phase) { ! boolean result = !isSimpleBonus() && checkConditions(trainType, phase); if (result) { for (NetworkVertex vertex:vertices) { --- 108,117 ---- } ! public boolean checkSimpleBonus(NetworkVertex vertex, TrainI train, PhaseI phase) { ! return (isSimpleBonus() && vertices.contains(vertex) && checkConditions(train, phase)); } ! public boolean checkComplexBonus(List<NetworkVertex> visitVertices, TrainI train, PhaseI phase) { ! boolean result = !isSimpleBonus() && checkConditions(train, phase); if (result) { for (NetworkVertex vertex:vertices) { *************** *** 109,121 **** } ! public boolean checkConditions(TrainTypeI trainType, PhaseI phase) { boolean result = true; // check trainTypes if (!trainTypes.isEmpty()) { ! if (trainType == null) { result = false; } else { ! result = result && trainTypes.contains(trainType); } } --- 125,146 ---- } ! public boolean checkConditions(TrainI train, PhaseI phase) { boolean result = true; + // check train + if (!trains.isEmpty()) { + if (train == null) { + result = false; + } else { + result = result && trains.contains(train); + } + } + // check trainTypes if (!trainTypes.isEmpty()) { ! if (train == null) { result = false; } else { ! result = result && trainTypes.contains(train.getType()); } } Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** RevenueAdapter.java 19 May 2010 20:14:13 -0000 1.16 --- RevenueAdapter.java 20 May 2010 19:57:01 -0000 1.17 *************** *** 335,355 **** } ! // set neighbors ! if (!v.isSink()) { ! List<NetworkVertex> neighbors = Graphs.neighborListOf(rcGraph, v); ! int j=0, neighborsArray[] = new int[neighbors.size()]; ! for (NetworkVertex n:neighbors){ ! neighborsArray[j++] = rcVertices.indexOf(n); ! } ! // sort by value orderboolean activatePrediction ! Arrays.sort(neighborsArray, 0, j); ! // define according edges ! int[] edgesArray = new int[j]; ! for (int e=0; e < j; e++) { ! NetworkVertex n = rcVertices.get(neighborsArray[e]); ! edgesArray[e] = rcEdges.indexOf(rcGraph.getEdge(v, n)); ! } ! rc.setVertexNeighbors(id, neighborsArray, edgesArray); } } --- 335,357 ---- } ! // set neighbors, now regardless of sink property ! // this is covered by the vertex attribute ! // and required for startvertices that are sinks themselves ! // if (!v.isSink()) { ! List<NetworkVertex> neighbors = Graphs.neighborListOf(rcGraph, v); ! int j=0, neighborsArray[] = new int[neighbors.size()]; ! for (NetworkVertex n:neighbors){ ! neighborsArray[j++] = rcVertices.indexOf(n); } + // sort by value orderboolean activatePrediction + Arrays.sort(neighborsArray, 0, j); + // define according edges + int[] edgesArray = new int[j]; + for (int e=0; e < j; e++) { + NetworkVertex n = rcVertices.get(neighborsArray[e]); + edgesArray[e] = rcEdges.indexOf(rcGraph.getEdge(v, n)); + } + rc.setVertexNeighbors(id, neighborsArray, edgesArray); + // } } *************** *** 403,407 **** // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrainType(), phase)) { value += bonus.getValue(); } --- 405,409 ---- // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrain(), phase)) { value += bonus.getValue(); } *************** *** 419,423 **** // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrainType(), phase)) { s.append("+" + bonus.getValue()); } --- 421,425 ---- // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrain(), phase)) { s.append("+" + bonus.getValue()); } Index: NetworkGraphBuilder.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkGraphBuilder.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NetworkGraphBuilder.java 14 May 2010 15:19:57 -0000 1.10 --- NetworkGraphBuilder.java 20 May 2010 19:57:01 -0000 1.11 *************** *** 169,172 **** --- 169,174 ---- for (NetworkVertex vertex:tokenVertexes){ + // allow to leave tokenVertices even if those are sinks + boolean storeSink = vertex.isSink(); vertex.setSink(false); vertexes.add(vertex); // add connection to graph *************** *** 176,179 **** --- 178,183 ---- for (;iterator.hasNext();) vertexes.add(iterator.next()); + // restore sink property + vertex.setSink(storeSink); } Index: RevenueTrainRun.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueTrainRun.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RevenueTrainRun.java 19 May 2010 20:14:13 -0000 1.3 --- RevenueTrainRun.java 20 May 2010 19:57:01 -0000 1.4 *************** *** 8,12 **** import org.apache.log4j.Logger; - import rails.game.MapHex; import rails.ui.swing.hexmap.HexMap; --- 8,11 ---- *************** *** 51,55 **** // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrainType(), revenueAdapter.getPhase())) { value += bonus.getValue(); } --- 50,54 ---- // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrain(), revenueAdapter.getPhase())) { value += bonus.getValue(); } *************** *** 81,99 **** int initLength = runPrettyPrint.length(); int multiple = runPrettyPrint.length() / PRETTY_PRINT_LENGTH; ! MapHex currentHex = null; NetworkVertex startVertex = null; for (NetworkVertex vertex:vertices) { if (startVertex == null) { ! currentHex = vertex.getHex(); startVertex = vertex; runPrettyPrint.append(prettyPrintHexName(vertex) + "("); } else if (startVertex == vertex) { ! currentHex = vertex.getHex(); runPrettyPrint.append(") / "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); runPrettyPrint.append(prettyPrintHexName(vertex) + "(0"); continue; ! } else if (vertex.getHex() != currentHex) { ! currentHex = vertex.getHex(); runPrettyPrint.append("), "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); --- 80,98 ---- int initLength = runPrettyPrint.length(); int multiple = runPrettyPrint.length() / PRETTY_PRINT_LENGTH; ! String currentHexName = null; NetworkVertex startVertex = null; for (NetworkVertex vertex:vertices) { if (startVertex == null) { ! currentHexName = prettyPrintHexName(vertex); startVertex = vertex; runPrettyPrint.append(prettyPrintHexName(vertex) + "("); } else if (startVertex == vertex) { ! currentHexName = prettyPrintHexName(vertex); runPrettyPrint.append(") / "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); runPrettyPrint.append(prettyPrintHexName(vertex) + "(0"); continue; ! } else if (!currentHexName.equals(prettyPrintHexName(vertex))) { ! currentHexName = prettyPrintHexName(vertex); runPrettyPrint.append("), "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); *************** *** 105,113 **** runPrettyPrint.append(revenueAdapter.getVertexValueAsString(vertex, train, revenueAdapter.getPhase())); } else { ! runPrettyPrint.append(currentHex.getOrientationName(vertex.getSide())); } } ! if (currentHex != null) { runPrettyPrint.append(")"); } --- 104,112 ---- runPrettyPrint.append(revenueAdapter.getVertexValueAsString(vertex, train, revenueAdapter.getPhase())); } else { ! runPrettyPrint.append(vertex.getHex().getOrientationName(vertex.getSide())); } } ! if (currentHexName != null) { runPrettyPrint.append(")"); } *************** *** 115,119 **** // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrainType(), revenueAdapter.getPhase())) { runPrettyPrint.append(" + "); runPrettyPrint.append(bonus.getName() + "(" + bonus.getValue() + ")"); --- 114,118 ---- // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrain(), revenueAdapter.getPhase())) { runPrettyPrint.append(" + "); runPrettyPrint.append(bonus.getName() + "(" + bonus.getValue() + ")"); Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NetworkTrain.java 18 May 2010 21:36:12 -0000 1.7 --- NetworkTrain.java 20 May 2010 19:57:01 -0000 1.8 *************** *** 17,25 **** private final int multiplyMinors; private final String trainName; ! private final TrainTypeI railsTrainType; NetworkTrain(int majors, int minors, boolean ignoreMinors, ! int multiplyMajors, int multiplyMinors, String trainName, ! TrainTypeI trainType) { this.majors = majors; this.minors = minors; --- 17,25 ---- private final int multiplyMinors; private final String trainName; ! private final TrainI railsTrain; ! NetworkTrain(int majors, int minors, boolean ignoreMinors, ! int multiplyMajors, int multiplyMinors, String trainName, TrainI train) { this.majors = majors; this.minors = minors; *************** *** 28,32 **** this.multiplyMinors = multiplyMinors; this.trainName = trainName; ! this.railsTrainType = trainType; log.info("Created NetworkTrain " + this.toString() + " / " + this.attributes()); } --- 28,32 ---- this.multiplyMinors = multiplyMinors; this.trainName = trainName; ! this.railsTrain = train; log.info("Created NetworkTrain " + this.toString() + " / " + this.attributes()); } *************** *** 45,49 **** } String trainName = railsTrain.getName(); - TrainTypeI trainType = railsTrain.getType(); if (majors == -1) { --- 45,48 ---- *************** *** 51,55 **** } else { return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, ! trainName, trainType); } } --- 50,54 ---- } else { return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, ! trainName, railsTrain); } } *************** *** 116,122 **** } ! TrainTypeI getRailsTrainType() { ! return railsTrainType; } public String attributes() { --- 115,126 ---- } ! public TrainI getRailsTrain() { ! return railsTrain; } + + public TrainTypeI getRailsTrainType() { + return railsTrain.getType(); + } + public String attributes() { |
From: Stefan F. <ste...@us...> - 2010-05-20 19:57:09
|
Update of /cvsroot/rails/18xx/data/18AL In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22874/data/18AL Modified Files: Game.xml Log Message: Revenue Calculator support for 18AL and various other fixes Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/18AL/Game.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Game.xml 19 May 2010 20:14:13 -0000 1.29 --- Game.xml 20 May 2010 19:57:01 -0000 1.30 *************** *** 105,108 **** --- 105,109 ---- </Component> <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> + <StaticModifier class="rails.game.specific._18AL.NamedTrainRevenueModifier" /> </Component> </ComponentManager> \ No newline at end of file |
From: Stefan F. <ste...@us...> - 2010-05-20 19:57:09
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18AL In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22874/rails/game/specific/_18AL Modified Files: NamedTrainToken.java Added Files: NamedTrainRevenueModifier.java Log Message: Revenue Calculator support for 18AL and various other fixes Index: NamedTrainToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18AL/NamedTrainToken.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NamedTrainToken.java 31 Jan 2010 22:22:33 -0000 1.5 --- NamedTrainToken.java 20 May 2010 19:57:01 -0000 1.6 *************** *** 3,11 **** import java.util.List; import rails.game.*; import rails.util.Tag; import rails.util.Util; ! public class NamedTrainToken extends Token implements ConfigurableComponentI { private String name; --- 3,21 ---- import java.util.List; + import org.apache.log4j.Logger; + + import rails.algorithms.NetworkVertex; + import rails.algorithms.RevenueAdapter; + import rails.algorithms.RevenueBonus; + import rails.algorithms.RevenueManager; + import rails.algorithms.RevenueStaticModifier; import rails.game.*; import rails.util.Tag; import rails.util.Util; ! public class NamedTrainToken extends Token implements ConfigurableComponentI /*, RevenueStaticModifier */ { ! ! protected static Logger log = ! Logger.getLogger(NamedTrainToken.class.getPackage().getName()); private String name; *************** *** 51,54 **** --- 61,68 ---- hexes = gameManager.getMapManager().parseLocations(hexesString); } + + // add them to the call list of the RevenueManager + // GameManager.getInstance().getRevenueManager().addStaticModifier(this); + } *************** *** 74,76 **** --- 88,109 ---- } + // public void modifyCalculator(RevenueAdapter revenueAdapter) { + // + // // 1. check if holder is a NameableTrain + // if (!(this.holder instanceof NameableTrain)) return; + // NameableTrain train = (NameableTrain)this.holder; + // + // // 2. check if operating company is owner of the train + // if (train.getOwner() == revenueAdapter.getCompany()) { + // // 2. define revenue bonus + // RevenueBonus bonus = new RevenueBonus(value, name); + // bonus.addTrain(train); + // for (NetworkVertex vertex:NetworkVertex.getVerticesByHexes(revenueAdapter.getVertices(), hexes)) { + // if (!vertex.isStation()) continue; + // bonus.addVertex(vertex); + // } + // revenueAdapter.addRevenueBonus(bonus); + // } + // } + } --- NEW FILE: NamedTrainRevenueModifier.java --- package rails.game.specific._18AL; import rails.algorithms.NetworkTrain; import rails.algorithms.NetworkVertex; import rails.algorithms.RevenueAdapter; import rails.algorithms.RevenueBonus; import rails.algorithms.RevenueStaticModifier; import rails.game.TrainI; public class NamedTrainRevenueModifier implements RevenueStaticModifier { public void modifyCalculator(RevenueAdapter revenueAdapter) { // 1. check all Trains for name Tokens for (NetworkTrain networkTrain:revenueAdapter.getTrains()) { TrainI train = networkTrain.getRailsTrain(); if (!(train instanceof NameableTrain)) continue; NamedTrainToken token = ((NameableTrain)train).getNameToken(); if (token == null) continue; // 2. define revenue bonus RevenueBonus bonus = new RevenueBonus(token.getValue(), token.getName()); bonus.addTrain(train); for (NetworkVertex vertex:NetworkVertex.getVerticesByHexes(revenueAdapter.getVertices(), token.getHexesToPass())) { if (!vertex.isStation()) continue; bonus.addVertex(vertex); } revenueAdapter.addRevenueBonus(bonus); } } } |
From: Stefan F. <ste...@us...> - 2010-05-20 19:57:09
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22874/rails/game/specific/_18EU Modified Files: OffBoardRevenueModifier.java Log Message: Revenue Calculator support for 18AL and various other fixes Index: OffBoardRevenueModifier.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OffBoardRevenueModifier.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OffBoardRevenueModifier.java 19 May 2010 20:14:13 -0000 1.1 --- OffBoardRevenueModifier.java 20 May 2010 19:57:01 -0000 1.2 *************** *** 43,47 **** bonusValue = 20; } else if (phase.isTileColourAllowed("green")) { ! bonusValue = 100; } else { return; --- 43,47 ---- bonusValue = 20; } else if (phase.isTileColourAllowed("green")) { ! bonusValue = 10; } else { return; *************** *** 62,66 **** if (hamburgCity != null) { // ... and duplicate the vertex ! NetworkVertex hamburgTerminal = NetworkVertex.duplicateVertex(revenueAdapter.getGraph(), hamburgCity, "Hamburg(T)", true); hamburgTerminal.setSink(true); offBoard.add(hamburgTerminal); --- 62,66 ---- if (hamburgCity != null) { // ... and duplicate the vertex ! NetworkVertex hamburgTerminal = NetworkVertex.duplicateVertex(revenueAdapter.getGraph(), hamburgCity, "B7", true); hamburgTerminal.setSink(true); offBoard.add(hamburgTerminal); |