Пример #1
0
        public SuDokuForm()
        {
            InitializeComponent();
#if DEBUG
            Assembly assembly = Assembly.GetExecutingAssembly();
            foreach (string s in assembly.GetManifestResourceNames())
            {
                string xx = s;
            }
#endif
            chlang = new LanguageChange();
            //chlang.ChangeLanguage("hu-HU");
            //chlang.ChangeLanguage("en");
            chlang.ChangeLanguage(null);                        //	set default language
            chlang.ApplyLanguageToForm(this);

            //	Init game comboBox
            for (int ii = 0; ii < Constants.gameDefTb.Length; ii++)
            {
                comboGameType.Items.Add(Constants.gameDefTb[ii].gTypeName);
            }
            pictureTable.BackColor      = Color.DimGray;
            tableQueue                  = new TableQueue();
            comboGameType.SelectedIndex = 0;
            gameTimer           = new System.Timers.Timer(1000);
            gameTimer.Elapsed  += OnTimedEvent;
            gameTimer.AutoReset = true;
            gameTimer.Enabled   = true;
        }
Пример #2
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 !"
        }