C++编程之美-代码清单1-23

代码清单1-23

bool GenarateValidMatrix()
{
     // prepare for the search 

     Coord coCurrent;
     coCurrent.x = 0;
     coCurrent.y = 0;

     while(true)
     {
          Cell c = m_cells[coCurrent.x, coCurrent.y];
        ArrayList al;

        if(!c.IsProcessed)
        {
             al = GetValidValueList(coCurrent);
             c.ValidList = al;
        }

        if(c.ValidList.Count > 0)
        {
             c.PickNextValidValue();
             if(coCurrent.x == this.Size - 1 && 
                  coCurrent.y == this.Size - 1)
             {
                  break;          // we reach the end of the matrix
             }
             else                // keep going to the next one
             {
                  coCurrent = NextCoord(coCurrent);
             }
        }
        else
        {
             // if we reach the beginning, break out
             if(coCurrent.x == 0 && coCurrent.y == 0)
             {
                  break;
             }
             else
             {
                  c.Clear();
                  coCurrent = PrevCoord(coCurrent);
             }
        }
    }
    return true; 
}
发布了1211 篇原创文章 · 获赞 951 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/104027296