
#include "labyrinth.hpp"

#include "map.h"

labyrinth::labyrinth(const char * map, int w, int h)
{
    _map = map;
    _w = w;
    _h = h;
}
    
//stack all route
stack<node> * labyrinth::getAllNeighbor(int from)
{
    //initialisation
    stack<node> * neighbor = new stack<node>;                        //pile de chemin
    node tmp;
    tmp.dist = 0;
    tmp.cost = 0;
    tmp.parent = from;
    
    if (NOTTOP(from, _w, _h))
        if (*(_map+UP(from, _w)) != '1')
        {
            tmp.index = UP(from, _w);
            neighbor->push(tmp);
        }
    if (NOTBOTTOM(from, _w, _h))
        if (*(_map+DOWN(from, _w)) != '1')
        {
            tmp.index = DOWN(from, _w);
            neighbor->push(tmp);
        }
    if (NOTEDGELF(from, _w, _h))
        if (*(_map+LEFT(from, _w)) != '1')
        {
            tmp.index = LEFT(from, _w);
            neighbor->push(tmp);
        }
    if (NOTEDGERG(from, _w, _h))
        if (*(_map+RIGHT(from, _w)) != '1')
        {
            tmp.index = RIGHT(from, _w);
            neighbor->push(tmp);
        }
    
    return neighbor;
}
