コード例 #1
0
ファイル: SudokuService.cs プロジェクト: Zy-THOMAS/Sudoku
        /// <summary>
        /// 计算数独空白单元格值
        /// </summary>
        public ParamInfo calcSudoduData(ParamInfo paramInfo)
        {
            string msg      = "第【" + paramInfo.SudokuNum + "】组数独计算结果为:\r\n\r\n";
            string resValue = null;
            int    resSort  = 1;

            try
            {
                for (int m = 0; m < 3; m++)
                {
                    for (int n = 0; n < 3; n++)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                if (!sudokuData[m][n][i][j].NumFlag)
                                {
                                    int[] curPosition = new int[4] {
                                        m, n, i, j
                                    };
                                    NumCell cellVal = GetCellVal(curPosition);
                                    if (!cellVal.IsHasValue)
                                    {
                                        m = cellVal.CurCell[0];
                                        n = cellVal.CurCell[1];
                                        i = cellVal.CurCell[2];
                                        j = cellVal.CurCell[3];
                                        ClearAfter(cellVal.CurCell);
                                    }
                                    sudokuData[m][n][i][j].NumValue = cellVal.Value;
                                    NumCell lastEmptyCell = allCellValContainer[allCellValContainer.Count - 1];
                                    if (ComparePosition(curPosition, lastEmptyCell.CurCell) && cellValContainer.Count > 0)
                                    {
                                        bool checjRes = checkSudokuResult(sudokuData, paramInfo);
                                        if (!checjRes)
                                        {
                                            throw new Exception();
                                        }
                                        resValue = NumHandler.getResult(sudokuData);
                                        msg      = "[" + paramInfo.SudokuNum + ", " + resSort + "]\r\n";
                                        StringBuilder resValueBuilder = (StringBuilder)paramInfo.ResValue[paramInfo.SudokuNum];
                                        resValueBuilder.Append(msg).Append(resValue);
                                        paramInfo.ResValue[paramInfo.SudokuNum] = resValueBuilder;
                                        //NumHandler.SaveTempData(msg + resValue, paramInfo.SudokuNum.ToString());
                                        NumHandler.ShowProcess(paramInfo.DisplayControl, "已完成第【" + paramInfo.SudokuNum + "】组数独解[" + resSort + "]");
                                        NumCell lastCellVals = cellValContainer[cellValContainer.Count - 1];
                                        m = lastCellVals.CurCell[0];
                                        n = lastCellVals.CurCell[1];
                                        i = lastCellVals.CurCell[2];
                                        j = lastCellVals.CurCell[3];
                                        resSort++;
                                    }
                                }
                            }
                        }
                    }
                }
                resValue = NumHandler.getResult(sudokuData);
            }
            catch (Exception)
            {
                resValue = "[" + paramInfo.SudokuNum + ", 0]";
                //NumHandler.SaveTempData(resValue, paramInfo.SudokuNum.ToString());
                StringBuilder resValueBuilder = (StringBuilder)paramInfo.ResValue[paramInfo.SudokuNum];
                resValueBuilder.Append(resValue).AppendLine();
                paramInfo.ResValue[paramInfo.SudokuNum] = resValueBuilder;
            }
            return(paramInfo);
        }
コード例 #2
0
ファイル: SudokuService.cs プロジェクト: Zy-THOMAS/Sudoku
        private void showResult(int index, int resSort, string resValue, TextBox displayControl)
        {
            string msg = "[" + index + ", " + resSort + "]\r\n\r\n";

            NumHandler.ShowProcess(displayControl, msg + resValue);
        }