Exemplo n.º 1
0
bool CTipDlg::ConfirmNode(void)
{
	int lev = 1;
	for(int lev = 1;lev < 9;lev ++)
	{
		for(CNode *pt = m_nodeList[lev].GetHead();pt != NULL;pt = pt->next)
		{
			for(int num = 1;num < 10;num ++)
			{
				if(pt->hasNum(num))
				{
					bool otherHas = false;
					for(int i = 0;i < 9;i ++)
					{
						if(m_node[i][pt->getRow()].hasNum(num) && i != pt->getCol())
						{
							otherHas = true;
							break;
						}
					}

					if(otherHas)
					{
						otherHas = false;
						for(int i = 0;i < 9;i ++)
						{
							if(m_node[pt->getCol()][i].hasNum(num) && i != pt->getRow())
							{
								otherHas = true;
								break;
							}
						}
					}
					else
					{
						
						NodeRC rc;
						rc.col = pt->getCol();
						rc.row = pt->getRow();
						rc.way = 1;
						m_vectorNum.push_back(rc);


						goto labelEnd2;
					}

					if(otherHas)
					{
						otherHas = false;
						int baseRow = pt->getRow() / 3 * 3;
						int baseCol = pt->getCol() / 3 * 3;
						for(int i = baseRow;i < baseRow + 3;i ++)
						{
							for(int j = baseCol;j < baseCol + 3;j ++)
							{
								if(m_node[j][i].hasNum(num) && !(i == pt->getRow() && j == pt->getCol()))
								{
									otherHas = true;
									goto labelEnd2;
								}
							}
						}
					}
					else
					{
						
						NodeRC rc;
						rc.col = pt->getCol();
						rc.row = pt->getRow();
						rc.way = 2;
						m_vectorNum.push_back(rc);

						goto labelEnd2;
					}
					if(!otherHas)
					{
						NodeRC rc;
						rc.col = pt->getCol();
						rc.row = pt->getRow();
						rc.way = 3;
						m_vectorNum.push_back(rc);
					}
labelEnd2:
					if(!otherHas)
					{
						m_nodeList[pt->getLen() - 1].RemoveNode(pt);
						pt->setNum(num);

						m_nodeList[0].AddNode(pt);
						delSurround(num, pt->getCol(), pt->getRow());
						return true;
					}



				}
			}
		}
	}
	return false;
}