当前位置:网站首页>"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 ).
边栏推荐
- 数据中台:中台架构及概述
- "Unusual proxy initial value setting is not supported", causes and Solutions
- Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
- tcpdump抓包实现过程
- 开源之夏中选名单已公示,基础软件领域成为今年的热门申请
- ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
- Using skills of xargs -- the way to build a dream
- Data middle office: a collection of middle office construction architectures of large domestic factories
- Floating error waiting for changelog lock
- 一文讲透,商业智能BI未来发展趋势如何
猜你喜欢

数据中台:数据采集和抽取的技术栈详解

基于QingCloud的 “房地一体” 云解决方案

【牛客】把字符串转换成整数

Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)

“不平凡的代理初始值设定不受支持”,出现的原因及解决方法

Distributed | how to make "secret calls" with dble

MySQL | 存储《康师傅MySQL从入门到高级》笔记

leetcode——错误的集合

Spark - LeftOuterJoin 结果条数与左表条数不一致

OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集
随机推荐
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
Data midrange: analysis of full stack technical architecture of data midrange, with industry solutions
数据中台:民生银行的数据中台实践方案
[quantitative investment] discrete Fourier transform to calculate array period
4274. 后缀表达式
Sword finger offer 55 - I. depth DFS method of binary tree
Why can ping fail while traceroute can
小程序wx.show
第七章 操作位和位串(三)
Liunx Mysql安装
陆奇:我现在最看好这四大技术趋势
Liunx change the port number of vsftpd
GradScaler MaxClipGradScaler
数据中台:数据治理概述
基于QingCloud的地理信息企业研发云解决方案
MyCAT读写分离与MySQL主从同步
教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
Become an IEEE student member
“论解不了数独所以选择做个数独游戏这件事”
Determination of monocular and binocular 3D coordinates