Exemple #1
0
CTipDlg::CTipDlg(CWnd* pParent, int table[9][9])
	: CDialog(CTipDlg::IDD, pParent)
	, m_index(0)
	, m_bStep(false)
{
	for(int i = 0;i < 9;i ++)
	{
		for(int j = 0;j < 9;j ++)
		{
			m_node[i][j].setLoc(i, j);
		}
	}

	for(int i = 0;i < 9;i ++)
	{
		for(int j= 0;j < 9;j ++)
		{
			if(table[i][j] == 0)
			{
				m_nodeList[8].AddNode(&m_node[i][j]);
			}
			else
			{
				m_node[i][j].setNum(table[i][j]);
				m_nodeList[0].AddNode(&m_node[i][j]);
			}
		}
	}


	for(CNode* pt = m_nodeList[0].GetHead();pt != NULL;pt = pt->next)
	{
		delSurround(pt->getData(), pt->getCol(), pt->getRow());
	}

	while (ConfirmNode());
}
Exemple #2
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;
}