• 大小: 5.73MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-11
  • 语言: C#
  • 标签: 生成数独  求解数独  C#  

资源简介

在VS2012环境下采用C#编写,能够求解9*9和更高阶的数独,同时能够生成不同难度的数独(不是采用载入现有谜题的方式),参考两篇知网论文的算法,生成高难度数独时时间会消耗比较长,存在继续优化的空间。

资源截图

代码片段和文件信息

//调试开关
#undef DEBUG

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace Soduku
{

    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            for (int i = 0; i < MAX; i++)
            {
                proAns[i] = new Chart();
            }
#if DEBUG
            solveTest();
#endif

        }

        const int RANK = 9;//数独的阶数
        const int MAX = 100;//最多的可行解数量,超出则报错
        const int GENNUM = 20;//初始化时随机填数的数量
        enum Diffcult { EASY = 40 GENERAL = 50 HARD = 60 SPECIAL = 74 };//数独的难度,挖去多少数字
        //enum Diffcult { EASY = 60 GENERAL = 90 HARD = 120 SPECIAL = 160 };//数独的难度,挖去多少数字
        enum State { UNFINISH SUCCESS FAIL };//任意时刻数独的状态
        static int[] table = new int[RANK RANK];//数独表,空白元素为0
        static int[] answer = new int[RANK RANK];//完整的九宫格
        static int[] player = new int[RANK RANK];//玩家输入的答案
        string curBox = ““; //当前处理的textbox的名称
        static int solved = 0;//记录解的个数
        static int[] ans;

        //存储所有可能的解
        class Chart
        {
            public int[] ans;
            public Chart()
            {
                ans = new int[RANK RANK];
            }
        }
        static Chart[] proAns = new Chart[MAX];

#if DEBUG
        //测试数独,为法国决赛题,含24个数字,有唯一解
        int[] test = new int[NN]
        {
            {000750000}
            {030048020}
            {100000006}
            {040000008}
            {790000031}
            {200000070}
            {500000007}
            {080320040}
            {000069000}
        };

        //高阶数独求解测试
        int[] test = new int[N N]
        {
            {160009007110060001}
            {070900128320016060}
            {00200601160800400}
            {1086111421516413009070}
            {120001300111000800016}
            {0100070159011000120}
            {001328319514161261100}
            {001600001010000800}
            {1411903401280750612}
            {001200005600001500}
            {0010171513624129111400}
            {35761181021310140090}
            {1500701031209020010}
            {02501200141500403160}
            {001116010941462012700}
            {4381200013700014000}
        };

        void solveTest()
        {
            Soduku_Gen(test);
            sloved =-1;

            for(int i=0;i            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-03-21 10:25  Soduku_v5\
     文件         586  2016-03-16 11:34  Soduku_v5\1.txt
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\Interm\
     文件       40960  2015-09-09 01:01  Soduku_v5\Setup1\Setup1\Express\Interm\_IsIcoRes.Exe
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\SingleImage\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\SingleImage\DiskImages\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\SingleImage\DiskImages\DISK1\
     文件     2067408  2015-11-13 16:35  Soduku_v5\Setup1\Setup1\Express\SingleImage\DiskImages\DISK1\setup.exe
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\SingleImage\LogFiles\
     文件       12196  2015-11-13 16:35  Soduku_v5\Setup1\Setup1\Express\SingleImage\LogFiles\11-13-2015 04-35-45 下午.txt
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup1\Express\SingleImage\Reports\
     文件       14068  2015-11-13 16:35  Soduku_v5\Setup1\Setup1\Express\SingleImage\Reports\11-13-2015 04-35-51 下午.htm
     目录           0  2016-03-21 10:25  Soduku_v5\Setup1\Setup1\Express\SingleImage\TestTools\
     目录           0  2015-11-20 16:46  Soduku_v5\Setup1\Setup_soduku\
     目录           0  2015-11-20 17:35  Soduku_v5\Setup1\Setup_soduku\Express\
     目录           0  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\Interm\
     文件       40960  2015-09-09 01:01  Soduku_v5\Setup1\Setup_soduku\Express\Interm\_IsIcoRes.Exe
     目录           0  2015-11-20 17:35  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\
     目录           0  2015-11-20 17:35  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\DiskImages\
     目录           0  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\DiskImages\DISK1\
     文件     2071016  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\DiskImages\DISK1\setup.exe
     目录           0  2015-11-20 17:35  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\LogFiles\
     文件       12228  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\LogFiles\11-20-2015 05-35-45 下午.txt
     目录           0  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\Reports\
     文件       14068  2015-11-20 17:36  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\Reports\11-20-2015 05-36-08 下午.htm
     目录           0  2016-03-21 10:25  Soduku_v5\Setup1\Setup_soduku\Express\SingleImage\TestTools\
     文件      610098  2015-11-15 12:14  Soduku_v5\Setup1\Setup_soduku.isl
     文件        1825  2015-11-15 12:14  Soduku_v5\Setup1\Setup_soduku.isproj
............此处省略106个文件信息

评论

共有 条评论