Пример #1
0
 P_II checkJump(P_II now,P_II pre)
 {
     P_II dir=M_P(now.first-pre.first,now.second-pre.second);
     P_II tmp=M_P(-1,-1);
     if (mazer.checkMaze(now.first,now.second) == false)
         return tmp;
     if (now == end)
         return now;
     if (dir.first != 0 && dir.second != 0)
     {
         if ((mazer.checkMaze(now.first-dir.first,now.second+dir.second)
          && !mazer.checkMaze(now.first-dir.first,now.second))
         ||  (mazer.checkMaze(now.first+dir.first,now.second-dir.second)
          && !mazer.checkMaze(now.first,now.second-dir.second)))
             return now;
     }
     else
     {
         if (dir.first != 0)
         {
             if ((mazer.checkMaze(now.first+dir.first,now.second+1)
              && !mazer.checkMaze(now.first,now.second+1))
             ||  (mazer.checkMaze(now.first+dir.first,now.second-1)
              && !mazer.checkMaze(now.first,now.second-1)))
                 return now;
         }
         else
         {
             if ((mazer.checkMaze(now.first+1,now.second+dir.second)
              && !mazer.checkMaze(now.first+1,now.second))
             ||  (mazer.checkMaze(now.first-1,now.second+dir.second)
              && !mazer.checkMaze(now.first-1,now.second)))
                 return now;
         }
     }
     if (dir.first != 0 && dir.second != 0)
     {
         tmp=checkJump(M_P(now.first+dir.first,now.second),now);
         P_II t2=checkJump(M_P(now.first,now.second+dir.second),now);
         if (tmp.first != -1 ||  t2.first != -1)
             return now;
     }
     if (mazer.checkMaze(now.first+dir.first,now.second)
     ||  mazer.checkMaze(now.first,now.second+dir.second))
     {
         tmp=checkJump(M_P(now.first+dir.first,now.second+dir.second),now);
         if (tmp.first != -1)
             return tmp;
     }
     return tmp;
 }
Пример #2
0
    V_PII neighbourPrune(Node c)
    {
        V_PII t;
        int i;
        P_II dir;
        t.clear();
        if (c.haveParent())
        {
            dir=c.getDirection();
            if (dir.first != 0 && dir.second != 0)
            {
                if (mazer.checkMaze(c.pos.first,c.pos.second+dir.second))
                        t.push_back(M_P(c.pos.first,c.pos.second+dir.second));

                if (mazer.checkMaze(c.pos.first+dir.first,c.pos.second))
                        t.push_back(M_P(c.pos.first+dir.first,c.pos.second));

                if (mazer.checkMaze(c.pos.first,c.pos.second+dir.second)
                ||  mazer.checkMaze(c.pos.first+dir.first,c.pos.second))
                        t.push_back(M_P(c.pos.first+dir.first,c.pos.second+dir.second));

                if (!mazer.checkMaze(c.pos.first-dir.first,c.pos.second)
                &&  mazer.checkMaze(c.pos.first,c.pos.second+dir.second))
                        t.push_back(M_P(c.pos.first-dir.first,c.pos.second+dir.second));

                if (!mazer.checkMaze(c.pos.first,c.pos.second-dir.second)
                &&  mazer.checkMaze(c.pos.first+dir.first,c.pos.second))
                        t.push_back(M_P(c.pos.first+dir.first,c.pos.second-dir.second));
            }
            else
            {
                if (dir.first == 0)
                {
                    if (mazer.checkMaze(c.pos.first,c.pos.second+dir.second))
                    {
                        if (mazer.checkMaze(c.pos.first,c.pos.second+dir.second))
                                t.push_back(M_P(c.pos.first,c.pos.second+dir.second));

                        if (!mazer.checkMaze(c.pos.first+1,c.pos.second))
                                t.push_back(M_P(c.pos.first+1,c.pos.second+dir.second));

                        if (!mazer.checkMaze(c.pos.first-1,c.pos.second))
                                t.push_back(M_P(c.pos.first-1,c.pos.second+dir.second));
                    }
                }
                else
                {
                    if (mazer.checkMaze(c.pos.first+dir.first,c.pos.second))
                    {
                        if (mazer.checkMaze(c.pos.first+dir.first,c.pos.second))
                                t.push_back(M_P(c.pos.first+dir.first,c.pos.second));

                        if (!mazer.checkMaze(c.pos.first,c.pos.second+1))
                                t.push_back(M_P(c.pos.first+dir.first,c.pos.second+1));

                        if (!mazer.checkMaze(c.pos.first,c.pos.second-1))
                                t.push_back(M_P(c.pos.first+dir.first,c.pos.second-1));
                    }
                }
            }
        }
        else
        {
            for (i=0; i<4; i++)
            {
                if (mazer.checkMaze(c.pos.first+g_dir[i][0],c.pos.second+g_dir[i][1]))
                        t.push_back(M_P(c.pos.first+g_dir[i][0],c.pos.second+g_dir[i][1]));
            }

            if (mazer.checkMaze(c.pos.first+1,c.pos.second) || mazer.checkMaze(c.pos.first,c.pos.second+1))
            {
                if (mazer.checkMaze(c.pos.first+1,c.pos.second+1))
                    t.push_back(M_P(c.pos.first+1,c.pos.second+1));
            }

            if (mazer.checkMaze(c.pos.first+1,c.pos.second) || mazer.checkMaze(c.pos.first,c.pos.second-1))
            {
                if (mazer.checkMaze(c.pos.first+1,c.pos.second-1))
                {

                    t.push_back(M_P(c.pos.first+1,c.pos.second-1));
                }
            }
            if (mazer.checkMaze(c.pos.first-1,c.pos.second) || mazer.checkMaze(c.pos.first,c.pos.second+1))
            {
                if (mazer.checkMaze(c.pos.first-1,c.pos.second+1))
                    t.push_back(M_P(c.pos.first-1,c.pos.second+1));
            }
            if (mazer.checkMaze(c.pos.first-1,c.pos.second) || mazer.checkMaze(c.pos.first,c.pos.second-1))
            {
                if (mazer.checkMaze(c.pos.first-1,c.pos.second-1))
                    t.push_back(M_P(c.pos.first-1,c.pos.second-1));
            }
        }
        for (i=0; i<t.size(); i++)
        {
            printf("%d %d\n",t[i].first,t[i].second);
        }
        return t;
    }