From: <ste...@us...> - 2010-10-16 22:43:32
|
Revision: 1452 http://rails.svn.sourceforge.net/rails/?rev=1452&view=rev Author: stefanfrey Date: 2010-10-16 22:43:25 +0000 (Sat, 16 Oct 2010) Log Message: ----------- Added ScoreTileOnlyOnceModifier for 1825 A few minor fixes Modified Paths: -------------- trunk/18xx/rails/algorithms/RevenueAdapter.java trunk/18xx/rails/algorithms/RevenueTrainRun.java trunk/18xx/rails/game/specific/_1825/DoubleHeadingModifier.java Added Paths: ----------- trunk/18xx/rails/game/specific/_1825/ScoreTileOnlyOnceModifier.java Modified: trunk/18xx/rails/algorithms/RevenueAdapter.java =================================================================== --- trunk/18xx/rails/algorithms/RevenueAdapter.java 2010-10-14 22:34:21 UTC (rev 1451) +++ trunk/18xx/rails/algorithms/RevenueAdapter.java 2010-10-16 22:43:25 UTC (rev 1452) @@ -272,7 +272,6 @@ List<RevenueBonusTemplate> tileBonuses = hex.getCurrentTile().getRevenueBonuses(); if (tileBonuses != null) bonuses.addAll(tileBonuses); - if (bonuses == null) continue; for (RevenueBonusTemplate bonus:bonuses) { addRevenueBonus(bonus.toRevenueBonus(hex, gameManager, graphBuilder)); } Modified: trunk/18xx/rails/algorithms/RevenueTrainRun.java =================================================================== --- trunk/18xx/rails/algorithms/RevenueTrainRun.java 2010-10-14 22:34:21 UTC (rev 1451) +++ trunk/18xx/rails/algorithms/RevenueTrainRun.java 2010-10-16 22:43:25 UTC (rev 1452) @@ -139,7 +139,7 @@ NetworkEdge previousEdge = null; NetworkVertex startVertex = null; for (NetworkEdge edge:edges) { - log.info("Processing edge " + edge.toFullInfoString() ); + log.debug("Processing edge " + edge.toFullInfoString() ); // process startEdge if (previousEdge == null) { previousEdge = edge; @@ -151,7 +151,7 @@ if (startVertex == null) { // if there is a joint route => other vertex of previousEdge if (commonVertex != null) { - log.info("Head Run"); + log.debug("Head Run"); startVertex = previousEdge.getOtherVertex(commonVertex); vertices.add(startVertex); vertices.add(commonVertex); @@ -162,12 +162,12 @@ } else { // start vertex is known // if there is a common vertex => continuous route if (commonVertex != null) { - log.info("Added common vertex"); + log.debug("Added common vertex"); vertices.add(commonVertex); } else { // otherwise it is bottom run // add the last vertex of the head train - log.info("Bottom Run"); + log.debug("Bottom Run"); vertices.add(previousEdge.getOtherVertex(vertices.get(vertices.size()-1))); vertices.add(startVertex); } @@ -176,7 +176,7 @@ } // add the last vertex of the route vertices.add(previousEdge.getOtherVertex(vertices.get(vertices.size()-1))); - log.info("Converted edges to vertices " + vertices); + log.debug("Converted edges to vertices " + vertices); } /** defines the edges from the list of vertices */ Modified: trunk/18xx/rails/game/specific/_1825/DoubleHeadingModifier.java =================================================================== --- trunk/18xx/rails/game/specific/_1825/DoubleHeadingModifier.java 2010-10-14 22:34:21 UTC (rev 1451) +++ trunk/18xx/rails/game/specific/_1825/DoubleHeadingModifier.java 2010-10-16 22:43:25 UTC (rev 1452) @@ -2,14 +2,8 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; -import org.apache.log4j.Logger; - import rails.algorithms.NetworkTrain; import rails.algorithms.RevenueAdapter; import rails.algorithms.RevenueDynamicModifier; @@ -21,9 +15,6 @@ */ public class DoubleHeadingModifier implements RevenueDynamicModifier { - protected static Logger log = - Logger.getLogger(DoubleHeadingModifier.class.getPackage().getName()); - private final static String TRAIN_2_NAME = "2"; private final static String DUALHEAD_NAME = "2&2"; @@ -68,8 +59,6 @@ } Collections.sort(train2Runs); - log.debug("Train2Runs=" + train2Runs); - // keep index on train2Runs int index2Runs = 0; // find DualHeads and remove two 2-train revenues Added: trunk/18xx/rails/game/specific/_1825/ScoreTileOnlyOnceModifier.java =================================================================== --- trunk/18xx/rails/game/specific/_1825/ScoreTileOnlyOnceModifier.java (rev 0) +++ trunk/18xx/rails/game/specific/_1825/ScoreTileOnlyOnceModifier.java 2010-10-16 22:43:25 UTC (rev 1452) @@ -0,0 +1,40 @@ +package rails.game.specific._1825; + +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.List; + +import rails.algorithms.NetworkVertex; +import rails.algorithms.RevenueAdapter; +import rails.algorithms.RevenueStaticModifier; +import rails.game.MapHex; + +/** + * This modifier ensures that on each tile only one station can be visited + */ + +public class ScoreTileOnlyOnceModifier implements RevenueStaticModifier { + + public void modifyCalculator(RevenueAdapter revenueAdapter) { + // 1. define for each hex a list of stations + HashMap<MapHex, List<NetworkVertex>> hexStations = new HashMap<MapHex, List<NetworkVertex>>(); + for (NetworkVertex v:revenueAdapter.getVertices()) { + if (v.isStation()) { + if (!hexStations.containsKey(v.getHex())) { + List<NetworkVertex> stations = new ArrayList<NetworkVertex>(); + hexStations.put(v.getHex(), stations); + } + hexStations.get(v.getHex()).add(v); + } + } + // 2. convert those with more than one station to a vertex visit set + for (MapHex hex:hexStations.keySet()) { + if (hexStations.get(hex).size() >= 2) { + revenueAdapter.addVertexVisitSet(revenueAdapter.new VertexVisit(hexStations.get(hex))); + } + } + + } + +} Property changes on: trunk/18xx/rails/game/specific/_1825/ScoreTileOnlyOnceModifier.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |