Finding the longest road in a Settlers of Catan game algorithmically

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-07-07T02:09:50Z Indexed on 2012/09/18 3:38 UTC
Read the original article Hit count: 162

Filed under:
|
|

I'm writing a Settlers of Catan clone for a class. One of the extra credit features is automatically determining which player has the longest road. I've thought about it, and it seems like some slight variation on depth-first search could work, but I'm having trouble figuring out what to do with cycle detection, how to handle the joining of a player's two initial road networks, and a few other minutiae. How could I do this algorithmically?

For those unfamiliar with the game, I'll try to describe the problem concisely and abstractly: I need to find the longest possible path in an undirected cyclic graph.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about graph