using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.UI;
//comments
//Unity 2019.2.6f1 (64-bit)
// unity3d frezzes; no debug.logs
// i have to kill it
// if you want to have the other class plz pm me
// end comments
public class test : MonoBehaviour {
// Use this for initialization
private GameObject[] feld;
public GameObject[,] goGroupH = new GameObject[9, 9];
public GameObject[,] goGroupV = new GameObject[9, 9];
public GameObject[,] goGroupS = new GameObject[9, 9];
void Start ()
{
int i;
feld = GameObject.FindGameObjectsWithTag("input");
for (i = 0; i<feld.Length -1; i++ )
{
Debug.Log(".");
//feld[i].
//Debug.Log(i);
}
//if (feld.Length == 0)
//{
// feld = GameObject.FindGameObjectsWithTag("input");
//}
blah();
Debug.Log("goGroupH.Length: " + goGroupH.Length);
Debug.Log("goGroupV.Length: " + goGroupV.Length);
Debug.Log("goGroupS.Length: " + goGroupS.Length);
Debug.Log("Hors");
//for (i = 0; i < 9; i++)
//{
// for (int j = 0; j < 9; j++)
// {
// if (goGroupH[i, j].GetComponentInChildren<InputField>().text != "")
// Debug.Log("i:" + i + " j: " + j + ".. " + goGroupH[i, j].GetComponentInChildren<InputField>().text);
// }
// Debug.Log("");
//}
//Debug.Log("Verts");
//for (i = 0; i < 9; i++)
//{
// for (int j = 0; j < 9; j++)
// {
// if (goGroupV[i, j].GetComponentInChildren<InputField>().text != "")
// Debug.Log("i:" + i + " j: " + j + ".. " + goGroupV[i, j].GetComponentInChildren<InputField>().text);
// }
// Debug.Log("");
//}
}
// Update is called once per frame
// void Update ()
// {
//}
public void blah() // init? or so
{
bool bOk = true;
bool bOkTemp = false;
int i;
int j;
int iZahl;
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9; j++ )
{
Debug.Log("gen i: " + i);
iZahl = j + 1;
feld[i*9+j].GetComponentInChildren<InputField>().text = "";
}
}
i = 0;
Debug.Log("do");
do
{
i++;
Debug.Log("erzeug sudoku: " + i);
createSudoku();
bOkTemp = testGroups();
if (bOkTemp == false)
bOk = false;
if (bOk == true)
{
bOkTemp = testHor();
if (bOkTemp == false)
bOk = false;
}
if (bOk == true)
{
bOkTemp = testVert();
if (bOkTemp == false)
bOk = false;
}
if (bOk == false)
{
nullSudoku();
}
if (i>1000)
{
Debug.Log("nice try");
Debug.Break();
}
}
while (bOk == false);
}
public int solver()
{
int i=0;
int j=0;
int m=0;
bool done = false;
while (done == false)
{
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
for (m = 0; m < 10; m++)
{
}
}
}
}
return i + j + m;
}
void nullSudoku()
{
for (int i = 0; i < feld.Length; i++)
{
feld[i].GetComponentInChildren<InputField>().text = "";
}
}
void createSudoku()
{
int[,] zahlen = new int[9,9];
int i;
int pos;
for (i = 0; i < 16; i++ ) // draw ints // not stored?
{
pos = (int)UnityEngine.Random.Range(0f, 81f); // 80?
feld[pos].GetComponentInChildren<InputField>().text = "" + (int)UnityEngine.Random.Range(1f, 10f); // up to 10?
}
//Debug.Log(pos);
}
public bool testGroups()
{
Debug.Break();
int i, j,k,m = 0;
int iAnzahl = 0;
int[] zahlen = new int[9] {0,0,0,0,0,0,0,0,0};
for (i=0; i<9; i++)
{
for (j=0; j<9;j++)
{
try
{
if (goGroupS[i, j].GetComponentInChildren<InputField>().text != "")
{
zahlen[iAnzahl] = StringToInt(goGroupS[i, j].GetComponentInChildren<InputField>().text);
// test quadrat
for (m = 0; m < iAnzahl; m++)
{
if (zahlen[m] == zahlen[iAnzahl])
{
Debug.Log("Doppelte Zahl: " + zahlen[m] + " gefunden. @: " +i + " : " +j);
return false;
}
}
iAnzahl++;
}
}
catch(Exception e)
{
Debug.Log(i + " : " + j + " : " + e);
}
}
for (j = 0; j < 9;j++ )
{
zahlen[j] = 0;
}
iAnzahl = 0;
}
return true;
}
bool testVert()
{
Debug.Log("test verts");
Debug.Break();
int iTemp;
for (int i = 0; i < 9; i++)
{
List<int> zahlen = new List<int>();
for (int j = 0; j < 9; j++)
{
if(goGroupV[i, j].GetComponentInChildren<InputField>().text != "")
{
iTemp = StringToInt(goGroupV[i, j].GetComponentInChildren<InputField>().text);
Debug.Log("iTemp - Verts: " + iTemp);
if (zahlen.Contains(iTemp))
{
Debug.Log("test verts - return False; double: " + iTemp);
return false;
}
else
{
zahlen.Add(iTemp);
}
}
}
}
return true;
}
bool testHor()
{
Debug.Log("test Hors");
Debug.Break();
int iTemp;
for (int i = 0; i < 9; i++)
{
List<int> zahlen = new List<int>();
for (int j = 0; j < 9; j++)
{
if (goGroupH[i, j].GetComponentInChildren<InputField>().text != "")
{
iTemp = StringToInt(goGroupH[i, j].GetComponentInChildren<InputField>().text);
if (zahlen.Contains(iTemp))
{
Debug.Log("test Hors - return False; double: " + iTemp);
return false;
}
else
{
zahlen.Add(iTemp);
}
}
}
Debug.Log("in Hor Line " + i + " sind die Zahlen: ");
for (int k = 0; k < zahlen.Count; k++)
{
Debug.Log(zahlen[k] + " ");
}
}
return true;
}
int StringToInt(string sText)
{
int iZahl = 0;
switch (sText)
{
case "1":
iZahl = 1; break;
case "2":
iZahl = 2; break;
case "3":
iZahl = 3; break;
case "4":
iZahl = 4; break;
case "5":
iZahl = 5; break;
case "6":
iZahl = 6; break;
case "7":
iZahl = 7; break;
case "8":
iZahl = 8; break;
case "9":
iZahl = 9; break;
default:
Debug.Log("Fehler: Umwandlung von String in Int"); break;
}
return iZahl;
}
public void Ausgabe()
{
int i, j;
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9; j++)
{
if (goGroupV[i, j] != null)
{
Debug.Log("i: " +i + " j: "+ j + " "+goGroupV[i, j].name);
}
}
}
}
}
// i hope it will look right…