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-04-20 20:18:25
|
Update of /cvsroot/rails/18xx In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv12186 Modified Files: my.properties Log Message: Added INFO logging for algorithm package Index: my.properties =================================================================== RCS file: /cvsroot/rails/18xx/my.properties,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** my.properties 29 Jan 2010 23:49:56 -0000 1.14 --- my.properties 20 Apr 2010 20:18:17 -0000 1.15 *************** *** 117,120 **** --- 117,121 ---- #log4j.debug=true log4j.rootLogger=DEBUG, F + log4j.logger.rails.algorithms=INFO # Define the Log file appender |
From: Stefan F. <ste...@us...> - 2010-04-20 20:18:02
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv12106/rails/ui/swing/hexmap Modified Files: GUIHex.java Log Message: Changed highlighting for selectable hexes Index: GUIHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUIHex.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** GUIHex.java 20 Apr 2010 19:45:40 -0000 1.42 --- GUIHex.java 20 Apr 2010 20:17:51 -0000 1.43 *************** *** 23,26 **** --- 23,27 ---- public static final double SQRT3 = Math.sqrt(3.0); public static double NORMAL_SCALE = 1.0; + public static double SELECTABLE_SCALE = 0.9; public static double SELECTED_SCALE = 0.8; *************** *** 34,44 **** public static void setScale(double scale) { NORMAL_SCALE = scale; SELECTED_SCALE = 0.8 * scale; } protected MapHex model; ! protected GeneralPath innerHexagon; protected static final Color highlightColor = Color.red; ! protected static final Color upgradableColor = Color.magenta; protected Point center; /** x and y coordinates on the map */ --- 35,47 ---- public static void setScale(double scale) { NORMAL_SCALE = scale; + SELECTABLE_SCALE = 0.9 * scale; SELECTED_SCALE = 0.8 * scale; } protected MapHex model; ! protected GeneralPath innerHexagonSelected; ! protected GeneralPath innerHexagonSelectable; protected static final Color highlightColor = Color.red; ! protected static final Color selectableColor = Color.red; protected Point center; /** x and y coordinates on the map */ *************** *** 154,161 **** (yVertex[0] + yVertex[3]) / 2.0); ! final double innerScale = 0.8; AffineTransform at = AffineTransform.getScaleInstance(innerScale, innerScale); ! innerHexagon = (GeneralPath) hexagon.createTransformedShape(at); // Translate innerHexagon to make it concentric. --- 157,169 ---- (yVertex[0] + yVertex[3]) / 2.0); ! innerHexagonSelected = defineInnerHexagon(0.8, center2D); ! innerHexagonSelectable = defineInnerHexagon(0.9, center2D); ! } ! ! private GeneralPath defineInnerHexagon(double innerScale, Point2D.Double center2D) { ! AffineTransform at = AffineTransform.getScaleInstance(innerScale, innerScale); ! GeneralPath innerHexagon = (GeneralPath) hexagon.createTransformedShape(at); // Translate innerHexagon to make it concentric. *************** *** 171,174 **** --- 179,194 ---- innerHexagon.transform(at); + return innerHexagon; + } + + /** + * returns point that corresponds to the definition as networkvertex + */ + public Point getHexPoint(int side){ + if (side >= 0) { // side + return new Point((int) xVertex[side],(int) yVertex[side]); + } else { // station + return getTokenCenter(0, 0, 0, -side); + } } *************** *** 254,258 **** this.selectable = selectable; if (selectable) { ! currentGUITile.setScale(SELECTED_SCALE); } else { currentGUITile.setScale(NORMAL_SCALE); --- 274,278 ---- this.selectable = selectable; if (selectable) { ! currentGUITile.setScale(SELECTABLE_SCALE); } else { currentGUITile.setScale(NORMAL_SCALE); *************** *** 327,342 **** Color terrainColor = Color.WHITE; ! if (isSelected() || isSelectable()) { ! if (isSelected()) ! g2.setColor(highlightColor); ! else ! g2.setColor(upgradableColor); g2.fill(hexagon); g2.setColor(terrainColor); ! g2.fill(innerHexagon); g2.setColor(Color.black); ! g2.draw(innerHexagon); } --- 347,368 ---- Color terrainColor = Color.WHITE; ! if (isSelected()) { ! g2.setColor(highlightColor); g2.fill(hexagon); g2.setColor(terrainColor); ! g2.fill(innerHexagonSelected); g2.setColor(Color.black); ! g2.draw(innerHexagonSelected); ! } else if (isSelectable()) { ! g2.setColor(selectableColor); ! g2.fill(hexagon); ! ! g2.setColor(terrainColor); ! g2.fill(innerHexagonSelectable); ! ! g2.setColor(Color.black); ! g2.draw(innerHexagonSelectable); } |
From: Stefan F. <ste...@us...> - 2010-04-20 19:45:49
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8480/rails/ui/swing Modified Files: ORPanel.java Log Message: First implementation to visualize revenue runs on the map Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** ORPanel.java 19 Apr 2010 19:35:38 -0000 1.57 --- ORPanel.java 20 Apr 2010 19:45:40 -0000 1.58 *************** *** 4,7 **** --- 4,8 ---- import java.awt.*; import java.awt.event.*; + import java.awt.geom.GeneralPath; import java.util.List; *************** *** 17,20 **** --- 18,22 ---- import rails.game.action.*; import rails.ui.swing.elements.*; + import rails.ui.swing.hexmap.HexMap; import rails.util.LocalText; import rails.util.Util; *************** *** 603,609 **** Graph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); ! NetworkGraphBuilder.visualize(graph, "Network of " + companyName); graph = NetworkGraphBuilder.optimizeGraph(graph); ! NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); // revenue calculation example on mapGraph --- 605,611 ---- Graph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); ! // NetworkGraphBuilder.visualize(graph, "Network of " + companyName); graph = NetworkGraphBuilder.optimizeGraph(graph); ! // NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); // revenue calculation example on mapGraph *************** *** 626,646 **** boolean anotherTrain = true; while (anotherTrain) { // create results // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), false); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), false); ! log.info("Revenue Adapter:" + ra); ! int revenueValue = ra.calculateRevenue(); ! log.info("Revenue Value:" + revenueValue); ! log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ! JOptionPane.showMessageDialog(orWindow, "Without Prediction: RevenueValue = " + revenueValue + ! "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); ! ra.refreshRevenueCalculator(); ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); JOptionPane.showMessageDialog(orWindow, "With Prediction: RevenueValue = " + revenueValue + "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); --- 628,652 ---- boolean anotherTrain = true; while (anotherTrain) { + int revenueValue; // create results // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), false); ! // ra.populateRevenueCalculator(company, gm.getCurrentPhase(), false); ! // log.info("Revenue Adapter:" + ra); ! // revenueValue = ra.calculateRevenue(); ! // log.info("Revenue Value:" + revenueValue); ! // log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ! // JOptionPane.showMessageDialog(orWindow, "Without Prediction: RevenueValue = " + revenueValue + ! // "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); ! // ! // ra.refreshRevenueCalculator(); ! ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! // ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); + ra.drawOptimalRunAsPath(orUIManager.getMap()); + orUIManager.getMap().repaint(); JOptionPane.showMessageDialog(orWindow, "With Prediction: RevenueValue = " + revenueValue + "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); *************** *** 840,843 **** --- 846,851 ---- revenueSelect[orCompIndex].setValue(bestRevenue); if (finalResult) { + revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); + orUIManager.getMap().repaint(); JOptionPane.showMessageDialog(orWindow, "Best Run Value = " + bestRevenue + "\n" + revenueAdapter.getOptimalRunPrettyPrint()); *************** *** 846,849 **** --- 854,858 ---- public void stopRevenueUpdate() { + orUIManager.getMap().setTrainPaths(null); revenueAdapter.removeRevenueListener(); revenueAdapter = null; |
From: Stefan F. <ste...@us...> - 2010-04-20 19:45:48
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8480/rails/algorithms Modified Files: RevenueCalculator.java RevenueAdapter.java NetworkEdge.java NetworkVertex.java Log Message: First implementation to visualize revenue runs on the map Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RevenueCalculator.java 19 Apr 2010 19:35:38 -0000 1.5 --- RevenueCalculator.java 20 Apr 2010 19:45:40 -0000 1.6 *************** *** 30,34 **** private final int[] trainMaxCities; private final int[] trainMaxTowns; ! private final boolean[] trainTownsCostNothing; private final int[] trainMultiplyCities; private final int[] trainMultiplyTowns; --- 30,34 ---- private final int[] trainMaxCities; private final int[] trainMaxTowns; ! private final boolean[] trainIgnoreTowns; private final int[] trainMultiplyCities; private final int[] trainMultiplyTowns; *************** *** 65,68 **** --- 65,76 ---- private RevenueAdapter revenueAdapter; + // termination results + private static enum Terminated { + WithEvaluation, + WithoutEvaluation, + NotYet + + } + protected static Logger log = Logger.getLogger(RevenueCalculator.class.getPackage().getName()); *************** *** 90,94 **** trainCities = new int[nbTrains]; trainTowns = new int[nbTrains]; ! trainTownsCostNothing = new boolean[nbTrains]; trainMultiplyCities = new int[nbTrains]; trainMultiplyTowns = new int[nbTrains]; --- 98,102 ---- trainCities = new int[nbTrains]; trainTowns = new int[nbTrains]; ! trainIgnoreTowns = new boolean[nbTrains]; trainMultiplyCities = new int[nbTrains]; trainMultiplyTowns = new int[nbTrains]; *************** *** 125,132 **** } ! void setTrain(int id, int cities, int towns, boolean townsCostNothing, int multiplyCities, int multiplyTowns) { trainMaxCities[id] = cities; trainMaxTowns[id] = towns; ! trainTownsCostNothing[id] = townsCostNothing; trainMultiplyCities[id] = multiplyCities; trainMultiplyTowns[id] = multiplyTowns; --- 133,140 ---- } ! void setTrain(int id, int cities, int towns, boolean ingoreTowns, int multiplyCities, int multiplyTowns) { trainMaxCities[id] = cities; trainMaxTowns[id] = towns; ! trainIgnoreTowns[id] = ingoreTowns; trainMultiplyCities[id] = multiplyCities; trainMultiplyTowns[id] = multiplyTowns; *************** *** 198,217 **** // encounterVertex adds value and returns true if value vertex ! boolean trainTerminated = false; ! if (encounterVertex(trainId, vertexId, true)) { ! if (useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); continue; - } else { - // check usual train termination - trainTerminated = trainTerminated(trainId); } } // and all edges of it ! boolean evaluateResult = true; ! if (!trainTerminated) { for (int j = 0; j < maxNeighbors; j++) { int neighborId = vertexNeighbors[vertexId][j]; --- 206,225 ---- // encounterVertex adds value and returns true if value vertex ! Terminated trainTerminated = Terminated.NotYet; ! boolean valueStation = encounterVertex(trainId, vertexId, true); ! if (valueStation) { ! // check usual train termination ! trainTerminated = trainTerminated(trainId); ! if (trainTerminated == Terminated.WithoutEvaluation || ! trainTerminated == Terminated.NotYet && useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); continue; } } // and all edges of it ! if (trainTerminated == Terminated.NotYet) { for (int j = 0; j < maxNeighbors; j++) { int neighborId = vertexNeighbors[vertexId][j]; *************** *** 219,223 **** if (neighborId == -1) break; // no more neighbors if (travelEdge(vertexId, neighborId, true)) { - evaluateResult = false; trainStartEdge[trainId] = j; // store edge nextVertex(trainId, neighborId, vertexId); --- 227,230 ---- *************** *** 227,231 **** // no more edges to find ! finalizeVertex(trainId, vertexId, evaluateResult); encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); --- 234,238 ---- // no more edges to find ! finalizeVertex(trainId, vertexId, valueStation); encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); *************** *** 270,289 **** // 1. encounterVertex adds value and returns true if value vertex ! boolean trainTerminated = false; ! if (encounterVertex(trainId, vertexId, true)) { ! if (useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); returnEdge(trainId); return; - } else { - // check usual train termination - trainTerminated = trainTerminated(trainId); } } // 2a. visit neighbors, if train has not terminated ! boolean evaluateResult = true; ! if (!trainTerminated) { for (int j = 0; j < maxNeighbors; j++) { int neighborId = vertexNeighbors[vertexId][j]; --- 277,296 ---- // 1. encounterVertex adds value and returns true if value vertex ! Terminated trainTerminated = Terminated.NotYet; ! boolean valueStation = encounterVertex(trainId, vertexId, true); ! if (valueStation) { ! // check usual train termination ! trainTerminated = trainTerminated(trainId); ! if (trainTerminated == Terminated.WithoutEvaluation || ! trainTerminated == Terminated.NotYet && useRevenuePrediction && predictRevenues(trainId)) { // 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 < maxNeighbors; j++) { int neighborId = vertexNeighbors[vertexId][j]; *************** *** 295,304 **** } if (travelEdge(vertexId, neighborId, edgeGreedy[previousId][vertexId])) { - evaluateResult = false; nextVertex(trainId, neighborId, vertexId); } } // 2b. restart at startVertex for bottom part ! if (trainBottomPos[trainId] == 0 && (vertexCity[vertexId] || vertexTown[vertexId])){ runBottom(trainId); } --- 302,310 ---- } if (travelEdge(vertexId, neighborId, edgeGreedy[previousId][vertexId])) { nextVertex(trainId, neighborId, vertexId); } } // 2b. restart at startVertex for bottom part ! if (valueStation && trainBottomPos[trainId] == 0 && (vertexCity[vertexId] || vertexTown[vertexId])){ runBottom(trainId); } *************** *** 306,310 **** // 3. no more edges to visit from here => evaluate or start new train ! finalizeVertex(trainId, vertexId, evaluateResult); // 4. then leave that vertex --- 312,316 ---- // 3. no more edges to visit from here => evaluate or start new train ! finalizeVertex(trainId, vertexId, valueStation); // 4. then leave that vertex *************** *** 326,330 **** trainCurrentValue[trainId] += vertexValue[vertexId] * trainMultiplyCities[trainId]; valueVertex = true; ! } else if (vertexTown[vertexId]) { trainTowns[trainId]++; trainCurrentValue[trainId] += vertexValue[vertexId] * trainMultiplyTowns[trainId]; --- 332,336 ---- trainCurrentValue[trainId] += vertexValue[vertexId] * trainMultiplyCities[trainId]; valueVertex = true; ! } else if (vertexTown[vertexId] && !trainIgnoreTowns[trainId]) { trainTowns[trainId]++; trainCurrentValue[trainId] += vertexValue[vertexId] * trainMultiplyTowns[trainId]; *************** *** 338,342 **** trainCurrentValue[trainId] -= vertexValue[vertexId] * trainMultiplyCities[trainId]; valueVertex = true; ! } else if (vertexTown[vertexId]) { trainTowns[trainId]--; trainCurrentValue[trainId] -= vertexValue[vertexId] * trainMultiplyTowns[trainId]; --- 344,348 ---- trainCurrentValue[trainId] -= vertexValue[vertexId] * trainMultiplyCities[trainId]; valueVertex = true; ! } else if (vertexTown[vertexId] && !trainIgnoreTowns[trainId] ) { trainTowns[trainId]--; trainCurrentValue[trainId] -= vertexValue[vertexId] * trainMultiplyTowns[trainId]; *************** *** 394,416 **** } ! private boolean trainTerminated(int trainId) { ! boolean terminated; ! if (trainTownsCostNothing[trainId]) { ! terminated = trainCities[trainId] == trainMaxCities[trainId]; } else if (trainTowns[trainId] == 0) { // default train ! terminated = trainCities[trainId] + trainTowns[trainId] == trainMaxCities[trainId]; } else { // plus trains ! int townDiff = trainMaxTowns[trainId] - trainTowns[trainId]; ! if (townDiff > 0) { ! terminated = false; ! } else if (townDiff == 0) { ! terminated = trainCities[trainId] == trainMaxCities[trainId]; ! } else { // negative townDiff, thus too many towns already visited ! terminated = trainCities[trainId] == trainMaxCities[trainId] + townDiff; ! } } ! if (terminated) { log.debug ("RC: Train " + trainId + " has terminated: " + "cities = " + trainCities[trainId] + " towns = " + trainTowns[trainId] + --- 400,422 ---- } ! private Terminated trainTerminated(int trainId) { ! Terminated terminated = Terminated.NotYet; ! if (trainIgnoreTowns[trainId]) { ! // express trains ! if (trainCities[trainId] == trainMaxCities[trainId]) ! terminated = Terminated.WithEvaluation; } else if (trainTowns[trainId] == 0) { // default train ! if (trainCities[trainId] + trainTowns[trainId] == trainMaxCities[trainId]) ! terminated = Terminated.WithEvaluation; } else { // plus trains ! if (trainCities[trainId] > trainMaxCities[trainId]){ ! terminated = Terminated.WithoutEvaluation; ! } else if (trainCities[trainId] + trainTowns[trainId] == ! trainMaxCities[trainId] + trainMaxTowns[trainId] ) ! terminated = Terminated.WithEvaluation; } ! if (terminated != Terminated.NotYet) { log.debug ("RC: Train " + trainId + " has terminated: " + "cities = " + trainCities[trainId] + " towns = " + trainTowns[trainId] + *************** *** 474,481 **** trainValue = maxTrainRevenues[j]; } else { // the current train ! if (trainTownsCostNothing[j]) { ! // still TODO ! trainValue = 0; ! } else if (trainTowns[j] == 0) { // default train trainValue = trainCurrentValue[j] + --- 480,484 ---- trainValue = maxTrainRevenues[j]; } else { // the current train ! if (trainMaxTowns[j] == 0) { // default train trainValue = trainCurrentValue[j] + *************** *** 524,527 **** --- 527,531 ---- buffer.append("trainMaxCities:" + Arrays.toString(trainMaxCities) + "\n"); buffer.append("trainMaxTowns:" + Arrays.toString(trainMaxTowns) + "\n"); + buffer.append("trainIgnoreTowns:" + Arrays.toString(trainIgnoreTowns) + "\n"); buffer.append("maxCityRevenues:" + Arrays.toString(maxCityRevenues) + "\n"); buffer.append("maxTownRevenues:" + Arrays.toString(maxTownRevenues) + "\n"); Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NetworkVertex.java 16 Apr 2010 16:38:21 -0000 1.6 --- NetworkVertex.java 20 Apr 2010 19:45:40 -0000 1.7 *************** *** 1,4 **** --- 1,5 ---- package rails.algorithms; + import java.awt.geom.Point2D; import java.util.Collection; import java.util.Comparator; *************** *** 14,17 **** --- 15,20 ---- import rails.game.Station; import rails.game.TokenI; + import rails.ui.swing.hexmap.GUIHex; + import rails.ui.swing.hexmap.HexMap; public final class NetworkVertex implements Comparable<NetworkVertex> { *************** *** 28,31 **** --- 31,35 ---- private final Station station; + private final City city; private final int side; *************** *** 51,54 **** --- 55,59 ---- if (t.equals(Station.TOWN)){ this.tokenable = false; + this.city = null; } else { this.tokenable = true; *************** *** 57,62 **** --- 62,69 ---- this.tokenSlots = 0; List<City> cities = hex.getCities(); + City foundCity = null; for (City city:cities) { if (station == city.getRelatedStation()) { + foundCity = city; tokens = city.getTokens(); this.tokenSlots = city.getSlots(); *************** *** 64,67 **** --- 71,75 ---- } } + this.city = foundCity; this.companiesHaveToken = new HashSet<PublicCompanyI>(); if (tokens != null) { *************** *** 80,83 **** --- 88,92 ---- this.hex = hex; this.station = null; + this.city = null; this.side = (side % 6); *************** *** 92,95 **** --- 101,105 ---- this.hex = null; this.station = null; + this.city = null; this.side = 0; *************** *** 133,136 **** --- 143,151 ---- } + public City getCity() { + return city; + } + + public int getSide(){ return side; *************** *** 256,259 **** --- 271,288 ---- v.setPhase(phase); } + + public static Point2D getVertexPoint2D(HexMap map, NetworkVertex vertex) { + GUIHex guiHex = map.getHexByName(vertex.getHex().getName()); + if (vertex.isCityType()) { + return guiHex.getCityPoint2D(vertex.getCity()); + } else if (vertex.isTownType()) { + return guiHex.getCenterPoint2D(); + } else if (vertex.isSide()) { + return guiHex.getSidePoint2D(vertex.getSide()); + } else { + return null; + } + } + } Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RevenueAdapter.java 19 Apr 2010 19:35:38 -0000 1.5 --- RevenueAdapter.java 20 Apr 2010 19:45:40 -0000 1.6 *************** *** 2,5 **** --- 2,8 ---- import java.awt.EventQueue; + import java.awt.Graphics2D; + import java.awt.geom.GeneralPath; + import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Arrays; *************** *** 20,23 **** --- 23,27 ---- import rails.game.TokenI; import rails.game.TrainI; + import rails.ui.swing.hexmap.HexMap; *************** *** 203,207 **** String t = trainString.trim(); ! int cities = 0; int towns = 0; boolean townsCostNothing = false; int multiplyCities = 1; int multiplyTowns = 1; if (t.equals("D")) { cities = 99; // diesel --- 207,211 ---- String t = trainString.trim(); ! int cities = 0; int towns = 0; boolean ignoreTowns = false; int multiplyCities = 1; int multiplyTowns = 1; if (t.equals("D")) { cities = 99; // diesel *************** *** 212,221 **** // express train cities = Integer.parseInt(t.replace("E", "")); ! townsCostNothing = true; multiplyTowns = 0; } else if (t.contains("D")) { // double (express) train cities = Integer.parseInt(t.replace("D", "")); ! townsCostNothing = true; multiplyCities = 2; multiplyTowns = 0; --- 216,225 ---- // express train cities = Integer.parseInt(t.replace("E", "")); ! ignoreTowns = true; multiplyTowns = 0; } else if (t.contains("D")) { // double (express) train cities = Integer.parseInt(t.replace("D", "")); ! ignoreTowns = true; multiplyCities = 2; multiplyTowns = 0; *************** *** 224,228 **** cities = Integer.parseInt(t); } ! NetworkTrain networkTrain = new NetworkTrain(cities, towns, townsCostNothing, multiplyCities, multiplyTowns, t); trains.add(networkTrain); } --- 228,232 ---- cities = Integer.parseInt(t); } ! NetworkTrain networkTrain = new NetworkTrain(cities, towns, ignoreTowns, multiplyCities, multiplyTowns, t); trains.add(networkTrain); } *************** *** 312,315 **** --- 316,343 ---- } + public void drawOptimalRunAsPath(HexMap map) { + List<GeneralPath> pathList = new ArrayList<GeneralPath>(); + Map<NetworkTrain, List<NetworkVertex>> run = getOptimalRun(); + + for (NetworkTrain train:run.keySet()) { + GeneralPath path = new GeneralPath(); + NetworkVertex startVertex = null; + for (NetworkVertex vertex:run.get(train)) { + Point2D vertexPoint = NetworkVertex.getVertexPoint2D(map, vertex); + if (startVertex == null) { + startVertex = vertex; + path.moveTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); + continue; + } else if (startVertex == vertex) { + path.moveTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); + continue; + } + if (vertexPoint != null) + path.lineTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); + } + pathList.add(path); + } + map.setTrainPaths(pathList); + } @Override Index: NetworkEdge.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkEdge.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NetworkEdge.java 13 Apr 2010 23:21:12 -0000 1.3 --- NetworkEdge.java 20 Apr 2010 19:45:40 -0000 1.4 *************** *** 1,4 **** --- 1,10 ---- package rails.algorithms; + import java.awt.Shape; + import java.awt.geom.Line2D; + import java.awt.geom.Point2D; + + import rails.ui.swing.hexmap.HexMap; + public final class NetworkEdge { *************** *** 51,55 **** return source + " - >" + target; } ! @Override // set to "" to faciltate visual graph --- 57,61 ---- return source + " - >" + target; } ! @Override // set to "" to faciltate visual graph *************** *** 61,63 **** --- 67,82 ---- } + public static Shape getEdgeShape(HexMap map, NetworkEdge edge){ + Point2D source = NetworkVertex.getVertexPoint2D(map, edge.getSource()); + Point2D target = NetworkVertex.getVertexPoint2D(map, edge.getTarget()); + Shape edgeShape; + if (source != null && target != null) { + edgeShape = new Line2D.Double(source, target); + } else { + edgeShape = null; + } + return edgeShape; + } + + } |
From: Stefan F. <ste...@us...> - 2010-04-20 19:45:48
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8480/rails/ui/swing/hexmap Modified Files: GUIHex.java HexMap.java Log Message: First implementation to visualize revenue runs on the map Index: GUIHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUIHex.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** GUIHex.java 11 Apr 2010 15:49:47 -0000 1.41 --- GUIHex.java 20 Apr 2010 19:45:40 -0000 1.42 *************** *** 181,184 **** --- 181,199 ---- } + public Point2D getCityPoint2D(City city){ + Point tokenPoint = getTokenCenter(0, 1, 0, city.getNumber() - 1); + return new Point2D.Double(tokenPoint.getX(), tokenPoint.getY()); + } + + public Point2D getSidePoint2D(int side){ + side = (5-side); + return new Point2D.Double((xVertex[side] + xVertex[(side+1)%6])/2, + (yVertex[side] + yVertex[(side+1)%6])/2); + } + + public Point2D getCenterPoint2D() { + return center; + } + public void setHexModel(MapHex model) { this.model = model; Index: HexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/HexMap.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** HexMap.java 11 Mar 2010 20:38:00 -0000 1.23 --- HexMap.java 20 Apr 2010 19:45:40 -0000 1.24 *************** *** 4,7 **** --- 4,8 ---- import java.awt.*; import java.awt.event.*; + import java.awt.geom.GeneralPath; import java.util.*; import java.util.List; *************** *** 65,69 **** protected boolean bonusTokenLayingEnabled = false; ! public void init(ORUIManager orUIManager, MapManager mapManager) { this.orUIManager = orUIManager; --- 66,75 ---- protected boolean bonusTokenLayingEnabled = false; ! ! /** list of generalpath elements to indicate train runs */ ! protected List<GeneralPath> trainPaths; ! protected Color[] trainColors = new Color[]{Color.CYAN, Color.PINK, Color.ORANGE, Color.GRAY}; ! protected Stroke trainStroke = new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); ! public void init(ORUIManager orUIManager, MapManager mapManager) { this.orUIManager = orUIManager; *************** *** 142,145 **** --- 148,160 ---- } } + + // paint train paths + Graphics2D g2 = (Graphics2D) g; + g2.setStroke(trainStroke); + int color = 0; + for (GeneralPath path:trainPaths) { + g2.setColor(trainColors[color++ % trainColors.length]); + g2.draw(path); + } } catch (NullPointerException ex) { *************** *** 338,341 **** --- 353,360 ---- } + public void setTrainPaths(List<GeneralPath> trainPaths) { + this.trainPaths = trainPaths; + } + /** * Off-board tiles must be able to retrieve the current phase. |
From: Erik V. <ev...@us...> - 2010-04-20 19:21:35
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5479/rails/game Modified Files: StartRound_1830.java Log Message: Fixed bad player assignment in 1830 style auctions (bug 2989440) Index: StartRound_1830.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound_1830.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** StartRound_1830.java 17 Feb 2010 22:01:43 -0000 1.31 --- StartRound_1830.java 20 Apr 2010 19:21:27 -0000 1.32 *************** *** 319,322 **** --- 319,324 ---- auctionItemState.set(null); numPasses.set(0); + // Next turn goes to priority holder + setPriorityPlayer(); // EV - Added to fix bug 2989440 } else { // More than one left: find next bidder |
From: Stefan F. <ste...@us...> - 2010-04-19 19:35:46
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7416/rails/ui/swing Modified Files: ORPanel.java Log Message: Several bug fixes to the revenue calculation and network iterator Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** ORPanel.java 16 Apr 2010 16:38:21 -0000 1.56 --- ORPanel.java 19 Apr 2010 19:35:38 -0000 1.57 *************** *** 607,621 **** NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); ! // revenue calculation example ! mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); ! RevenueAdapter ra = new RevenueAdapter(mapGraph); ! // set tokens ! List<TokenI> tokens = company.getTokens(); ! for (TokenI token:tokens){ ! NetworkVertex vertex = nwGraph.getVertex(token); ! if (vertex != null) ra.addStartVertex(vertex); ! } ! // run on railroad graph, does not work so far, thus use map graph ! // RevenueAdapter ra = new RevenueAdapter(graph); // get trains --- 607,621 ---- NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); ! // revenue calculation example on mapGraph ! // mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); ! // RevenueAdapter ra = new RevenueAdapter(mapGraph); ! // // set tokens ! // List<TokenI> tokens = company.getTokens(); ! // for (TokenI token:tokens){ ! // NetworkVertex vertex = nwGraph.getVertex(token); ! // if (vertex != null) ra.addStartVertex(vertex); ! // } ! // run on railroad graph ! RevenueAdapter ra = new RevenueAdapter(graph); // get trains *************** *** 627,639 **** while (anotherTrain) { // create results ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8")); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase()); ! ra.activateRevenuePrediction(); log.info("Revenue Adapter:" + ra); int revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); ! log.info("Revenue run:" + ra.getOptimalRun()); ! JOptionPane.showMessageDialog(orWindow, "RevenueValue = " + revenueValue + ! "\n RevenueRun = " + ra.getOptimalRun()); String trainsToAdd = --- 627,648 ---- while (anotherTrain) { // create results ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), false); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), false); log.info("Revenue Adapter:" + ra); int revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); ! log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ! JOptionPane.showMessageDialog(orWindow, "Without Prediction: RevenueValue = " + revenueValue + ! "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); ! ! ra.refreshRevenueCalculator(); ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); ! log.info("Revenue Adapter:" + ra); ! revenueValue = ra.calculateRevenue(); ! log.info("Revenue Value:" + revenueValue); ! log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ! JOptionPane.showMessageDialog(orWindow, "With Prediction: RevenueValue = " + revenueValue + ! "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); String trainsToAdd = *************** *** 822,827 **** } ! ra.populateRevenueCalculator(company, gm.getCurrentPhase()); ! ra.activateRevenuePrediction(); ra.addRevenueListener(this); --- 831,835 ---- } ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); ra.addRevenueListener(this); |
From: Stefan F. <ste...@us...> - 2010-04-19 19:35:46
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7416/rails/algorithms Modified Files: RevenueCalculator.java RevenueAdapter.java NetworkIterator.java Log Message: Several bug fixes to the revenue calculation and network iterator Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RevenueCalculator.java 16 Apr 2010 16:38:21 -0000 1.4 --- RevenueCalculator.java 19 Apr 2010 19:35:38 -0000 1.5 *************** *** 46,53 **** --- 46,59 ---- // dynamic run data private int finalTrain; + private boolean useRevenuePrediction; + private int currentBestValue; private final int [][] currentBestRun; + private int countVisits; private int countEdges; + private int nbEdges; + private int nbEvaluations; + private int nbPredictions; // prediction data *************** *** 59,64 **** private RevenueAdapter revenueAdapter; - private boolean stopped; - protected static Logger log = Logger.getLogger(RevenueCalculator.class.getPackage().getName()); --- 65,68 ---- *************** *** 101,104 **** --- 105,110 ---- currentBestRun = new int[nbTrains][nbVertexes]; + useRevenuePrediction = false; + } *************** *** 130,133 **** --- 136,140 ---- this.maxCityRevenues = maxCityRevenues; this.maxTownRevenues = maxTownRevenues; + useRevenuePrediction = true; } *************** *** 136,140 **** --- 143,162 ---- } + int getNumberOfEvaluations() { + return nbEvaluations; + } + private void notifyRevenueAdapter(final int revenue, final boolean finalResult) { + String modifier; + if (finalResult) + modifier = "final"; + else + modifier = "new best"; + StringBuffer statistics = new StringBuffer(); + statistics.append(nbEvaluations + " evaluations"); + if (useRevenuePrediction) + statistics.append(", " + nbPredictions + " predictions"); + statistics.append(" and " + nbEdges + " edges travelled."); + log.info("Report " + modifier + " result of " + revenue + " after " + statistics.toString()); revenueAdapter.notifyRevenueListener(revenue, finalResult); } *************** *** 143,153 **** log.info("RC: calculateRevenue trains from " + startTrain + " to " + finalTrain); ! stopped = false; ! // initialize maximum train revenues ! maxTrainRevenues = new int[nbTrains]; ! for (int j=0; j < nbTrains; j++) { ! maxTrainRevenues[j] = maxCityRevenues[trainMaxCities[j]] * trainMultiplyCities[j] + ! maxTownRevenues[trainMaxTowns[j]] * trainMultiplyTowns[j]; } --- 165,177 ---- log.info("RC: calculateRevenue trains from " + startTrain + " to " + finalTrain); ! nbEvaluations = 0; nbPredictions = 0; nbEdges = 0; ! // initialize maximum train revenues ! if (useRevenuePrediction) { ! maxTrainRevenues = new int[nbTrains]; ! for (int j=0; j < nbTrains; j++) { ! maxTrainRevenues[j] = maxCityRevenues[trainMaxCities[j]] * trainMultiplyCities[j] + ! maxTownRevenues[trainMaxTowns[j]] * trainMultiplyTowns[j]; ! } } *************** *** 173,184 **** log.debug("RC: Using startVertex nr. " + i + " for train " + trainId); ! // check train termination and revenue prediction after visit ! boolean trainTerminated; ! if (encounterVertex(trainId, startVertexes[i], true)) { ! trainTerminated = trainTerminated(trainId) || (predictRevenues(trainId)); ! } else { ! trainTerminated = false; } ! // and all edges of it boolean evaluateResult = true; --- 197,214 ---- log.debug("RC: Using startVertex nr. " + i + " for train " + trainId); ! // encounterVertex adds value and returns true if value vertex ! boolean trainTerminated = false; ! if (encounterVertex(trainId, vertexId, true)) { ! if (useRevenuePrediction && predictRevenues(trainId)) { ! // cannot beat current best value => leave immediately ! encounterVertex(trainId, vertexId, false); ! log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); ! continue; ! } else { ! // check usual train termination ! trainTerminated = trainTerminated(trainId); ! } } ! // and all edges of it boolean evaluateResult = true; *************** *** 197,202 **** // no more edges to find ! finalizeVertex(trainId, startVertexes[i], evaluateResult); ! encounterVertex(trainId, startVertexes[i], false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); } --- 227,232 ---- // no more edges to find ! finalizeVertex(trainId, vertexId, evaluateResult); ! encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); } *************** *** 239,248 **** private void nextVertex(int trainId, int vertexId, int previousId) { ! // 1. add vertex to path and returns true if train terminated (if start = 0, otherwise it is a revisit of the start) ! boolean trainTerminated; if (encounterVertex(trainId, vertexId, true)) { ! trainTerminated = trainTerminated(trainId) || (predictRevenues(trainId)); ! } else { ! trainTerminated = false; } --- 269,284 ---- private void nextVertex(int trainId, int vertexId, int previousId) { ! // 1. encounterVertex adds value and returns true if value vertex ! boolean trainTerminated = false; if (encounterVertex(trainId, vertexId, true)) { ! if (useRevenuePrediction && predictRevenues(trainId)) { ! // cannot beat current best value => leave immediately ! encounterVertex(trainId, vertexId, false); ! returnEdge(trainId); ! return; ! } else { ! // check usual train termination ! trainTerminated = trainTerminated(trainId); ! } } *************** *** 322,326 **** edgeUsed[startVertex][endVertex] = true; edgeUsed[endVertex][startVertex] = true; ! countEdges++; log.debug("RC: Count Edges = " + countEdges); return true; --- 358,362 ---- edgeUsed[startVertex][endVertex] = true; edgeUsed[endVertex][startVertex] = true; ! countEdges++; nbEdges++; log.debug("RC: Count Edges = " + countEdges); return true; *************** *** 407,410 **** --- 443,447 ---- } } + nbEvaluations++; log.debug("RC: current total value " + totalValue); *************** *** 430,434 **** private boolean predictRevenues(int trainId){ int totalValue = 0; - for (int j = 0; j <= finalTrain; j++) { int trainValue; --- 467,470 ---- *************** *** 438,445 **** trainValue = maxTrainRevenues[j]; } else { // the current train ! if (trainTownsCostNothing[trainId]) { // still TODO trainValue = 0; ! } else if (trainTowns[trainId] == 0) { // default train trainValue = trainCurrentValue[j] + --- 474,481 ---- trainValue = maxTrainRevenues[j]; } else { // the current train ! if (trainTownsCostNothing[j]) { // still TODO trainValue = 0; ! } else if (trainTowns[j] == 0) { // default train trainValue = trainCurrentValue[j] + *************** *** 447,451 **** } else { // plus trains ! int townDiff = trainMaxTowns[trainId] - trainTowns[trainId]; if (townDiff > 0) { trainValue = trainCurrentValue[j] + --- 483,487 ---- } else { // plus trains ! int townDiff = trainMaxTowns[j] - trainTowns[j]; if (townDiff > 0) { trainValue = trainCurrentValue[j] + *************** *** 460,469 **** } } } log.debug("RC: Train " + j + " has value of " + trainValue); ! totalValue += Math.min(trainValue, maxTrainRevenues[trainId]); } ! boolean terminate = (totalValue < currentBestValue); if (terminate) log.debug("Run terminated due to predicted value of " + totalValue); --- 496,508 ---- } } + trainValue = Math.min(trainValue, maxTrainRevenues[j]); } log.debug("RC: Train " + j + " has value of " + trainValue); ! totalValue += trainValue; } ! nbPredictions++; ! ! boolean terminate = (totalValue <= currentBestValue); if (terminate) log.debug("Run terminated due to predicted value of " + totalValue); *************** *** 472,477 **** - - @Override public String toString() { --- 511,514 ---- Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RevenueAdapter.java 16 Apr 2010 16:38:21 -0000 1.4 --- RevenueAdapter.java 19 Apr 2010 19:35:38 -0000 1.5 *************** *** 61,64 **** --- 61,66 ---- public void refreshRevenueCalculator() { rc = null; + // refresh startVertexes + this.startVertexes = new ArrayList<NetworkVertex>(); } *************** *** 76,80 **** } ! public void activateRevenuePrediction() { // separate vertexes --- 78,82 ---- } ! private void prepareRevenuePrediction(boolean activatePrediction) { // separate vertexes *************** *** 92,122 **** int maxCityLength = 0, maxTownLength = 0; for (NetworkTrain train: trains) { ! int increaseTowns = 0; if (train.getCities() > maxCities) { ! increaseTowns = maxCities - train.getCities(); train.setCities(maxCities); } ! int trainTowns = train.getTowns() + increaseTowns; ! if (trainTowns > maxTowns) { ! train.setTowns(maxTowns); ! } maxCityLength = Math.max(maxCityLength, train.getCities()); maxTownLength = Math.max(maxTownLength, train.getTowns()); } ! // get max revenue results ! int[] maxCityRevenues = revenueList(cities, maxCityLength); ! int[] maxTownRevenues = revenueList(towns, maxTownLength); ! // set revenue results in revenue calculator ! rc.setPredictionData(maxCityRevenues, maxTownRevenues); } ! public void populateRevenueCalculator(PublicCompanyI company, PhaseI phase){ if (rc == null) initRevenueCalculator(); ! // set vertexes ! // Define ordering on vertexes by value NetworkVertex.setPhaseForAll(vertexes, phase); --- 94,125 ---- int maxCityLength = 0, maxTownLength = 0; for (NetworkTrain train: trains) { ! int trainTowns = train.getTowns(); if (train.getCities() > maxCities) { ! trainTowns = trainTowns+ train.getCities() - maxCities; train.setCities(maxCities); } ! train.setTowns(Math.min(trainTowns, maxTowns)); ! maxCityLength = Math.max(maxCityLength, train.getCities()); maxTownLength = Math.max(maxTownLength, train.getTowns()); } ! if (activatePrediction) { ! // get max revenue results ! int[] maxCityRevenues = revenueList(cities, maxCityLength); ! int[] maxTownRevenues = revenueList(towns, maxTownLength); ! // set revenue results in revenue calculator ! rc.setPredictionData(maxCityRevenues, maxTownRevenues); ! } } ! public void populateRevenueCalculator(PublicCompanyI company, PhaseI phase, boolean activatePrediction){ if (rc == null) initRevenueCalculator(); ! // prepare and optionaly activate revenue prediction ! prepareRevenuePrediction(activatePrediction); ! // Define ordering on vertexes by value NetworkVertex.setPhaseForAll(vertexes, phase); Index: NetworkIterator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkIterator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NetworkIterator.java 12 Apr 2010 17:37:32 -0000 1.3 --- NetworkIterator.java 19 Apr 2010 19:35:38 -0000 1.4 *************** *** 26,41 **** */ WHITE, ! ! /** ! * Vertex has not been returned via iterator yet, but has to use autoedge ! */ ! YELLOW, ! ! /** ! * Vertex has been returned via iterator, but we're ! * not done with all of its out-edges yet. ! */ GRAY, - /** * Vertex has been returned via iterator, and we're --- 26,34 ---- */ WHITE, ! /** ! * Vertex has been returned via iterator, but we're ! * not done with all of its out-edges yet. ! */ GRAY, /** * Vertex has been returned via iterator, and we're *************** *** 50,53 **** --- 43,47 ---- */ private Map<NetworkVertex, VisitColor> seen = new HashMap<NetworkVertex, VisitColor>(); + private Map<NetworkVertex, Boolean> mustUseGreedy = new HashMap<NetworkVertex, Boolean>(); private NetworkVertex startVertex; *************** *** 148,154 **** * @return <tt>true</tt> if vertex has already been seen */ ! private boolean isSeenVertex(NetworkVertex vertex) { ! return seen.containsKey(vertex); } --- 142,148 ---- * @return <tt>true</tt> if vertex has already been seen */ ! private boolean isSeenVertex(NetworkVertex vertex, boolean mustUseGreedy) { ! return seen.containsKey(vertex) && (mustUseGreedy || !this.mustUseGreedy.get(vertex) ); } *************** *** 188,192 **** NetworkVertex oppositeV = Graphs.getOppositeVertex(graph, edge, vertex); ! if (isSeenVertex(oppositeV)) { encounterVertexAgain(oppositeV, edge); } else { --- 182,186 ---- NetworkVertex oppositeV = Graphs.getOppositeVertex(graph, edge, vertex); ! if (isSeenVertex(oppositeV, vertex.isSide() && !edge.isGreedy() )) { encounterVertexAgain(oppositeV, edge); } else { *************** *** 206,215 **** /** copy of standard dfs */ private void encounterVertex(NetworkVertex vertex, NetworkEdge edge) { ! VisitColor color = VisitColor.WHITE; ! if (vertex.isSide() && !edge.isGreedy()) ! color = VisitColor.YELLOW; ! putSeenData(vertex, color); stack.add(vertex); ! log.debug("Iterator: Added to stack " + vertex + " with color " + color); } --- 200,207 ---- /** copy of standard dfs */ private void encounterVertex(NetworkVertex vertex, NetworkEdge edge) { ! putSeenData(vertex, VisitColor.WHITE); ! mustUseGreedy.put(vertex, vertex.isSide() && !edge.isGreedy()); stack.add(vertex); ! log.debug("Iterator: Added to stack " + vertex); } *************** *** 217,221 **** private void encounterVertexAgain(NetworkVertex vertex, NetworkEdge edge) { VisitColor color = getSeenData(vertex); ! if (color != VisitColor.WHITE && color != VisitColor.YELLOW) { // We've already visited this vertex; no need to mess with the // stack (either it's BLACK and not there at all, or it's GRAY --- 209,213 ---- private void encounterVertexAgain(NetworkVertex vertex, NetworkEdge edge) { VisitColor color = getSeenData(vertex); ! if (color != VisitColor.WHITE) { // We've already visited this vertex; no need to mess with the // stack (either it's BLACK and not there at all, or it's GRAY *************** *** 289,293 **** { NetworkVertex v = popStack(); ! putSeenData(v, VisitColor.BLACK); finishVertex(v); } --- 281,286 ---- { NetworkVertex v = popStack(); ! if (getSeenData(v) == VisitColor.WHITE) ! putSeenData(v, VisitColor.BLACK); finishVertex(v); } |
From: Erik V. <ev...@us...> - 2010-04-18 20:52:41
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30360/rails/game Modified Files: PublicCompanyI.java PublicCompany.java Log Message: Chech Prussian presidency after each formation round Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** PublicCompany.java 27 Mar 2010 18:27:08 -0000 1.93 --- PublicCompany.java 18 Apr 2010 20:52:32 -0000 1.94 *************** *** 1502,1505 **** --- 1502,1533 ---- } } + + /** A generic presidency check. Perhaps it can replace the above two methods. */ + public void checkPresidency () { + + Player president = getPresident(); + int presIndex = president.getIndex(); + int presShare = president.getPortfolio().getShare(this); + + GameManagerI gmgr = GameManager.getInstance(); + Player player; + int share; + + for (int i = presIndex + 1; i < presIndex + + gmgr.getNumberOfPlayers(); i++) { + player = gmgr.getPlayerByIndex(i); + share = player.getPortfolio().getShare(this); + if (share > presShare) { + // Hand presidency to the first player with a higher share + president.getPortfolio().swapPresidentCertificate(this, + player.getPortfolio()); + ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", + player.getName(), + name )); + return; + } + } + + } /** Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** PublicCompanyI.java 27 Mar 2010 18:27:08 -0000 1.51 --- PublicCompanyI.java 18 Apr 2010 20:52:32 -0000 1.52 *************** *** 264,267 **** --- 264,268 ---- public void checkPresidencyOnBuy(Player buyer); + public void checkPresidency (); public int getCapitalisation(); |
From: Erik V. <ev...@us...> - 2010-04-18 20:52:40
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30360/rails/game/specific/_1835 Modified Files: PrussianFormationRound.java Log Message: Chech Prussian presidency after each formation round Index: PrussianFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/PrussianFormationRound.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PrussianFormationRound.java 15 Apr 2010 19:49:50 -0000 1.10 --- PrussianFormationRound.java 18 Apr 2010 20:52:32 -0000 1.11 *************** *** 300,304 **** if (!hex.hasTokenOfCompany(prussian) && hex.layBaseToken(prussian, city.getNumber())) { /* TODO: the false return value must be impossible. */ ! message =LocalText.getText("ExchangesBaseToken", PR_ID, minor.getName(), city.getName()); --- 300,304 ---- if (!hex.hasTokenOfCompany(prussian) && hex.layBaseToken(prussian, city.getNumber())) { /* TODO: the false return value must be impossible. */ ! message = LocalText.getText("ExchangesBaseToken", PR_ID, minor.getName(), city.getName()); *************** *** 346,349 **** --- 346,353 ---- } + protected void finishRound() { + if (prussian.hasStarted()) prussian.checkPresidency(); + super.finishRound(); + } public static boolean prussianIsComplete(GameManagerI gameManager) { *************** *** 354,362 **** } return true; - /* - List<PublicCertificateI> unissued - = gameManager.getBank().getUnavailable().getCertificatesPerCompany(PR_ID); - return unissued == null || unissued.isEmpty(); - */ } --- 358,361 ---- |
From: Erik V. <ev...@us...> - 2010-04-18 20:52:40
|
Update of /cvsroot/rails/18xx In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30360 Modified Files: LocalisedText.properties Log Message: Chech Prussian presidency after each formation round Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** LocalisedText.properties 11 Apr 2010 15:49:47 -0000 1.128 --- LocalisedText.properties 18 Apr 2010 20:52:32 -0000 1.129 *************** *** 229,232 **** --- 229,233 ---- INFO=Game Notes Info=Info + Insert=Insert InterestPaidFromTreasury={0} pays {1} loan interest from its treasury InterestPartlyPaidFromTreasury={0} pays {1} (of {2}) loan interest from its treasury |
From: Erik V. <ev...@us...> - 2010-04-18 15:10:06
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv25475/rails/ui/swing/hexmap Modified Files: GUITile.java Log Message: Reinstated the brown-OO-upgrade-correctness check, which had disappeared in version 1.0.5 for unclear reasons. Index: GUITile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUITile.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** GUITile.java 31 Jan 2010 22:22:36 -0000 1.22 --- GUITile.java 18 Apr 2010 15:09:58 -0000 1.23 *************** *** 138,141 **** --- 138,142 ---- oldTrack.getEndPoint(prevTileSide)); } else { + // Downgraded // Assume there are only two exits // (this is the only known case for downgrading: *************** *** 190,208 **** if (oldCities.get(lll) == null) continue; // If new tile is missing a connection, skip ! log.debug("Found " + oldCities.get(kk) + " & " ! + oldCities.get(ll)); ! log.debug("Check " + newCities.get(kk) + " & " + newCities.get(ll)); if (newCities.get(kk) == null || newCities.get(ll) == null) continue rot; // If connected cities do not correspond, skip ! // log.debug("Compare ! // "+oldCities.get(kkk)+"/"+oldCities.get(lll) ! // +" ~ "+newCities.get(kk)+"/"+newCities.get(ll)); ! // if ((oldCities.get(kkk).equals(oldCities.get(lll))) ! // != (newCities.get(kk).equals(newCities.get(ll)))) { ! // log.debug("No match!"); ! // continue rot; ! // } } } --- 191,209 ---- if (oldCities.get(lll) == null) continue; // If new tile is missing a connection, skip ! log.debug("Found " + oldCities.get(kkk) + " & " ! + oldCities.get(lll)); ! log.debug("Check " + newCities.get(kkk) + " & " + newCities.get(ll)); if (newCities.get(kk) == null || newCities.get(ll) == null) continue rot; // If connected cities do not correspond, skip ! // (this is the "OO brown upgrade get-right" feature) ! log.debug("Compare "+oldCities.get(kkk)+"/"+oldCities.get(lll) ! +" ~ "+newCities.get(kk)+"/"+newCities.get(ll)); ! if ((oldCities.get(kkk).equals(oldCities.get(lll))) ! != (newCities.get(kk).equals(newCities.get(ll)))) { ! log.debug("No match!"); ! continue rot; ! } } } |
From: Erik V. <ev...@us...> - 2010-04-18 15:09:05
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv25235/rails/game Modified Files: City.java Log Message: 'relatedStation' converted into a State object Index: City.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/City.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** City.java 11 Apr 2010 15:49:47 -0000 1.11 --- City.java 18 Apr 2010 15:08:57 -0000 1.12 *************** *** 8,11 **** --- 8,12 ---- import rails.game.move.Moveable; + import rails.game.state.GenericState; import rails.util.Util; *************** *** 29,33 **** private int number; private String uniqueId; ! private Station relatedStation; private int slots; private ArrayList<TokenI> tokens; --- 30,35 ---- private int number; private String uniqueId; ! //private Station relatedStation; ! private GenericState<Station> relatedStation; private int slots; private ArrayList<TokenI> tokens; *************** *** 41,50 **** this.mapHex = mapHex; this.number = number; ! this.relatedStation = station; ! uniqueId = mapHex.getName() + "_" + number; ! slots = relatedStation.getBaseSlots(); ! tokens = new ArrayList<TokenI>(slots); } --- 43,53 ---- this.mapHex = mapHex; this.number = number; ! uniqueId = mapHex.getName() + "_" + number; ! relatedStation = new GenericState<Station>("City_"+uniqueId+"_station", station); ! setRelatedStation(station); ! ! tokens = new ArrayList<TokenI>(4); } *************** *** 66,74 **** public Station getRelatedStation() { ! return relatedStation; } public void setRelatedStation(Station relatedStation) { ! this.relatedStation = relatedStation; trackEdges = mapHex.getConnectionString(mapHex.getCurrentTile(), --- 69,78 ---- public Station getRelatedStation() { ! return relatedStation.getObject(); } public void setRelatedStation(Station relatedStation) { ! this.relatedStation.set(relatedStation); ! slots = relatedStation.getBaseSlots(); trackEdges = mapHex.getConnectionString(mapHex.getCurrentTile(), |
From: Erik V. <ev...@us...> - 2010-04-18 12:47:45
|
Update of /cvsroot/rails/18xx/data/1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv4547/data/1835 Modified Files: Map.xml Log Message: Added missing hex G1 Index: Map.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1835/Map.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Map.xml 11 Apr 2010 15:49:47 -0000 1.10 --- Map.xml 18 Apr 2010 12:47:37 -0000 1.11 *************** *** 45,48 **** --- 45,49 ---- <Hex name="F18" tile="0"/> <Hex name="F20" tile="0"/> + <Hex name="G1" tile="-7"/> <Hex name="G3" tile="-807" cost="50" city="Essen/Duisburg"/> <Hex name="G5" tile="-10" city="Dortmund"/> |
From: Stefan F. <ste...@us...> - 2010-04-16 16:38:29
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv2212/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: Updated revenue calculation: Pretty print and better thread support Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** ORUIManager.java 15 Apr 2010 21:46:28 -0000 1.66 --- ORUIManager.java 16 Apr 2010 16:38:21 -0000 1.67 *************** *** 474,477 **** --- 474,478 ---- if (command.equals(ORPanel.SET_REVENUE_CMD)) { amount = orPanel.getRevenue(orCompIndex); + orPanel.stopRevenueUpdate(); log.debug("Set revenue amount is " + amount); action.setActualRevenue(amount); Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** ORPanel.java 15 Apr 2010 21:46:28 -0000 1.55 --- ORPanel.java 16 Apr 2010 16:38:21 -0000 1.56 *************** *** 110,113 **** --- 110,116 ---- private PublicCompanyI orComp = null; + + private RevenueAdapter revenueAdapter = null; + private Thread revenueThread = null; protected static Logger log = *************** *** 782,790 **** button1.setVisible(true); - // initialize and start the revenue adapter ! RevenueAdapter ra = initRevenueCalculation(orComp); ! ! new Thread(ra).start(); } --- 785,792 ---- button1.setVisible(true); // initialize and start the revenue adapter ! revenueAdapter = initRevenueCalculation(orComp); ! revenueThread = new Thread(revenueAdapter); ! revenueThread.start(); } *************** *** 827,834 **** } ! public void revenueUpdate(int revenue, boolean finalResult) { ! revenueSelect[orCompIndex].setValue(revenue); } public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { --- 829,848 ---- } ! public void revenueUpdate(int bestRevenue, boolean finalResult) { ! revenueSelect[orCompIndex].setValue(bestRevenue); ! if (finalResult) { ! JOptionPane.showMessageDialog(orWindow, "Best Run Value = " + bestRevenue + ! "\n" + revenueAdapter.getOptimalRunPrettyPrint()); ! } } + public void stopRevenueUpdate() { + revenueAdapter.removeRevenueListener(); + revenueAdapter = null; + revenueThread.interrupt(); + revenueThread = null; + } + + public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { |
From: Stefan F. <ste...@us...> - 2010-04-16 16:38:29
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv2212/rails/algorithms Modified Files: RevenueCalculator.java RevenueAdapter.java NetworkVertex.java Log Message: Updated revenue calculation: Pretty print and better thread support Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RevenueCalculator.java 15 Apr 2010 21:46:28 -0000 1.3 --- RevenueCalculator.java 16 Apr 2010 16:38:21 -0000 1.4 *************** *** 1,5 **** package rails.algorithms; - import java.awt.EventQueue; import java.util.Arrays; --- 1,4 ---- *************** *** 57,63 **** private int[] maxTrainRevenues; ! // revenue listener ! private RevenueListener revenueListener; protected static Logger log = --- 56,63 ---- private int[] maxTrainRevenues; ! // revenue Adapter ! private RevenueAdapter revenueAdapter; + private boolean stopped; protected static Logger log = *************** *** 65,70 **** ! public RevenueCalculator (int nbVertexes, int maxNeighbors, int nbTrains) { this.nbVertexes = nbVertexes; this.maxNeighbors = maxNeighbors; --- 65,71 ---- ! public RevenueCalculator (RevenueAdapter revenueAdapter, int nbVertexes, int maxNeighbors, int nbTrains) { + this.revenueAdapter = revenueAdapter; this.nbVertexes = nbVertexes; this.maxNeighbors = maxNeighbors; *************** *** 99,102 **** --- 100,104 ---- currentBestRun = new int[nbTrains][nbVertexes]; + } *************** *** 133,139 **** return currentBestRun; } ! ! void addRevenueListener(RevenueListener listener) { ! this.revenueListener = listener; } --- 135,141 ---- return currentBestRun; } ! ! private void notifyRevenueAdapter(final int revenue, final boolean finalResult) { ! revenueAdapter.notifyRevenueListener(revenue, finalResult); } *************** *** 141,144 **** --- 143,148 ---- log.info("RC: calculateRevenue trains from " + startTrain + " to " + finalTrain); + stopped = false; + // initialize maximum train revenues maxTrainRevenues = new int[nbTrains]; *************** *** 150,153 **** --- 154,161 ---- this.finalTrain = finalTrain; runTrain(startTrain); + + // inform revenue listener via adapter + notifyRevenueAdapter(currentBestValue, true); + return currentBestValue; } *************** *** 414,424 **** } log.info("RC: Found better run with " + totalValue); ! // inform revenue listener ! EventQueue.invokeLater( ! new Runnable() { ! public void run() { ! revenueListener.revenueUpdate(currentBestValue, false); ! } ! }); } } --- 422,427 ---- } log.info("RC: Found better run with " + totalValue); ! // inform revenue listener via adapter ! notifyRevenueAdapter(currentBestValue, false); } } Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NetworkVertex.java 13 Apr 2010 23:21:12 -0000 1.5 --- NetworkVertex.java 16 Apr 2010 16:38:21 -0000 1.6 *************** *** 209,212 **** --- 209,227 ---- } + public String getVertexName(){ + StringBuffer name = new StringBuffer(); + if (isStation()) { + // if (hex.getCityName() != null && !hex.getCityName().equals("")) + // name.append(hex.getCityName()); + // else + // name.append("Station"); + // if (station.getNumber() != 1) + // name.append("." + station.getNumber()); + name.append(this.getValue()); + } else + name.append(hex.getOrientationName(side)); + return name.toString(); + } + @Override public String toString(){ Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RevenueAdapter.java 15 Apr 2010 21:46:28 -0000 1.3 --- RevenueAdapter.java 16 Apr 2010 16:38:21 -0000 1.4 *************** *** 1,4 **** --- 1,5 ---- package rails.algorithms; + import java.awt.EventQueue; import java.util.ArrayList; import java.util.Arrays; *************** *** 14,17 **** --- 15,19 ---- import rails.game.GameManager; + import rails.game.MapHex; import rails.game.PhaseI; import rails.game.PublicCompanyI; *************** *** 32,35 **** --- 34,41 ---- private List<NetworkTrain> trains; + // revenue listener + private RevenueListener revenueListener; + + public RevenueAdapter(Graph<NetworkVertex, NetworkEdge> graph){ this.graph = graph; *************** *** 49,53 **** maxNeighbors = Math.max(maxNeighbors, graph.edgesOf(vertex).size()); ! this.rc = new RevenueCalculator(vertexes.size(), ++maxNeighbors, trains.size()); // increase maxEdges to allow for cutoff } } --- 55,59 ---- maxNeighbors = Math.max(maxNeighbors, graph.edgesOf(vertex).size()); ! this.rc = new RevenueCalculator(this, vertexes.size(), ++maxNeighbors, trains.size()); // increase maxEdges to allow for cutoff } } *************** *** 250,254 **** public void addRevenueListener(RevenueListener listener) { ! rc.addRevenueListener(listener); } --- 256,271 ---- public void addRevenueListener(RevenueListener listener) { ! this.revenueListener = listener; ! } ! ! void notifyRevenueListener(final int revenue, final boolean finalResult) { ! if (revenueListener == null) return; ! ! EventQueue.invokeLater( ! new Runnable() { ! public void run() { ! revenueListener.revenueUpdate(revenue, finalResult); ! } ! }); } *************** *** 257,260 **** --- 274,313 ---- } + public void removeRevenueListener() { + // only removes revenueListener + revenueListener = null; + } + + public String getOptimalRunPrettyPrint() { + StringBuffer runPrettyPrint = new StringBuffer(); + Map<NetworkTrain, List<NetworkVertex>> run = getOptimalRun(); + + for (NetworkTrain train:run.keySet()) { + runPrettyPrint.append("Train " + train + ": "); + MapHex currentHex = null; + NetworkVertex startVertex = null; + for (NetworkVertex vertex:run.get(train)) { + if (startVertex == null) { + currentHex = vertex.getHex(); + startVertex = vertex; + runPrettyPrint.append(vertex.getHex().getName() + "("); + } else if (startVertex == vertex) { + currentHex = vertex.getHex(); + runPrettyPrint.append(") / " + vertex.getHex().getName() + "(0"); + continue; + } else if (vertex.getHex() != currentHex) { + currentHex = vertex.getHex(); + runPrettyPrint.append("), " + vertex.getHex().getName() + "("); + } else { + runPrettyPrint.append(","); + } + runPrettyPrint.append(vertex.getVertexName()); + } + runPrettyPrint.append(")\n"); + } + return runPrettyPrint.toString(); + } + + @Override public String toString() { |
From: Stefan F. <ste...@us...> - 2010-04-15 21:46:36
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14783/rails/algorithms Modified Files: NetworkTrain.java RevenueCalculator.java RevenueAdapter.java Added Files: RevenueListener.java Log Message: RevenueCalculation feeds into ORPanel implementation Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RevenueCalculator.java 13 Apr 2010 23:21:12 -0000 1.2 --- RevenueCalculator.java 15 Apr 2010 21:46:28 -0000 1.3 *************** *** 1,4 **** --- 1,5 ---- package rails.algorithms; + import java.awt.EventQueue; import java.util.Arrays; *************** *** 56,59 **** --- 57,63 ---- private int[] maxTrainRevenues; + // revenue listener + private RevenueListener revenueListener; + protected static Logger log = *************** *** 129,132 **** --- 133,140 ---- return currentBestRun; } + + void addRevenueListener(RevenueListener listener) { + this.revenueListener = listener; + } int calculateRevenue(int startTrain, int finalTrain) { *************** *** 406,409 **** --- 414,424 ---- } log.info("RC: Found better run with " + totalValue); + // inform revenue listener + EventQueue.invokeLater( + new Runnable() { + public void run() { + revenueListener.revenueUpdate(currentBestValue, false); + } + }); } } *************** *** 455,458 **** --- 470,474 ---- + @Override public String toString() { --- NEW FILE: RevenueListener.java --- package rails.algorithms; public interface RevenueListener { public void revenueUpdate(int revenue, boolean finalResult); } Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NetworkTrain.java 13 Apr 2010 23:21:12 -0000 1.2 --- NetworkTrain.java 15 Apr 2010 21:46:28 -0000 1.3 *************** *** 3,8 **** public final class NetworkTrain { ! private final int cities; ! private final int towns; private final boolean townsCostNothing; private final int multiplyCities; --- 3,8 ---- public final class NetworkTrain { ! private int cities; ! private int towns; private final boolean townsCostNothing; private final int multiplyCities; *************** *** 28,35 **** --- 28,43 ---- } + void setCities(int cities){ + this.cities = cities; + } + int getTowns() { return towns; } + void setTowns(int towns){ + this.towns = towns; + } + int calculateRevenue(int[] cityValues, int[] townValues) { return cityValues[cities] * multiplyCities + townValues[towns] * multiplyTowns; Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RevenueAdapter.java 13 Apr 2010 23:21:12 -0000 1.2 --- RevenueAdapter.java 15 Apr 2010 21:46:28 -0000 1.3 *************** *** 8,19 **** import java.util.Map; import org.jgrapht.Graph; import org.jgrapht.Graphs; import rails.game.PhaseI; import rails.game.PublicCompanyI; import rails.game.TrainI; ! public class RevenueAdapter { private Graph<NetworkVertex, NetworkEdge> graph; --- 8,24 ---- import java.util.Map; + import javax.swing.SwingUtilities; + import org.jgrapht.Graph; import org.jgrapht.Graphs; + import rails.game.GameManager; import rails.game.PhaseI; import rails.game.PublicCompanyI; + import rails.game.TokenI; import rails.game.TrainI; ! ! public class RevenueAdapter implements Runnable { private Graph<NetworkVertex, NetworkEdge> graph; *************** *** 75,81 **** --- 80,98 ---- } + int maxCities = cities.size(); + int maxTowns = towns.size(); + // check train lengths int maxCityLength = 0, maxTownLength = 0; for (NetworkTrain train: trains) { + int increaseTowns = 0; + if (train.getCities() > maxCities) { + increaseTowns = maxCities - train.getCities(); + train.setCities(maxCities); + } + int trainTowns = train.getTowns() + increaseTowns; + if (trainTowns > maxTowns) { + train.setTowns(maxTowns); + } maxCityLength = Math.max(maxCityLength, train.getCities()); maxTownLength = Math.max(maxTownLength, train.getTowns()); *************** *** 221,224 **** --- 238,242 ---- } + public int calculateRevenue() { return calculateRevenue(0, trains.size() - 1); *************** *** 229,241 **** return rc.calculateRevenue(startTrain, finalTrain); } @Override public String toString() { StringBuffer buffer = new StringBuffer(); ! buffer.append("RevenueCalculator:" + rc); ! buffer.append("Vertexes:" + vertexes); ! buffer.append("Edges:" + edges); return buffer.toString(); } } --- 247,269 ---- return rc.calculateRevenue(startTrain, finalTrain); } + + + public void addRevenueListener(RevenueListener listener) { + rc.addRevenueListener(listener); + } + + public void run() { + calculateRevenue(0, trains.size() -1); + } @Override public String toString() { StringBuffer buffer = new StringBuffer(); ! buffer.append("RevenueCalculator: \n" + rc); ! buffer.append("\n Vertexes: \n" + vertexes); ! buffer.append("\n Edges: \n" + edges); return buffer.toString(); } + } |
From: Stefan F. <ste...@us...> - 2010-04-15 21:46:36
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14783/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: RevenueCalculation feeds into ORPanel implementation Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ORUIManager.java 11 Apr 2010 15:49:47 -0000 1.65 --- ORUIManager.java 15 Apr 2010 21:46:28 -0000 1.66 *************** *** 1364,1368 **** } ! orPanel.initORCompanyTurn(orCompIndex); privatesCanBeBoughtNow = possibleActions.contains(BuyPrivate.class); --- 1364,1368 ---- } ! orPanel.initORCompanyTurn(orComp, orCompIndex); privatesCanBeBoughtNow = possibleActions.contains(BuyPrivate.class); Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** ORPanel.java 15 Apr 2010 19:49:50 -0000 1.54 --- ORPanel.java 15 Apr 2010 21:46:28 -0000 1.55 *************** *** 21,25 **** public class ORPanel extends GridPanel ! implements ActionListener, KeyListener { private static final long serialVersionUID = 1L; --- 21,25 ---- public class ORPanel extends GridPanel ! implements ActionListener, KeyListener, RevenueListener { private static final long serialVersionUID = 1L; *************** *** 737,742 **** } ! public void initORCompanyTurn(int orCompIndex) { this.orCompIndex = orCompIndex; president[orCompIndex].setHighlight(true); --- 737,743 ---- } ! public void initORCompanyTurn(PublicCompanyI orComp, int orCompIndex) { + this.orComp = orComp; this.orCompIndex = orCompIndex; president[orCompIndex].setHighlight(true); *************** *** 771,774 **** --- 772,776 ---- revenueCaption.setHighlight(true); revenueSelect[orCompIndex].setValue(action.getPresetRevenue()); + setSelect(revenue[orCompIndex], revenueSelect[orCompIndex], true); *************** *** 779,784 **** --- 781,834 ---- button1.setEnabled(true); button1.setVisible(true); + + + // initialize and start the revenue adapter + RevenueAdapter ra = initRevenueCalculation(orComp); + + new Thread(ra).start(); } + private RevenueAdapter initRevenueCalculation(PublicCompanyI company){ + + GameManagerI gm = orUIManager.getGameUIManager().getGameManager(); + MapManager mapManager = gm.getMapManager(); + + NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); + nwGraph.generateGraph(mapManager.getHexesAsList()); + Graph<NetworkVertex, NetworkEdge> mapGraph = nwGraph.getMapGraph(); + + mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); + + // revenue calculation example + mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); + RevenueAdapter ra = new RevenueAdapter(mapGraph); + + // set tokens + List<TokenI> tokens = company.getTokens(); + for (TokenI token:tokens){ + NetworkVertex vertex = nwGraph.getVertex(token); + if (vertex != null) ra.addStartVertex(vertex); + } + + // run on railroad graph, does not work so far, thus use map graph + // RevenueAdapter ra = new RevenueAdapter(graph); + + // get trains + company.getPortfolio().getTrainList(); + for (TrainI train:company.getPortfolio().getTrainList()) { + ra.addTrain(train); + } + + ra.populateRevenueCalculator(company, gm.getCurrentPhase()); + ra.activateRevenuePrediction(); + ra.addRevenueListener(this); + + return ra; + } + + public void revenueUpdate(int revenue, boolean finalResult) { + revenueSelect[orCompIndex].setValue(revenue); + } + public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { *************** *** 952,954 **** --- 1002,1005 ---- } + } |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/game/specific/_1835 Modified Files: GameManager_1835.java OperatingRound_1835.java PrussianFormationRound.java StockRound_1835.java Log Message: Removed a redundant (because duplicate) method Index: StockRound_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/StockRound_1835.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** StockRound_1835.java 8 Apr 2010 21:23:47 -0000 1.10 --- StockRound_1835.java 15 Apr 2010 19:49:50 -0000 1.11 *************** *** 105,121 **** if (sharesInIPO == 0) { if (name.equals(GameManager_1835.SX_ID) && ! ipo.getShare(companyManager.getCompanyByName(GameManager_1835.BY_ID)) == 0 || name.equals(GameManager_1835.BY_ID) && ! ipo.getShare(companyManager.getCompanyByName(GameManager_1835.SX_ID)) == 0) { // Group 1 sold out: release Badische ! releaseCompanyShares (companyManager.getCompanyByName(GameManager_1835.BA_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.BA_ID)); } else if (name.equals(GameManager_1835.BA_ID) || name.equals(GameManager_1835.WT_ID) || name.equals(GameManager_1835.HE_ID)) { ! if (ipo.getShare(companyManager.getCompanyByName(GameManager_1835.BA_ID)) == 0 ! && ipo.getShare(companyManager.getCompanyByName(GameManager_1835.WT_ID)) == 0 ! && ipo.getShare(companyManager.getCompanyByName(GameManager_1835.HE_ID)) == 0) { // Group 2 sold out: release MS ! releaseCompanyShares (companyManager.getCompanyByName(GameManager_1835.MS_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.MS_ID)); --- 105,121 ---- if (sharesInIPO == 0) { if (name.equals(GameManager_1835.SX_ID) && ! ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BY_ID)) == 0 || name.equals(GameManager_1835.BY_ID) && ! ipo.getShare(companyManager.getPublicCompany(GameManager_1835.SX_ID)) == 0) { // Group 1 sold out: release Badische ! releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.BA_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.BA_ID)); } else if (name.equals(GameManager_1835.BA_ID) || name.equals(GameManager_1835.WT_ID) || name.equals(GameManager_1835.HE_ID)) { ! if (ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BA_ID)) == 0 ! && ipo.getShare(companyManager.getPublicCompany(GameManager_1835.WT_ID)) == 0 ! && ipo.getShare(companyManager.getPublicCompany(GameManager_1835.HE_ID)) == 0) { // Group 2 sold out: release MS ! releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.MS_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.MS_ID)); *************** *** 130,134 **** if (name.equals(GameManager_1835.BA_ID)) { if (sharesInIPO == 50) { // 50% sold: release Wurttemberg ! releaseCompanyShares (companyManager.getCompanyByName(GameManager_1835.WT_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.WT_ID)); --- 130,134 ---- if (name.equals(GameManager_1835.BA_ID)) { if (sharesInIPO == 50) { // 50% sold: release Wurttemberg ! releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.WT_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.WT_ID)); *************** *** 144,148 **** } else if (name.equals(GameManager_1835.WT_ID)) { //Wurttembergische if (sharesInIPO == 50) { // 50% sold: release Hessische ! releaseCompanyShares (companyManager.getCompanyByName(GameManager_1835.HE_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.HE_ID)); --- 144,148 ---- } else if (name.equals(GameManager_1835.WT_ID)) { //Wurttembergische if (sharesInIPO == 50) { // 50% sold: release Hessische ! releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.HE_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.HE_ID)); *************** *** 150,154 **** } else if (name.equals(GameManager_1835.MS_ID)) { // Mecklenburg/Schwerin if (sharesInIPO == 40) { // 60% sold: release Oldenburg ! releaseCompanyShares (companyManager.getCompanyByName(GameManager_1835.OL_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.OL_ID)); --- 150,154 ---- } else if (name.equals(GameManager_1835.MS_ID)) { // Mecklenburg/Schwerin if (sharesInIPO == 40) { // 60% sold: release Oldenburg ! releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.OL_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", "All", GameManager_1835.OL_ID)); Index: PrussianFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/PrussianFormationRound.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PrussianFormationRound.java 8 Apr 2010 21:23:47 -0000 1.9 --- PrussianFormationRound.java 15 Apr 2010 19:49:50 -0000 1.10 *************** *** 31,36 **** Step step; ! public static String PR_ID = GameManager_1835.PR_ID; ! public static String M2_ID = GameManager_1835.M2_ID; public PrussianFormationRound (GameManagerI gameManager) { --- 31,36 ---- Step step; ! private static String PR_ID = GameManager_1835.PR_ID; ! private static String M2_ID = GameManager_1835.M2_ID; public PrussianFormationRound (GameManagerI gameManager) { *************** *** 45,49 **** public void start() { ! prussian = companyManager.getCompanyByName(PR_ID); phase = getCurrentPhase(); startPr = !prussian.hasStarted(); --- 45,49 ---- public void start() { ! prussian = companyManager.getPublicCompany(PR_ID); phase = getCurrentPhase(); startPr = !prussian.hasStarted(); *************** *** 59,63 **** if (step == Step.START) { ! m2 = companyManager.getCompanyByName(M2_ID); setCurrentPlayer(m2.getPresident()); ((GameManager_1835)gameManager).setPrussianFormationStartingPlayer(currentPlayer); --- 59,63 ---- if (step == Step.START) { ! m2 = companyManager.getPublicCompany(M2_ID); setCurrentPlayer(m2.getPresident()); ((GameManager_1835)gameManager).setPrussianFormationStartingPlayer(currentPlayer); *************** *** 348,354 **** --- 348,362 ---- public static boolean prussianIsComplete(GameManagerI gameManager) { + + for (PublicCompanyI company : gameManager.getAllPublicCompanies()) { + if (!company.getTypeName().equalsIgnoreCase("Minor")) continue; + if (!company.isClosed()) return false; + } + return true; + /* List<PublicCertificateI> unissued = gameManager.getBank().getUnavailable().getCertificatesPerCompany(PR_ID); return unissued == null || unissued.isEmpty(); + */ } Index: GameManager_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/GameManager_1835.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GameManager_1835.java 9 Apr 2010 21:26:11 -0000 1.7 --- GameManager_1835.java 15 Apr 2010 19:49:50 -0000 1.8 *************** *** 6,10 **** public class GameManager_1835 extends GameManager { - public static String PR_NAME = PrussianFormationRound.PR_ID; private RoundI previousRound = null; private Player prFormStartingPlayer = null; --- 6,9 ---- Index: OperatingRound_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/OperatingRound_1835.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OperatingRound_1835.java 11 Apr 2010 15:49:47 -0000 1.3 --- OperatingRound_1835.java 15 Apr 2010 19:49:50 -0000 1.4 *************** *** 120,125 **** return result; } - - - } --- 120,122 ---- |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/game Modified Files: CompanyManager.java CompanyManagerI.java Log Message: Removed a redundant (because duplicate) method Index: CompanyManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManager.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CompanyManager.java 17 Feb 2010 22:02:51 -0000 1.23 --- CompanyManager.java 15 Apr 2010 19:49:50 -0000 1.24 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, Map<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, Map<String, CompanyI>>(); /** A list of all company types */ private List<CompanyTypeI> lCompanyTypes = new ArrayList<CompanyTypeI>(); /** A list of all start packets (usually one) */ private List<StartPacket> startPackets = new ArrayList<StartPacket>(); /** A map of all start packets, keyed by name. Default name is "Initial" */ private Map<String, StartPacket> startPacketMap = new HashMap<String, StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); protected GameManagerI gameManager; /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { gameManager = GameManager.getInstance(); /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); lCompanyTypes.add(companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); (mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name", StartPacket.DEFAULT_NAME); String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); startPacketMap.put(name, sp); sp.configureFromXML(packetTag); } } } // Post XML parsing initialisations public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.finishConfiguration(gameManager); } for (PrivateCompanyI comp : lPrivateCompanies) { comp.finishConfiguration(gameManager); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public List<CompanyTypeI> getCompanyTypes() { return lCompanyTypes; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { if (priv.isCloseable()) // check if private is closeable priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } public StartPacket getStartPacket (int index) { return startPackets.get(index); } public StartPacket getStartPacket (String name) { return startPacketMap.get(name); } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, Map<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, Map<String, CompanyI>>(); /** A list of all company types */ private List<CompanyTypeI> lCompanyTypes = new ArrayList<CompanyTypeI>(); /** A list of all start packets (usually one) */ private List<StartPacket> startPackets = new ArrayList<StartPacket>(); /** A map of all start packets, keyed by name. Default name is "Initial" */ private Map<String, StartPacket> startPacketMap = new HashMap<String, StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); protected GameManagerI gameManager; /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { gameManager = GameManager.getInstance(); /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); lCompanyTypes.add(companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); (mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name", StartPacket.DEFAULT_NAME); String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); startPacketMap.put(name, sp); sp.configureFromXML(packetTag); } } } // Post XML parsing initialisations public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.finishConfiguration(gameManager); } for (PrivateCompanyI comp : lPrivateCompanies) { comp.finishConfiguration(gameManager); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } /* public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } */ public List<CompanyTypeI> getCompanyTypes() { return lCompanyTypes; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { if (priv.isCloseable()) // check if private is closeable priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } public StartPacket getStartPacket (int index) { return startPackets.get(index); } public StartPacket getStartPacket (String name) { return startPacketMap.get(name); } } \ No newline at end of file Index: CompanyManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManagerI.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** CompanyManagerI.java 4 Feb 2010 21:27:58 -0000 1.14 --- CompanyManagerI.java 15 Apr 2010 19:49:50 -0000 1.15 *************** *** 53,59 **** * @return The company object, or null if not found. */ ! CompanyI getCompany(String type, String name); ! public PublicCompanyI getCompanyByName(String name); public List<CompanyTypeI> getCompanyTypes(); --- 53,59 ---- * @return The company object, or null if not found. */ ! public CompanyI getCompany(String type, String name); ! //public PublicCompanyI getCompanyByName(String name); public List<CompanyTypeI> getCompanyTypes(); |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/ui/swing Modified Files: ORPanel.java Log Message: Removed a redundant (because duplicate) method Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** ORPanel.java 13 Apr 2010 23:21:13 -0000 1.53 --- ORPanel.java 15 Apr 2010 19:49:50 -0000 1.54 *************** *** 597,601 **** } else { CompanyManagerI cm = gm.getCompanyManager(); ! PublicCompanyI company = cm.getCompanyByName(companyName); Graph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); --- 597,601 ---- } else { CompanyManagerI cm = gm.getCompanyManager(); ! PublicCompanyI company = cm.getPublicCompany(companyName); Graph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/game/action In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/game/action Modified Files: ReachDestinations.java MergeCompanies.java Log Message: Removed a redundant (because duplicate) method Index: MergeCompanies.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/MergeCompanies.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MergeCompanies.java 28 Feb 2010 21:38:06 -0000 1.8 --- MergeCompanies.java 15 Apr 2010 19:49:50 -0000 1.9 *************** *** 135,139 **** CompanyManagerI cmgr = getCompanyManager(); ! mergingCompany = cmgr.getCompanyByName(mergingCompanyName); targetCompanies = new ArrayList<PublicCompanyI>(); --- 135,139 ---- CompanyManagerI cmgr = getCompanyManager(); ! mergingCompany = cmgr.getPublicCompany(mergingCompanyName); targetCompanies = new ArrayList<PublicCompanyI>(); *************** *** 142,146 **** targetCompanies.add(null); } else { ! targetCompanies.add(cmgr.getCompanyByName(name)); } } --- 142,146 ---- targetCompanies.add(null); } else { ! targetCompanies.add(cmgr.getPublicCompany(name)); } } *************** *** 149,153 **** && !selectedTargetCompanyName.equals("null")) { selectedTargetCompany = ! cmgr.getCompanyByName(selectedTargetCompanyName); } } --- 149,153 ---- && !selectedTargetCompanyName.equals("null")) { selectedTargetCompany = ! cmgr.getPublicCompany(selectedTargetCompanyName); } } Index: ReachDestinations.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/ReachDestinations.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ReachDestinations.java 30 Dec 2009 11:30:33 -0000 1.4 --- ReachDestinations.java 15 Apr 2010 19:49:50 -0000 1.5 *************** *** 92,96 **** for (String cname : possibleCompanyNames.split(",")) { if (!"".equals(cname)) { ! possibleCompanies.add(cmgr.getCompanyByName(cname)); } } --- 92,96 ---- for (String cname : possibleCompanyNames.split(",")) { if (!"".equals(cname)) { ! possibleCompanies.add(cmgr.getPublicCompany(cname)); } } *************** *** 100,104 **** for (String cname : reachedCompanyNames.split(",")) { if (!"".equals(cname)) { ! reachedCompanies.add(cmgr.getCompanyByName(cname)); } } --- 100,104 ---- for (String cname : reachedCompanyNames.split(",")) { if (!"".equals(cname)) { ! reachedCompanies.add(cmgr.getPublicCompany(cname)); } } |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java StockRound_1856.java CGRFormationRound.java Log Message: Removed a redundant (because duplicate) method Index: StockRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/StockRound_1856.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** StockRound_1856.java 27 Mar 2010 18:27:08 -0000 1.15 --- StockRound_1856.java 15 Apr 2010 19:49:50 -0000 1.16 *************** *** 154,158 **** PublicCompany_CGR cgr = ! (PublicCompany_CGR)companyManager.getCompanyByName(PublicCompany_CGR.NAME); if (cgr.hasStarted() && cgr.getPresident() == currentPlayer && cgr.hasTemporaryPresident()) { --- 154,158 ---- PublicCompany_CGR cgr = ! (PublicCompany_CGR)companyManager.getPublicCompany(PublicCompany_CGR.NAME); if (cgr.hasStarted() && cgr.getPresident() == currentPlayer && cgr.hasTemporaryPresident()) { Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** CGRFormationRound.java 16 Feb 2010 20:19:47 -0000 1.33 --- CGRFormationRound.java 15 Apr 2010 19:49:50 -0000 1.34 *************** *** 22,26 **** private String cgrName = PublicCompany_CGR.NAME; private PublicCompany_CGR cgr ! = (PublicCompany_CGR)gameManager.getCompanyManager().getCompanyByName(cgrName); private List<TrainI> trainsToDiscardFrom = null; private boolean forcedTrainDiscard = true; --- 22,26 ---- private String cgrName = PublicCompany_CGR.NAME; private PublicCompany_CGR cgr ! = (PublicCompany_CGR)gameManager.getCompanyManager().getPublicCompany(cgrName); private List<TrainI> trainsToDiscardFrom = null; private boolean forcedTrainDiscard = true; Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** OperatingRound_1856.java 23 Mar 2010 18:44:17 -0000 1.33 --- OperatingRound_1856.java 15 Apr 2010 19:49:50 -0000 1.34 *************** *** 486,490 **** List<PublicCompanyI> companies = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); ! PublicCompanyI cgr = companyManager.getCompanyByName(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); --- 486,490 ---- List<PublicCompanyI> companies = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); ! PublicCompanyI cgr = companyManager.getPublicCompany(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:58
|
Update of /cvsroot/rails/18xx/rails/game/correct In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/game/correct Modified Files: CashCorrectionAction.java OperatingCost.java Log Message: Removed a redundant (because duplicate) method Index: OperatingCost.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/correct/OperatingCost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** OperatingCost.java 2 Mar 2010 22:15:07 -0000 1.6 --- OperatingCost.java 15 Apr 2010 19:49:50 -0000 1.7 *************** *** 109,113 **** in.defaultReadObject(); if (Util.hasValue(companyName)) ! company = getCompanyManager().getCompanyByName(companyName); } } --- 109,113 ---- in.defaultReadObject(); if (Util.hasValue(companyName)) ! company = getCompanyManager().getPublicCompany(companyName); } } Index: CashCorrectionAction.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/correct/CashCorrectionAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CashCorrectionAction.java 28 Mar 2010 17:05:56 -0000 1.3 --- CashCorrectionAction.java 15 Apr 2010 19:49:50 -0000 1.4 *************** *** 118,122 **** correctCashHolder = getGameManager().getPlayerManager().getPlayerByName(cashHolderName); else if (cashHolderType.equals("PublicCompany")) ! correctCashHolder = getCompanyManager().getCompanyByName(cashHolderName); } } --- 118,122 ---- correctCashHolder = getGameManager().getPlayerManager().getPlayerByName(cashHolderName); else if (cashHolderType.equals("PublicCompany")) ! correctCashHolder = getCompanyManager().getPublicCompany(cashHolderName); } } |
From: Erik V. <ev...@us...> - 2010-04-15 19:49:57
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19350/rails/ui/swing/gamespecific/_1835 Modified Files: StatusWindow_1835.java Log Message: Removed a redundant (because duplicate) method Index: StatusWindow_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** StatusWindow_1835.java 8 Apr 2010 21:24:02 -0000 1.4 --- StatusWindow_1835.java 15 Apr 2010 19:49:50 -0000 1.5 *************** *** 27,31 **** public void init (GameUIManager gameUIManager) { super.init(gameUIManager); ! prussian = gameUIManager.getGameManager().getCompanyManager().getCompanyByName(GameManager_1835.PR_ID); } --- 27,31 ---- public void init (GameUIManager gameUIManager) { super.init(gameUIManager); ! prussian = gameUIManager.getGameManager().getCompanyManager().getPublicCompany(GameManager_1835.PR_ID); } |