Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSandman

Posted 07 September 2012 - 05:14 AM

Sounds like it should work, but it also sounds a bit overcomplicated, with lots of needless hunting around in lists.

You don't need to maintain giant lists of lists. If you are familiar with recursion you can write a pretty simple function to do the test.

Ropey Pseudocode:

bool ConnectsToEdge(Edge edgeToCheck, Hex currentHex, Player player)
{
	for each neighbourHex
	{
		if(neighbourHex.IsOwnedByPlayer(player))
		{
			if neighbourHex.IsEdgeHex(edgeToCheck)
				return true
			else
				if ConnectsToEdge(edgeToCheck, neighbourHex, player)
					return true
		}
	}
	return false
}

#1Sandman

Posted 07 September 2012 - 05:13 AM

Sounds like it should work, but it also sounds a bit overcomplicated, with lots of needless hunting around in lists.

You don't need to maintain giant lists of lists. If you are familiar with recursion you can write a pretty simple function to do the test.

Ropey Pseudocode:

bool ConnectsToEdge(Edge edgeToCheck, Hex currentHex, Player player)
{
    for each neighbour
    {
        if(neighbour.IsOwnedByPlayer(player))
        {
            if neighbour.IsEdgeHex(edgeToCheck)
                return true
            else
                if ConnectsToEdge(edgeToCheck, neighbour, player)
                    return true
        }
    }
    return false
}

PARTNERS