From: Michael A. <out...@gm...> - 2013-08-29 05:27:58
|
So what I found was that the NetworkIterator stopped at nodes that were sinks. If I want to be able to build a graph that just tells me that I'm connected and ignores tokens in the way, I think I need to add a setting to NetworkIterator to tell it if it should ignore sinks. As this is a complicated area of the code, and it's not limited to the 1880 specific areas, I'd appreciate some feedback on my proposed changes: diff --git a/rails/algorithms/NetworkCompanyGraph.java b/rails/algorithms/NetworkCompanyGraph.java index bd93113..0e5b2c8 100644 --- a/rails/algorithms/NetworkCompanyGraph.java +++ b/rails/algorithms/NetworkCompanyGraph.java @@ -64,7 +64,8 @@ return phase2Graph; } - public SimpleGraph<NetworkVertex, NetworkEdge> createRouteGraph(boolean addHQ) { + + private SimpleGraph<NetworkVertex, NetworkEdge> createGraph(boolean addHQ, boolean ignoreSinks) { // get mapgraph from builder SimpleGraph<NetworkVertex, NetworkEdge> mapGraph = graphBuilder.getMapGraph(); @@ -88,7 +89,7 @@ // add connection to graph graph.addVertex(vertex); graph.addEdge(vertex, hqVertex, new NetworkEdge(vertex, hqVertex, false)); - NetworkIterator iterator = new NetworkIterator(mapGraph, vertex, company); + NetworkIterator iterator = new NetworkIterator(mapGraph, vertex, company, ignoreSinks); for (;iterator.hasNext();) vertexes.add(iterator.next()); // restore sink property @@ -112,6 +113,14 @@ return graph; } + public SimpleGraph<NetworkVertex, NetworkEdge> createRouteGraph(boolean addHQ) { + return createGraph(addHQ, false); + } + + public SimpleGraph<NetworkVertex, NetworkEdge> createConnectionGraph(boolean addHQ) { + return createGraph(addHQ, true); + } + public List<NetworkVertex> getCompanyBaseTokenVertexes(PublicCompanyI company) { List<NetworkVertex> vertexes = new ArrayList<NetworkVertex>(); for (TokenI token:company.getTokens()){ diff --git a/rails/algorithms/NetworkIterator.java b/rails/algorithms/NetworkIterator.java index f4029e8..1adc0a6 100644 --- a/rails/algorithms/NetworkIterator.java +++ b/rails/algorithms/NetworkIterator.java @@ -26,6 +26,7 @@ private NetworkVertex startVertex; private boolean startVertexVisited; private boolean routeIterator; + private boolean ignoreSinks; // internal data private List<NetworkVertex> stack = new ArrayList<NetworkVertex>(); @@ -41,14 +42,14 @@ public NetworkIterator(Graph<NetworkVertex, NetworkEdge> graph, NetworkVertex startVertex) { - this(graph, startVertex, null); + this(graph, startVertex, null, false); } /** * Returns NetworkIterator for specific company */ public NetworkIterator(Graph<NetworkVertex, NetworkEdge> graph, NetworkVertex startVertex, - PublicCompanyI company) { + PublicCompanyI company, boolean ignoreSinks) { super(); if (graph == null) @@ -61,6 +62,7 @@ this.startVertex = startVertex; this.startVertexVisited = false; this.routeIterator = false; + this.ignoreSinks = ignoreSinks; } NetworkIterator setRouteIterator(boolean routeIterator) { @@ -174,7 +176,7 @@ private void addUnseenChildrenOf(NetworkVertex vertex, boolean greedy) { - if (vertex.isSink()) return; + if (vertex.isSink() && (!ignoreSinks)) return; log.debug("Iterator: Add unseen children of " + vertex); for (NetworkEdge edge : graph.edgesOf(vertex)) { diff --git a/rails/algorithms/NetworkVertex.java b/rails/algorithms/NetworkVertex.java index 91356af..03045b9 100644 --- a/rails/algorithms/NetworkVertex.java +++ b/rails/algorithms/NetworkVertex.java @@ -311,7 +311,7 @@ */ public static void initAllRailsVertices(Graph<NetworkVertex, NetworkEdge> graph, PublicCompanyI company, PhaseI phase) { - + // store vertices for removal List<NetworkVertex> verticesToRemove = new ArrayList<NetworkVertex>(); for (NetworkVertex v:graph.vertexSet()) { On Wed, Aug 28, 2013 at 4:52 PM, Michael Alexander <out...@gm...>wrote: > Here's what I ended up with so far: > > compA is the private investor > compB is the company to check to see if there is a connection with > > PublicCompanyI compA = operatingCompany.get(); > ... > NetworkGraphBuilder nwGraph = > NetworkGraphBuilder.create(gameManager); > NetworkCompanyGraph companyGraph = > NetworkCompanyGraph.create(nwGraph, compA); > SimpleGraph<NetworkVertex, NetworkEdge> graph = > companyGraph.createRouteGraph(true); > Set<NetworkVertex> verticies = graph.vertexSet(); > ... > for (TokenI token : compB.getTokens()) { > TokenHolder holder = token.getHolder(); > if (!(holder instanceof Stop)) continue; > Stop city = (Stop) holder; > Station station = city.getRelatedStation(); > > for (NetworkVertex vert : verticies) { > if (vert.getType() == > NetworkVertex.VertexType.STATION) { > Station vertStation = vert.getStation(); > if (station == vertStation) { > // There is a link between the companies! > Hooray! > } > } > } > } > ... > > This seems to work for simple cases, however, I suspect (without digging > too much) that it will get blocked by tokens, which I can't have. I bet it > won't be too hard to fix, tho. > > Mike > > > > On Wed, Aug 28, 2013 at 2:38 PM, brett lentz <bre...@gm...>wrote: > >> In order to do tile rotations, there is already logic that is aware of >> the "exits" of a tile. There's also the route suggestion code. >> >> It might be possible to leverage that same code to create a route graph >> that enables detection of destination runs. >> >> It probably needs a fair bit of work to adapt for this purpose, but those >> are at least places in the code to start looking. >> >> ---Brett. >> >> >> ---Brett. >> >> >> On Wed, Aug 28, 2013 at 9:50 AM, Chris Shaffer <chr...@gm...>wrote: >> >>> There are games where tokens do block destinations, so whatever code >>> you write should allow for that possibility. There are also games >>> where connections are considered complete as soon as the tile is laid, >>> and others where the check occurs during the relevant company's >>> operating turn. >>> >>> -- >>> Chris >>> >>> Please consider the environment before printing this e-mail. >>> >>> >>> On Wed, Aug 28, 2013 at 6:35 AM, Michael Alexander >>> <out...@gm...> wrote: >>> > Both Major Companies in 1856 and Foreign Investors in 1880 have the >>> idea of >>> > needing to reach a destination. Both are implemented by having the >>> game >>> > player use a special action to tell the game engine that a connection >>> has >>> > taken place. Once the connection exists, some one time event occurs. >>> It >>> > seems like if there is code that could be used to determine if a >>> connection >>> > exists, the game could automatically determine that without relying on >>> the >>> > player to tell it. >>> > >>> > So I actually want something slightly different than what I said. >>> It's not >>> > that the current company can make a run between two hexes that I want >>> to >>> > know, it's that a connection exists (regardless of tokens). >>> > >>> > Mike >>> > >>> > >>> > On Wed, Aug 28, 2013 at 9:28 AM, Chris Shaffer < >>> chr...@gm...> >>> > wrote: >>> >> >>> >> Would this be for games where companies are limited to building track >>> >> where their trains can actually reach, or some other purpose? >>> >> >>> >> -- >>> >> Chris >>> >> >>> >> Please consider the environment before printing this e-mail. >>> >> >>> >> >>> >> On Tue, Aug 27, 2013 at 11:24 PM, Michael Alexander >>> >> <out...@gm...> wrote: >>> >> > Everyone, >>> >> > >>> >> > I'd like to add a check to see if the currently operating >>> company >>> >> > can >>> >> > run from specific MapHex to another. It seems like there should be >>> a >>> >> > way to >>> >> > do this, since a similar calculation would have to be made when >>> >> > determining >>> >> > what MapHexs are eligible to have a tile placed, but I can't seem to >>> >> > figure >>> >> > out how to do it. What am I missing? >>> >> > >>> >> > Thanks, >>> >> > >>> >> > Michael Alexander >>> >> > >>> >> > >>> >> > >>> ------------------------------------------------------------------------------ >>> >> > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, >>> more! >>> >> > Discover the easy way to master current and previous Microsoft >>> >> > technologies >>> >> > and advance your career. Get an incredible 1,500+ hours of >>> step-by-step >>> >> > tutorial videos with LearnDevNow. Subscribe today and save! >>> >> > >>> >> > >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> >> > _______________________________________________ >>> >> > Rails-devel mailing list >>> >> > Rai...@li... >>> >> > https://lists.sourceforge.net/lists/listinfo/rails-devel >>> >> > >>> >> >>> >> >>> >> >>> ------------------------------------------------------------------------------ >>> >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> >> Discover the easy way to master current and previous Microsoft >>> >> technologies >>> >> and advance your career. Get an incredible 1,500+ hours of >>> step-by-step >>> >> tutorial videos with LearnDevNow. Subscribe today and save! >>> >> >>> >> >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> >> _______________________________________________ >>> >> Rails-devel mailing list >>> >> Rai...@li... >>> >> https://lists.sourceforge.net/lists/listinfo/rails-devel >>> > >>> > >>> > >>> > >>> ------------------------------------------------------------------------------ >>> > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> > Discover the easy way to master current and previous Microsoft >>> technologies >>> > and advance your career. Get an incredible 1,500+ hours of step-by-step >>> > tutorial videos with LearnDevNow. Subscribe today and save! >>> > >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> > _______________________________________________ >>> > Rails-devel mailing list >>> > Rai...@li... >>> > https://lists.sourceforge.net/lists/listinfo/rails-devel >>> > >>> >>> >>> ------------------------------------------------------------------------------ >>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> Discover the easy way to master current and previous Microsoft >>> technologies >>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>> tutorial videos with LearnDevNow. Subscribe today and save! >>> >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> Rails-devel mailing list >>> Rai...@li... >>> https://lists.sourceforge.net/lists/listinfo/rails-devel >>> >> >> >> >> ------------------------------------------------------------------------------ >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >> Discover the easy way to master current and previous Microsoft >> technologies >> and advance your career. Get an incredible 1,500+ hours of step-by-step >> tutorial videos with LearnDevNow. Subscribe today and save! >> >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >> _______________________________________________ >> Rails-devel mailing list >> Rai...@li... >> https://lists.sourceforge.net/lists/listinfo/rails-devel >> >> > |