}
}
}
// Перестановка регионов (блок из трех строк/столбцов)
public void MixVerticalRegions ()
{
Random rand = new Random ();
short Region1, Region2;
//Переставляем две строки в первой тройке
Region1 = (short)(rand.Next (7654) % 3);
Region2 = (short)(rand.Next (45545) % 3);
ExchangeValuesOfVerticalRegions (Region1, Region2);
}
public void ExchangeValuesOfVerticalRegions (short Region1, short Region2)
{
if (Region1!= Region2)
{
short lineTemp1;
short lineTemp2;
short lineTemp3;
for (short i = 0; i <9; i++)
{
lineTemp1 = field [i, Region1 * 3].Value;
lineTemp2 = field [i, Region1 * 3 + 1].Value;
lineTemp3 = field [i, Region1 * 3 + 2].Value;
field [i, Region1 * 3].Value = field [i, Region2 * 3].Value;
field [i, Region1 * 3 + 1].Value = field [i, Region2 * 3 + 1].Value;
field [i, Region1 * 3 + 2].Value = field [i, Region2 * 3 + 2].Value;
field [i, Region1 * 3].Value = lineTemp1;
field [i, Region1 * 3 + 1].Value = lineTemp2;
field [i, Region1 * 3 + 2].Value = lineTemp3;
}
}
}
public void MixHorizontalRegions ()
{
Random rand = new Random ();
short Region1, Region2;
//Переставляем две строки в первой тройке
Region1 = (short)(rand.Next (7654) % 3);
Region2 = (short)(rand.Next (45545) % 3);
ExchangeValuesOfHorizontalRegions (Region1, Region2);
}
public void ExchangeValuesOfHorizontalRegions (short Region1, short Region2)
{
if (Region1!= Region2)
{
short lineTemp1;
short lineTemp2;
short lineTemp3;
for (short i = 0; i <9; i++)
{
lineTemp1 = field [Region1 * 3, i].Value;
lineTemp2 = field [Region1 * 3 +1, i].Value;
lineTemp3 = field [Region1 * 3 +2, i].Value;
field [Region1 * 3, i].Value = field [i, Region2 * 3].Value;
field [Region1 * 3 +1, i].Value = field [i, Region2 * 3 + 1].Value;
field [Region1 * 3 +2, i].Value = field [i, Region2 * 3 + 2].Value;
field [Region1 * 3, i].Value = lineTemp1;
field [Region1 * 3 +1, i].Value = lineTemp2;
field [Region1 * 3 +2, i].Value = lineTemp3;
}
}
}
// Освобождение клеток на поле
public void DeleteNumbersFromField ()
{
Random rand = new Random ();
for (short k = 0; k <9; k++)
{
short [] randString = new short [9];
numbers = new short [9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
for (short i = 0; i <9; i++)
{
short temp = (short)(rand.Next (45689 * (i +1) – 6) % (9 – i));
randString [i] = numbers [temp];
for (short j = temp; j <9 – i – 1; j++)
{
numbers [j] = numbers [j +1];
}
}
short tempRand = (short)(rand.Next (4, 7));
for (short t = 0; t { field [k, randString[t]].Value = 0; } for (short t = tempRand; t <9; t++) { field [k, randString[t]].Standard = true; } } } // Проверка условий победы public bool Win () { bool flag = true; short full = 0; SearchRepeats (); // Подсчет заполненных клеток for (short i = 0; i <9; i++) { for (short j = 0; j <9; j++) { if (field [i, j].Value!= 0) { full++; } } } // Если заполненны все клетки if (full == 81) { for (short i = 0; i <9; i++) { for (short j = 0; j <9; j++) { // Если есть повтор if (field [i, j].Repeat) { flag = false; break; } } if (!flag) { break; } } } // Если все заполненно и нет ошибок – заблокировать поле if (flag && full == 81) { for (short i = 0; i <9; i++) { for (short j = 0; j <9; j++) { field [i, j].Standard = true; } } } return (flag && full == 81); } // Проверка повторений во всех строках/столбцах/квадратах public void SearchRepeats () { // Нет повторений for (short i = 0; i <9; i++) { for (short j = 0; j <9; j++) { field [i, j].Repeat = false; } } // Поиск повторений в строках for (short i = 0; i <9; i++) { for (short j = 0; j <9; j++) { for (short k = 0; k <9; k++) { if (field [i, j].Value == field [i, k].Value && j!= k) { field [i, j].Repeat = true; } } } } // Поиск повторений в столбцах for (short i = 0; i <9; i++)