Click here to Skip to main content
15,913,101 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Motion tracking algorythm from Pan and tilt video feed Pin
jk chan17-Jan-11 2:28
jk chan17-Jan-11 2:28 
GeneralRe: Motion tracking algorythm from Pan and tilt video feed Pin
GDMFSOB17-Jan-11 2:39
GDMFSOB17-Jan-11 2:39 
AnswerRe: InstallShield Pin
Peter_in_27806-Jan-11 19:07
professionalPeter_in_27806-Jan-11 19:07 
GeneralRe: InstallShield Pin
lucky_12216-Jan-11 22:30
lucky_12216-Jan-11 22:30 
AnswerRe: InstallShield Pin
Richard MacCutchan6-Jan-11 21:37
mveRichard MacCutchan6-Jan-11 21:37 
AnswerRe: installshield Pin
JOAT-MON6-Jan-11 9:09
JOAT-MON6-Jan-11 9:09 
GeneralRe: installshield Pin
R. Erasmus24-Mar-11 21:21
R. Erasmus24-Mar-11 21:21 
QuestionStuck on an a* pathfinding algorithm [modified] Pin
venomation3-Jan-11 17:21
venomation3-Jan-11 17:21 
SOLVED

For anyone interested here is the solution to my problem:

public IEnumerable<Tile> PathFind(Tile startNode, Tile endNode)
{
    List<Tile> openNodes = new List<Tile>() { startNode };
    List<Tile> closedNodes = new List<Tile>();
    Tile lowestFScore = null;
    while (openNodes.Count > 0 && lowestFScore != endNode)
    {
        lowestFScore = GetLowestScoringTile(openNodes, endNode);

        openNodes.Remove(lowestFScore);

        if (lowestFScore == null)
            return null;

        SwitchFromOpenToClosedList(lowestFScore, openNodes, closedNodes);

        IEnumerable<Tile> neighbouringTile = GetNeighbouringTiles(lowestFScore);

        foreach (Tile n in neighbouringTile)
        {
            if (IgnoreTile(n))
            {
                SwitchFromOpenToClosedList(n, openNodes, closedNodes);
                continue;
            }

            if (closedNodes.Contains(n)) continue;

            if (!openNodes.Contains(n))
            {
                openNodes.Add(n);
                n.Parent = lowestFScore;
            }


        }
    }

    return RenderToGrid(endNode);
}


I have done my research and attempted several times to create my version of the infamous A* path-finding algorithm.
The algorithm I have made does seem to work though!...(unsurprisingly)

If anyone can help me it would be great, I am sure it is just a logic problem in the main part of the method:

public void PathFind(Tile startNode, Tile endNode)
        {
            List<Tile> openNodes = new List<Tile>() { startNode };
            List<Tile> closedNodes = new List<Tile>();

            Tile currentNode = startNode;
            while (true)
            {
                foreach (Tile n in GetNeighbouringTiles(currentNode))
                {
                    if (closedNodes.Contains(n)) continue;

                    if (IgnoreTile(n))
                    {
                        if (!closedNodes.Contains(n))
                        {
                            closedNodes.Add(n);
                            continue;
                        }
                    }


                    n.Parent = currentNode;

                    if (!openNodes.Contains(n))
                        openNodes.Add(n);

                }

                if (openNodes.Contains(currentNode))
                    openNodes.Remove(currentNode);


                Tile lowestScoring = GetLowestScoringTile(openNodes, endNode);
                if (lowestScoring == null) lowestScoring = currentNode;

                if (openNodes.Contains(lowestScoring))
                {
                    openNodes.Remove(lowestScoring);
                }

                foreach (Tile n in GetNeighbouringTiles(lowestScoring))
                {
                    if (closedNodes.Contains(n)) continue;
                    if (IgnoreTile(n))
                    {
                        if (!closedNodes.Contains(n))
                        {
                            closedNodes.Add(n);
                            continue;
                        }
                    }


                    n.Parent = lowestScoring;
                    if (!openNodes.Contains(n))
                        openNodes.Add(n);
                    else
                    {
                        if (Tile.GetCost(lowestScoring, endNode) > Tile.GetCost(n, endNode))
                        {
                            n.Parent = lowestScoring;
                            lowestScoring = n;
                        }
                    }
                }

                currentNode = lowestScoring;

                if (openNodes.Count == 0 || currentNode == endNode) 
                    return;



            }
        }


I am expecting the method to return when there are no more nodes remaining (which tells me that there is no way of getting from a to b), or the current node is the end node (which should mean that I can just re-curse through each "Parent" attribute of the endNode to cycle through the path.

Edit1: I noticed that the first " n.Parent = currentNode;" is never reached!
Edit2: The "GetNeighbouringTiles" method was incorrect, it didn't search for moving down... The pathfinding method hits an infinite loop now...


It only ever does the former result D'Oh! | :doh:

modified on Tuesday, January 4, 2011 1:40 PM

AnswerRe: Stuck on an a* pathfinding algorithm Pin
Espen Harlinn4-Jan-11 0:46
professionalEspen Harlinn4-Jan-11 0:46 
GeneralRe: Stuck on an a* pathfinding algorithm Pin
venomation4-Jan-11 7:44
venomation4-Jan-11 7:44 
GeneralRe: Stuck on an a* pathfinding algorithm Pin
Espen Harlinn4-Jan-11 8:27
professionalEspen Harlinn4-Jan-11 8:27 
AnswerRe: Stuck on an a* pathfinding algorithm Pin
ely_bob10-Jan-11 9:55
professionalely_bob10-Jan-11 9:55 
QuestionI'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright20-Dec-10 15:23
professionalRoger Wright20-Dec-10 15:23 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
GlobX20-Dec-10 16:07
GlobX20-Dec-10 16:07 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright20-Dec-10 16:48
professionalRoger Wright20-Dec-10 16:48 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
GlobX20-Dec-10 16:58
GlobX20-Dec-10 16:58 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright20-Dec-10 17:53
professionalRoger Wright20-Dec-10 17:53 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Luc Pattyn20-Dec-10 16:58
sitebuilderLuc Pattyn20-Dec-10 16:58 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright20-Dec-10 17:51
professionalRoger Wright20-Dec-10 17:51 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
GlobX20-Dec-10 19:30
GlobX20-Dec-10 19:30 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright22-Dec-10 4:03
professionalRoger Wright22-Dec-10 4:03 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
agolddog23-Dec-10 4:06
agolddog23-Dec-10 4:06 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright23-Dec-10 5:05
professionalRoger Wright23-Dec-10 5:05 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Luc Pattyn23-Dec-10 5:39
sitebuilderLuc Pattyn23-Dec-10 5:39 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
jschell23-Dec-10 8:25
jschell23-Dec-10 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.