示例#1
0
        static int maxlev = 0;                  //	Maximal queue level

        sresult SuSolve(solvetype type)
        {
            //******************************************************
            //	Controlling the game solving
            //******************************************************
            //	Flg:	-1	- MAKERESULT	Solve game
            //			=0	- TESTRESULTS	Count solutions
            //	Returns:
            //		-1	- Solution found
            //		0	- No solution
            //		1	- 1 solution
            //		>1	- More than one solution exist
            int nbresults = 0;

            gameTable.ClearSelects();
            tableQueue = new TableQueue();
            resultList = new TableQueue();
            trynb      = 0;
            maxlev     = 0;
            //	Solving table
            while (true)
            {
                Recount :                int ret = SolveAll();
                //	ret	<0 - no solution
                //		=0 - no new fixed value
                //		>0 - new fixed value found
                BackTry :                if (ret >= 0)
                {
                    //	Ellenõrizni hogy vége-e, vagy tovább kell számolni
                    int eret = gameTable.EndTest();
                    if (eret < 0)
                    {
                        //	>=0 - there are fixable cells
                        //	=-1 - all cells are fixed
                        if (type == (int)solvetype.TESTRESULTS)
                        {
                            if (nbresults == 0)
                            {
                                int qSize = tableQueue.gameTableList.Count;
                                if (qSize == 0)
                                {
                                    nbresults++;
                                    break;
                                }
                            }
#if DEBUG
#endif
                            nbresults++;
                            resultList.Push(gameTable);
                            ret = -1;
                            goto BackTry;
                        }
                        else
                        {
                            //	task: found solution
                            //	step out from loop and return by OK
                            break;
                        }
                    }
                    if (ret > 0)                        //	Talált megoldást, újra számolni
                    {
                        goto Recount;                   //	continue;
                    }
                }
                else
                {
                    //	<0 - here no solution
BackStep:           //	Hiba, visszalépni majd következõ próbát keresni
                    if (tableQueue.Size > 0)
                    {
                        gameTable = tableQueue.Pop();
                        --level;
                        textActLevel.Text = level.ToString();
                        textActLevel.Refresh();
                    }
                    else
                    {
                        //	Itt a vége, nincs megoldás
                        switch (nbresults)
                        {
                        case 0:
                            return(sresult.SOLVE_NORESULT);

                        default:
                            if (nbresults < (int)sresult.SOLVE_MORERESULT)
                            {
                                if (tableQueue.Size > 0)
                                {
                                    goto BackStep;
                                }
                            }
                            return((sresult)(Math.Min(nbresults, (int)sresult.SOLVE_MORERESULT)));
                        }
                    }
                }

                //	Következõ próbálkozás
                if (gameTable.x >= 0)
                {
                    if (gameTable.cell(gameTable.x, gameTable.y).cannum == 0)
                    {
                        ret = -1;
                        goto BackTry;
                    }
                }
                else
                {
                    SearchNext();
                }

                //	Beállítani a próbát
                if (SetTryNum() <= 0)
                {
                    //	Lehetetlen
                    return(sresult.SOLVE_IMPOSSIBLE);
                }

                ++level;
                textActLevel.Text = level.ToString();
                textActLevel.Refresh();
                maxlev            = Math.Max(maxlev, level);
                textMaxLevel.Text = maxlev.ToString();
                textMaxLevel.Refresh();
                trynb++;
                textTryNb.Text = trynb.ToString();
                textTryNb.Refresh();
                if (trynb > 10000)
                {
                    return(sresult.SOLVE_FEWDATA);
                }
                tableQueue.Push(gameTable);
                gameTable.y     =
                    gameTable.x = -1;
                gameTable.tnb   = 0;
                gameTable.level = level;
            }
            return(sresult.SOLVE_OK);                   //	"Jó megoldás !"
        }
示例#2
0
        private int AnalyzeResult(solvetype type)
        {
            GameTable gameTableSave = gameTable.DeepClone(gameTable);
            sresult   sret          = SuSolve(type);
            //		-1	- no solution
            //		 0	- solved
            //		>0	- other solve error
            string msgid;
            string msgtype;

            switch (sret)
            {
            case sresult.SOLVE_FEWDATA:
                msgid   = chlang.GetLocalizedString("MB_msg_errfill");
                msgtype = chlang.GetLocalizedString("MB_caption_err");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case sresult.SOLVE_IMPOSSIBLE:                      //		"Lehetetlen megoldás"
                msgid   = chlang.GetLocalizedString("MB_msg_NOresult");
                msgtype = chlang.GetLocalizedString("MB_caption_err");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case sresult.SOLVE_CANCELLED:
                msgid   = chlang.GetLocalizedString("MB_msg_stopped");
                msgtype = chlang.GetLocalizedString("MB_caption_err");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case sresult.SOLVE_OK:                                      //	-1	"Jó megoldás !"
                //	Returns:
                if (type == solvetype.MAKERESULT)
                {
                    pictureTable_Resize(null, null);
                    msgid   = chlang.GetLocalizedString("MB_msg_result");
                    msgtype = chlang.GetLocalizedString("MB_caption_result");
                }
                else
                {
                    msgid   = chlang.GetLocalizedString("MB_msg_solvable");
                    msgtype = chlang.GetLocalizedString("MB_caption_result");
                }
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case sresult.SOLVE_NORESULT:                        //	 0	"Hiba, nincs megoldás"
                msgid   = chlang.GetLocalizedString("MB_msg_NOresult");
                msgtype = chlang.GetLocalizedString("MB_caption_err");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case sresult.SOLVE_ONERESULT:                       //	1	"1 megoldás"
                msgid   = chlang.GetLocalizedString("MB_msg_1result");
                msgtype = chlang.GetLocalizedString("MB_caption_result");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case sresult.SOLVE_MORERESULT:                      //	>15	"Több megoldás"
                msgid   = string.Format(chlang.GetLocalizedString("MB_msg_MANYresult"), (int)sret);
                msgtype = chlang.GetLocalizedString("MB_caption_result");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            default:                                                                    //	<15	"Több megoldás"
                msgid   = string.Format(chlang.GetLocalizedString("MB_msg_NBresult"), (int)sret);
                msgtype = chlang.GetLocalizedString("MB_caption_result");
                MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;
            }
            gameTable     = gameTableSave;
            gameTableSave = null;
            gameTable.ClearSelects();
            pictureTable_Resize(null, null);
            return((int)sret);
        }