From: Stefan F. <ste...@we...> - 2013-08-29 10:56:14
|
<html> <head> </head> <body>You coded against Rail 1.x, this part of the code is upgraded in Rails 2.0 branches.<br> Especially the connectivity functions are improved. If you check out Rails 2.0 you will realize that it supports full verification of tile lays. <br> So I suggest that you code that functionally in 2.0 otherwise it will most likely duplicate efforts and will not be mergeable. <br> <br><br><div class="gmail_quote">Michael Alexander <out...@gm...> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> <div> 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:<br/> <br/> diff --git a/rails/algorithms/NetworkCompanyGraph.java b/rails/algorithms/NetworkCompanyGraph.java<br/> index bd93113..0e5b2c8 100644<br/> --- a/rails/algorithms/NetworkCompanyGraph.java<br/> +++ b/rails/algorithms/NetworkCompanyGraph.java<br/> @@ -64,7 +64,8 @@<br/> return phase2Graph;<br/> }<br/> <br/> - public SimpleGraph<NetworkVertex, NetworkEdge> createRouteGraph(boolean addHQ) {<br/> + <br/> + private SimpleGraph<NetworkVertex, NetworkEdge> createGraph(boolean addHQ, boolean ignoreSinks) {<br/> // get mapgraph from builder<br/> SimpleGraph<NetworkVertex, NetworkEdge> mapGraph = graphBuilder.getMapGraph();<br/> <br/> @@ -88,7 +89,7 @@<br/> // add connection to graph<br/> graph.addVertex(vertex);<br/> graph.addEdge(vertex, hqVertex, new NetworkEdge(vertex, hqVertex, false));<br/> - NetworkIterator iterator = new NetworkIterator(mapGraph, vertex, company);<br/> + NetworkIterator iterator = new NetworkIterator(mapGraph, vertex, company, ignoreSinks);<br/> for (;iterator.hasNext();)<br/> vertexes.add(iterator.next());<br/> // restore sink property<br/> @@ -112,6 +113,14 @@<br/> return graph;<br/> }<br/> <br/> + public SimpleGraph<NetworkVertex, NetworkEdge> createRouteGraph(boolean addHQ) {<br/> + return createGraph(addHQ, false);<br/> + }<br/> +<br/> + public SimpleGraph<NetworkVertex, NetworkEdge> createConnectionGraph(boolean addHQ) {<br/> + return createGraph(addHQ, true);<br/> + }<br/> + <br/> public List<NetworkVertex> getCompanyBaseTokenVertexes(PublicCompanyI company) {<br/> List<NetworkVertex> vertexes = new ArrayList<NetworkVertex>();<br/> for (TokenI token:company.getTokens()){<br/> diff --git a/rails/algorithms/NetworkIterator.java b/rails/algorithms/NetworkIterator.java<br/> index f4029e8..1adc0a6 100644<br/> --- a/rails/algorithms/NetworkIterator.java<br/> +++ b/rails/algorithms/NetworkIterator.java<br/> @@ -26,6 +26,7 @@<br/> private NetworkVertex startVertex;<br/> private boolean startVertexVisited;<br/> private boolean routeIterator;<br/> + private boolean ignoreSinks;<br/> <br/> // internal data<br/> private List<NetworkVertex> stack = new ArrayList<NetworkVertex>();<br/> @@ -41,14 +42,14 @@<br/> <br/> public NetworkIterator(Graph<NetworkVertex, NetworkEdge> graph,<br/> NetworkVertex startVertex) {<br/> - this(graph, startVertex, null);<br/> + this(graph, startVertex, null, false);<br/> }<br/> <br/> /**<br/> * Returns NetworkIterator for specific company<br/> */<br/> public NetworkIterator(Graph<NetworkVertex, NetworkEdge> graph, NetworkVertex startVertex,<br/> - PublicCompanyI company) {<br/> + PublicCompanyI company, boolean ignoreSinks) {<br/> super();<br/> <br/> if (graph == null)<br/> @@ -61,6 +62,7 @@<br/> this.startVertex = startVertex;<br/> this.startVertexVisited = false;<br/> this.routeIterator = false;<br/> + this.ignoreSinks = ignoreSinks;<br/> }<br/> <br/> NetworkIterator setRouteIterator(boolean routeIterator) {<br/> @@ -174,7 +176,7 @@<br/> <br/> private void addUnseenChildrenOf(NetworkVertex vertex, boolean greedy) {<br/> <br/> - if (vertex.isSink()) return;<br/> + if (vertex.isSink() && (!ignoreSinks)) return;<br/> log.debug("Iterator: Add unseen children of " + vertex);<br/> <br/> for (NetworkEdge edge : graph.edgesOf(vertex)) {<br/> diff --git a/rails/algorithms/NetworkVertex.java b/rails/algorithms/NetworkVertex.java<br/> index 91356af..03045b9 100644<br/> --- a/rails/algorithms/NetworkVertex.java<br/> +++ b/rails/algorithms/NetworkVertex.java<br/> @@ -311,7 +311,7 @@<br/> */<br/> public static void initAllRailsVertices(Graph<NetworkVertex, NetworkEdge> graph,<br/> PublicCompanyI company, PhaseI phase) {<br/> -<br/> + <br/> // store vertices for removal<br/> List<NetworkVertex> verticesToRemove = new ArrayList<NetworkVertex>();<br/> for (NetworkVertex v:graph.vertexSet()) {<br/> </div> <div class="gmail_extra"> <br/> <br/> <div class="gmail_quote"> On Wed, Aug 28, 2013 at 4:52 PM, Michael Alexander<span> <<a href="mailto:out...@gm..." target="_blank">out...@gm...</a>></span> wrote:<br/> <blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204) solid;padding-left: 1.0ex;"> <div> <div> Here's what I ended up with so far:<br/> <br/> </div> <div> compA is the private investor<br/> </div> <div> compB is the company to check to see if there is a connection with<br/> </div> <div> <br/> PublicCompanyI compA = operatingCompany.get();<br/> ...<br/> NetworkGraphBuilder nwGraph = NetworkGraphBuilder.create(gameManager);<br/> NetworkCompanyGraph companyGraph = NetworkCompanyGraph.create(nwGraph, compA);<br/> SimpleGraph<NetworkVertex, NetworkEdge> graph = companyGraph.createRouteGraph(true);<br/> Set<NetworkVertex> verticies = graph.vertexSet();<br/> ...<br/> for (TokenI token : compB.getTokens()) {<br/> TokenHolder holder = token.getHolder();<br/> if (!(holder instanceof Stop)) continue;<br/> Stop city = (Stop) holder;<br/> Station station = city.getRelatedStation();<br/> <br/> for (NetworkVertex vert : verticies) {<br/> if (vert.getType() == NetworkVertex.VertexType.STATION) {<br/> Station vertStation = vert.getStation();<br/> if (station == vertStation) {<br/> </div> // There is a link between the companies! Hooray!<br/> <div> }<br/> }<br/> }<br/> }<br/> ...<br/> <br/> </div> <div> 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.<br/> <br/> Mike<br/> </div> <div> <br/> </div> </div> <div class="HOEnZb"> <div class="h5"> <div class="gmail_extra"> <br/> <br/> <div class="gmail_quote"> On Wed, Aug 28, 2013 at 2:38 PM, brett lentz<span> <<a href="mailto:bre...@gm..." target="_blank">bre...@gm...</a>></span> wrote:<br/> <blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204) solid;padding-left: 1.0ex;"> <div> 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.<br/> <br/> It might be possible to leverage that same code to create a route graph that enables detection of destination runs.<br/> <br/> 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. <div> <br/> </div> <div> ---Brett. </div> </div> <div class="gmail_extra"> <span><font color="#888888"><br clear="all"/> <div> <br/> ---Brett. </div> </font></span> <div> <div> <br/> <br/> <div class="gmail_quote"> On Wed, Aug 28, 2013 at 9:50 AM, Chris Shaffer<span> <<a href="mailto:chr...@gm..." target="_blank">chr...@gm...</a>></span> wrote:<br/> <blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204) solid;padding-left: 1.0ex;"> There are games where tokens do block destinations, so whatever code<br/> you write should allow for that possibility. There are also games<br/> where connections are considered complete as soon as the tile is laid,<br/> and others where the check occurs during the relevant company's<br/> operating turn.<br/> <div> <br/> --<br/> Chris<br/> <br/> Please consider the environment before printing this e-mail.<br/> <br/> <br/> </div> <div> <div> On Wed, Aug 28, 2013 at 6:35 AM, Michael Alexander<br/> <<a href="mailto:out...@gm..." target="_blank">out...@gm...</a>> wrote:<br/> > Both Major Companies in 1856 and Foreign Investors in 1880 have the idea of<br/> > needing to reach a destination. Both are implemented by having the game<br/> > player use a special action to tell the game engine that a connection has<br/> > taken place. Once the connection exists, some one time event occurs. It<br/> > seems like if there is code that could be used to determine if a connection<br/> > exists, the game could automatically determine that without relying on the<br/> > player to tell it.<br/> ><br/> > So I actually want something slightly different than what I said. It's not<br/> > that the current company can make a run between two hexes that I want to<br/> > know, it's that a connection exists (regardless of tokens).<br/> ><br/> > Mike<br/> ><br/> ><br/> > On Wed, Aug 28, 2013 at 9:28 AM, Chris Shaffer <<a href="mailto:chr...@gm..." target="_blank">chr...@gm...</a>><br/> > wrote:<br/> >><br/> >> Would this be for games where companies are limited to building track<br/> >> where their trains can actually reach, or some other purpose?<br/> >><br/> >> --<br/> >> Chris<br/> >><br/> >> Please consider the environment before printing this e-mail.<br/> >><br/> >><br/> >> On Tue, Aug 27, 2013 at 11:24 PM, Michael Alexander<br/> >> <<a href="mailto:out...@gm..." target="_blank">out...@gm...</a>> wrote:<br/> >> > Everyone,<br/> >> ><br/> >> > I'd like to add a check to see if the currently operating company<br/> >> > can<br/> >> > run from specific MapHex to another. It seems like there should be a<br/> >> > way to<br/> >> > do this, since a similar calculation would have to be made when<br/> >> > determining<br/> >> > what MapHexs are eligible to have a tile placed, but I can't seem to<br/> >> > figure<br/> >> > out how to do it. What am I missing?<br/> >> ><br/> >> > Thanks,<br/> >> ><br/> >> > Michael Alexander<br/> >> ><br/> >> ><br/> >> > ------------------------------------------------------------------------------<br/> >> > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!<br/> >> > Discover the easy way to master current and previous Microsoft<br/> >> > technologies<br/> >> > and advance your career. Get an incredible 1,500+ hours of step-by-step<br/> >> > tutorial videos with LearnDevNow. Subscribe today and save!<br/> >> ><br/> >> ><a href="http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk" target="_blank"> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk</a><br/> >> > _______________________________________________<br/> >> > Rails-devel mailing list<br/> >> ><a href="mailto:Rai...@li..." target="_blank"> Rai...@li...</a><br/> >> ><a href="https://lists.sourceforge.net/lists/listinfo/rails-devel" target="_blank"> https://lists.sourceforge.net/lists/listinfo/rails-devel</a><br/> >> ><br/> >><br/> >><br/> >> ------------------------------------------------------------------------------<br/> >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!<br/> >> Discover the easy way to master current and previous Microsoft<br/> >> technologies<br/> >> and advance your career. Get an incredible 1,500+ hours of step-by-step<br/> >> tutorial videos with LearnDevNow. Subscribe today and save!<br/> >><br/> >><a href="http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk" target="_blank"> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk</a><br/> >> _______________________________________________<br/> >> Rails-devel mailing list<br/> >><a href="mailto:Rai...@li..." target="_blank"> Rai...@li...</a><br/> >><a href="https://lists.sourceforge.net/lists/listinfo/rails-devel" target="_blank"> https://lists.sourceforge.net/lists/listinfo/rails-devel</a><br/> ><br/> ><br/> ><br/> > ------------------------------------------------------------------------------<br/> > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!<br/> > Discover the easy way to master current and previous Microsoft technologies<br/> > and advance your career. Get an incredible 1,500+ hours of step-by-step<br/> > tutorial videos with LearnDevNow. Subscribe today and save!<br/> ><a href="http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk" target="_blank"> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk</a><br/> > _______________________________________________<br/> > Rails-devel mailing list<br/> ><a href="mailto:Rai...@li..." target="_blank"> Rai...@li...</a><br/> ><a href="https://lists.sourceforge.net/lists/listinfo/rails-devel" target="_blank"> https://lists.sourceforge.net/lists/listinfo/rails-devel</a><br/> ><br/> <br/> ------------------------------------------------------------------------------<br/> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!<br/> Discover the easy way to master current and previous Microsoft technologies<br/> and advance your career. Get an incredible 1,500+ hours of step-by-step<br/> tutorial videos with LearnDevNow. Subscribe today and save!<br/> <a href="http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk</a><br/> _______________________________________________<br/> Rails-devel mailing list<br/> <a href="mailto:Rai...@li..." target="_blank">Rai...@li...</a><br/> <a href="https://lists.sourceforge.net/lists/listinfo/rails-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/rails-devel</a><br/> </div> </div> </blockquote> </div> <br/> </div> </div> </div> <br/> ------------------------------------------------------------------------------<br/> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!<br/> Discover the easy way to master current and previous Microsoft technologies<br/> and advance your career. Get an incredible 1,500+ hours of step-by-step<br/> tutorial videos with LearnDevNow. Subscribe today and save!<br/> <a href="http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk</a><br/> _______________________________________________<br/> Rails-devel mailing list<br/> <a href="mailto:Rai...@li..." target="_blank">Rai...@li...</a><br/> <a href="https://lists.sourceforge.net/lists/listinfo/rails-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/rails-devel</a><br/> <br/> </blockquote> </div> <br/> </div> </div> </div> </blockquote> </div> <br/> </div> </blockquote></div></body> </html> |