lundi 15 octobre 2018

crash after some iteration of a c++ custom tree

I'm writing a simple sliding tiles (3x3) solver. That's my main function main and tha's my other file It's not the best approach for sure i just generate all the possible configuration but I don't know why during the execution my pc freeze and I must manuallly restart. the's the main code

node *tree;
std::list<node> open;
tree=new node;
tree->parent=NULL;
tree->s.game[0][0]=8;
tree->s.game[0][1]=2;
tree->s.game[0][2]=7;
tree->s.game[1][0]=4;
tree->s.game[1][1]=3;
tree->s.game[1][2]=6;
tree->s.game[2][0]=5;
tree->s.game[2][1]=1;
tree->s.game[2][2]=0;
tree->s.pos.row=2;
tree->s.pos.col=2;

expand_node(tree);
open.push_back(tree->childs[0]);
for (int i = 1; i < 4; ++i)
    for(auto v : open)
        if(!(v.s==tree->childs[i].s))
            open.push_back(tree->childs[i]);

auto it=open.begin();
while(!(tree->s==final))
{

    tree->parent=it->parent;
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
            tree->s.game[i][j]=it->s.game[i][j];   

    expand_node(tree);
    for (int i = 0; i < 4; ++i)
        for(auto v : open)
            if(!(v.s==tree->childs[i].s))
                open.push_back(tree->childs[i]);
        printf("ok\n");
it++;

}      
print_s(tree->s);

ps I compiled everything with

g++ -Wall -Wextra -std=c++11 main.cpp

Aucun commentaire:

Enregistrer un commentaire