読者です 読者をやめる 読者になる 読者になる

数独を解く(1日目)

c#

まずはGUIまわりから(GUI.cs)
メインフォーム(Form1)のLoadのイベントハンドラーを作成する必要あり。

using System;
using System.Drawing;
using System.Windows.Forms;

namespace 数独ソルバー
{
    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, EventArgs e)
        {
            this.SuspendLayout();
            //Form1の設定
            this.Height = 382; this.Width = 530;
            this.MinimizeBox = false; this.MaximizeBox = false;
            this.Text = "数独ソルバー";
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            //
            //IDbuttonの設定
            int[] gyo = { 10, 45, 80, 120, 155, 190, 230, 265, 300 };

            for (int i = 0; i < 81; i++)
            {
                IDbutton[i] = new Button();
                IDbutton[i].Text = "";
                IDbutton[i].Size = new Size(35, 35);
                IDbutton[i].Font = new Font("Arial", 14);
                IDbutton[i].Location = new Point(gyo[i % 9], gyo[i / 9]);
                IDbutton[i].Click += IDbutton_Click;
            }
            this.Controls.AddRange(IDbutton);
            //
            //新規、検証、実行ボタンの設定
            newGame.Text = "新規入力"; kensyo.Text = "検証"; zikko.Text = "実行";
            newGame.Size = new Size(150, 40);
            kensyo.Size = new Size(150, 40); 
            zikko.Size = new Size(150, 40);
            newGame.Location = new Point(350, 190);
            kensyo.Location = new Point(350, 240); 
            zikko.Location = new Point(350, 290);
            zikko.Enabled = false;
            newGame.Click+=newGame_Click;
            kensyo.Click += kensyo_Click;
            zikko.Click += zikko_Click;
            this.Controls.AddRange(new Control[] { newGame, kensyo, zikko });
            //
            this.ResumeLayout();
        }
    }
}

メインプログラム(Form1.cs)

using System;
using System.Windows.Forms;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;

namespace 数独をとく
{
    public partial class Form1 : Form
    {
        Button[] IDbutton = new Button[81];
        Button kensyo = new Button();
        Button zikko = new Button();
        Button newGame = new Button();

        int[] kazu = new int[81];
        readonly int[] next_position = { 0, 1, 2, 9, 10, 11, 18, 19, 20 };
        readonly int[] start_position = { 0, 3, 6, 27, 30, 33, 54, 57, 60 };

        string[][] each_data = new string[9][];
        int[] each_data_para = new int[9];
        int[] sort_index = new int[9];

        public Form1()
        {
            InitializeComponent();
        }

        private void kensyo_Click(object sender, EventArgs e)
        {
            //後で記述
        }
       
        private bool kensyo_do()
        {
            //後で記述
        }

        private void zikko_Click(object sender, EventArgs e)
        {
            //後で記述
        }

        private bool hantei(int para)
        {
            //後で記述
        }
        
        private void newGame_Click(object sender, EventArgs e)
        {
            //後で記述
        }
        
        private void IDbutton_Click(object sender, EventArgs e)
        {
            //後で記述
        }
    }
}