当前位置:网站首页>"I can't understand Sudoku, so I choose to play Sudoku."
"I can't understand Sudoku, so I choose to play Sudoku."
2022-06-24 08:57:00 【Foulove】
one day , Xiaoming was browsing the Li Kou website with relish , I was pleasantly surprised to find a topic that seemed very easy to start ( The root of all evil T T).

So Xiaoming wrote the problem-solving ideas with interest .
Opened as usual Unity Ready to start doing .
.( draw UI)
..( Write the script , Use constantly produces 1~9 The method of random numbers , Fill in the blanks one by one , To solve Sudoku )
...( Hanging components )
Yes .
The test link :
1 Empty tests ( That's all right. )
2 Blank random numbers ( That's all right. )
81 Empty ( No response )

Maybe Untiy What front-end programmers fear most is not full screen error reporting , But the code is OK , No problem with the engine setup , But I can't run .( Core algorithm logic error T T)
So , At a time when I was thinking hard about how to solve Sudoku , A pat on the thigh , Why can't I play Sudoku , It's not easy (— —).
So he came . Since we can't solve Sudoku, let's make a Sudoku game and solve it by ourselves ( Confidence in fans ).
Solve Sudoku successfully :

Fail to solve Sudoku :

Draft function :( Because I found that we usually want to finish Sudoku , Always used to use a draft sheet to check , Most of the software on the market is not available , I added this function , It is also an innovation )

Partial source code :
Sudoke class :
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class Sudoke : MonoBehaviour
{
public GameObject[] AllGrid;// All squares
public GameObject m_Panel;
public GameObject m_RawImage;
public GameObject m_Paper;
public GameObject m_Paper_1;
public GameObject tici;// Questions
public Button m_SolveBtn;// Sudoku button
public Button Paper;// Paper button
[Header(" The value of the lattice ")]
public List<string> GridValue = new List<string>();
public bool canWrite;
[SerializeField]
private char[] SudokeAllNum;// All the numbers
private GameObject m_Grid;
private string m_GridValue;// The value of the lattice
private string randomNum;
public void Awake()
{
tici.GetComponent<Text>().text = " The first 1 topic ";
SetGridValue();
m_SolveBtn.onClick.AddListener(GetGridValue);
Paper.onClick.AddListener(UsePaper);
Exam();
m_RawImage.gameObject.SetActive(false);
m_Paper_1.gameObject.SetActive(true);
AddLimit();
}
public void Update()
{
#region Row store
RowStorage(NumsManager.instance.Row_0, 0, 8);
RowStorage(NumsManager.instance.Row_1, 9, 17);
RowStorage(NumsManager.instance.Row_2, 18, 26);
RowStorage(NumsManager.instance.Row_3, 27, 35);
RowStorage(NumsManager.instance.Row_4, 36, 44);
RowStorage(NumsManager.instance.Row_5, 45, 53);
RowStorage(NumsManager.instance.Row_6, 54, 62);
RowStorage(NumsManager.instance.Row_7, 63, 71);
RowStorage(NumsManager.instance.Row_8, 72, 80);
#endregion
#region Column store
ColStorage(NumsManager.instance.Col_0, 0);
ColStorage(NumsManager.instance.Col_1, 1);
ColStorage(NumsManager.instance.Col_2, 2);
ColStorage(NumsManager.instance.Col_3, 3);
ColStorage(NumsManager.instance.Col_4, 4);
ColStorage(NumsManager.instance.Col_5, 5);
ColStorage(NumsManager.instance.Col_6, 6);
ColStorage(NumsManager.instance.Col_7, 7);
ColStorage(NumsManager.instance.Col_8, 8);
#endregion
#region Palace storage
BoxStorage(NumsManager.instance.Box_0, 0, 1, 2);
BoxStorage(NumsManager.instance.Box_1, 3, 4, 5);
BoxStorage(NumsManager.instance.Box_2, 6, 7, 8);
BoxStorage(NumsManager.instance.Box_3, 27, 28, 29);
BoxStorage(NumsManager.instance.Box_4, 30, 31, 32);
BoxStorage(NumsManager.instance.Box_5, 33, 34, 35);
BoxStorage(NumsManager.instance.Box_6, 54, 55, 56);
BoxStorage(NumsManager.instance.Box_7, 57, 58, 59);
BoxStorage(NumsManager.instance.Box_8, 60, 61, 62);
#endregion
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
/// <summary>
/// Lattice dynamic assignment
/// </summary>
private void SetGridValue()
{
for (int i = 0; i < AllGrid.Length; i++)
{
m_Grid = m_Panel.transform.GetChild(i).gameObject;
AllGrid.SetValue(m_Grid, i);
}
}
/// <summary>
/// Get the value of the grid
/// </summary>x
private void GetGridValue()
{
GridValue.Clear();// Refresh the values in the list
for (int i = 0; i < AllGrid.Length; i++)
{
m_Grid = m_Panel.transform.GetChild(i).gameObject;
m_GridValue = m_Grid.GetComponent<InputField>().text;
if (m_GridValue!=null)
{
GridValue.Add(m_GridValue);// The list stores the values entered in the grid
}
}
}
/// <summary>
/// Row store
/// </summary>
/// <param name="list"></param>
/// <param name="min"></param>
/// <param name="max"></param>
public void RowStorage(List<string> list, int min, int max)
{
list.Clear();
for (int i = min; i <= max; i++)
{
list.Add(AllGrid[i].GetComponent<InputField>().text);
}
}
/// <summary>
/// Column store
/// </summary>
/// <param name="list"></param>
/// <param name="index"></param>
public void ColStorage(List<string> list,int index)
{
list.Clear();
for (int i = 0; i < 9; i++)
{
list.Add(AllGrid[index].GetComponent<InputField>().text);
index += 9;
}
}
/// <summary>
/// Palace storage
/// </summary>
/// <param name="list"></param>
/// <param name="startNum"></param>
/// <param name="midNum"></param>
/// <param name="lastNum"></param>
public void BoxStorage(List<string> list,int startNum,int midNum,int lastNum)
{
list.Clear();
for (int i = 0; i < 3; i++)
{
list.Add(AllGrid[startNum].GetComponent<InputField>().text);
list.Add(AllGrid[midNum].GetComponent<InputField>().text);
list.Add(AllGrid[lastNum].GetComponent<InputField>().text);
startNum += 9;
midNum += 9;
lastNum += 9;
}
}
/// <summary>
/// Add questions
/// </summary>
/// <param name="orderNum"></param>
/// <param name="examNum"></param>
public void AddExam(int orderNum,string examNum)
{
for (int i = 0; i < AllGrid.Length; i++)
{
AllGrid[orderNum].GetComponent<InputField>().text = examNum;
AllGrid[orderNum].GetComponent<InputField>().interactable = false;
}
}
/// <summary>
/// Write the test questions
/// </summary>
public void Exam()
{
// The first question is
AddExam(3, "9");
AddExam(4, "5");
AddExam(5, "7");
AddExam(6, "3");
AddExam(7, "8");
AddExam(8, "2");
AddExam(15, "5");
AddExam(16, "4");
AddExam(17, "1");
AddExam(12, "6");
AddExam(13, "2");
AddExam(14, "3");
AddExam(21, "1");
AddExam(22, "8");
AddExam(23, "4");
AddExam(24, "7");
AddExam(29, "4");
AddExam(30, "8");
AddExam(32, "5");
AddExam(38, "5");
AddExam(40, "6");
AddExam(41, "2");
AddExam(48, "4");
AddExam(50, "1");
AddExam(51, "6");
AddExam(54, "7");
AddExam(57, "3");
AddExam(60, "2");
AddExam(61, "6");
AddExam(63, "4");
AddExam(64, "2");
AddExam(66, "5");
AddExam(69, "9");
AddExam(71, "3");
AddExam(72, "6");
AddExam(73, "5");
AddExam(78, "4");
AddExam(79, "1");
}
/// <summary>
/// Realize the draft making operation
/// </summary>
public void UsePaper()
{
if (canWrite == true)
{
m_RawImage.gameObject.SetActive(false);
m_Paper.gameObject.SetActive(false);
m_Paper_1.gameObject.SetActive(true);
canWrite = false;
}
else
{
m_RawImage.gameObject.SetActive(true);
m_Paper_1.gameObject.SetActive(false);
m_Paper.gameObject.SetActive(true);
canWrite = true;
}
}
/// <summary>
/// Set that each input box can only input one character
/// </summary>
public void AddLimit()
{
for (int i = 0; i < AllGrid.Length; i++)
{
AllGrid[i].GetComponent<InputField>().characterLimit = 1;
}
}
}
NumsManager class :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NumsManager : MonoBehaviour
{
public static NumsManager instance;
public List<string> Col_0, Col_1, Col_2, Col_3, Col_4, Col_5, Col_6
, Col_7 , Col_8 = new List<string>();// Nine columns
public List<string> Row_0, Row_1, Row_2, Row_3, Row_4, Row_5, Row_6
, Row_7, Row_8 = new List<string>();// Nine elements
public List<string> Box_0, Box_1, Box_2, Box_3, Box_4, Box_5, Box_6
, Box_7, Box_8 = new List<string>();// Nine palaces
public List<string> OriginalAsw = new List<string>() {"1","2","3","4","5","6","7","8","9"};
public int completeNum = 0;
public GameObject OK;// success
public GameObject NoOK;// Failure
public Button completeBtn;// Finish button
NumsManager()
{
instance = this;
}
void Awake()
{
completeBtn.onClick.AddListener(TestOkorNot);
}
public void Update()
{
// Click anywhere to continue the game
if (Input.GetMouseButtonDown(0))
{
NoOK.gameObject.SetActive(false);
}
}
/// <summary>
/// Detection system
/// </summary>
public void TestOkorNot()
{
completeNum = 0;
TestAsw(Col_0);
TestAsw(Col_1);
TestAsw(Col_2);
TestAsw(Col_3);
TestAsw(Col_4);
TestAsw(Col_5);
TestAsw(Col_6);
TestAsw(Col_7);
TestAsw(Col_8);
TestAsw(Row_0);
TestAsw(Row_1);
TestAsw(Row_2);
TestAsw(Row_3);
TestAsw(Row_4);
TestAsw(Row_5);
TestAsw(Row_6);
TestAsw(Row_7);
TestAsw(Row_8);
TestAsw(Box_0);
TestAsw(Box_1);
TestAsw(Box_2);
TestAsw(Box_3);
TestAsw(Box_4);
TestAsw(Box_5);
TestAsw(Box_6);
TestAsw(Box_7);
TestAsw(Box_8);
if (completeNum == 243)//3*9*9 This is the completion condition
{
OK.gameObject.SetActive(true);
}
else
{
NoOK.gameObject.SetActive(true);
}
}
/// <summary>
/// Detection principle
/// </summary>
/// <param name="nowAswList"></param>
public void TestAsw(List<string> nowAswList)
{
for (int i = 0; i < OriginalAsw.Count; i++)
{
for (int s = 0; s < nowAswList.Count; s++)
{
nowAswList.Sort();
if (nowAswList[s]==OriginalAsw[i])
{
completeNum += 1;
}
}
}
}
}
At present, the blogger has successfully graduated , So there is more time to share the technology blog . Looking back on the four years of College , There are still many feelings , But if you stay in one place forever , I can't enjoy the scenery behind , So just stride forward (2022 A message from a graduate of ).
边栏推荐
- China chip Unicorn Corporation
- Determination of monocular and binocular 3D coordinates
- The form image uploaded in chorme cannot view the binary image information of the request body
- [MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
- MySQL | store notes of Master Kong MySQL from introduction to advanced
- GradScaler MaxClipGradScaler
- 【NOI模拟赛】寄(树形DP)
- Database to query the quantity of books lent in this month. If it is higher than 10, it will display "more than 10 books lent in this month". Otherwise, it will display "less than 10 books lent in thi
- 双指针模拟
- 關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
猜你喜欢

The form image uploaded in chorme cannot view the binary image information of the request body

input的聚焦后的边框问题

Data midrange: detailed explanation of the technical stack of data acquisition and extraction

【NOI模拟赛】给国与时光鸡(构造)

What is graph neural network? Figure what is the use of neural networks?

Distributed | how to make "secret calls" with dble

一文讲透,商业智能BI未来发展趋势如何

Data middle office: middle office architecture and overview

uniapp 开发多端项目如何配置环境变量以及区分环境打包

Xiaohei ai4code code baseline nibble 1
随机推荐
關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
何时使用RDD和DataFrame/DataSet
À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL
It is enough to read this article about ETL. Three minutes will let you understand what ETL is
“不平凡的代理初始值设定不受支持”,出现的原因及解决方法
数据中台:数据治理概述
偶然间得到的framework工具类 自用
【使用 PicGo+腾讯云对象存储COS 作为图床】
Data middle office: middle office practice and summary
随笔-反思
[quantitative investment] discrete Fourier transform to calculate array period
Win11 blank when using VIM to view content in cmder
第七章 操作位和位串(三)
小程序wx.show
2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
QT source code analysis -- QObject (2)
1704. 判断字符串的两半是否相似
"Unusual proxy initial value setting is not supported", causes and Solutions
【NOI模拟赛】摆(线性代数,杜教筛)
threejs辉光通道01(UnrealBloomPass && layers)