Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 5 KB
using System;
using System.Collections.Generic;
using System.Text;
namespace legfedés
{
class Program
{
public const int x = 8;
public const int y = 8;
public static int n;
public static bool[,,] d;
public static bool[,] now = new bool[x,y];
public static int[] st = new int[x * y / 4];
public static bool[,] érintők;
static void Main(string[] args)
{
Console.Write("initializing...");
initialize();
Console.Write("done\n");
int next = 0;
for (int lvl = 0; ; ) {
Console.ReadKey(true);
dump();
if (st[lvl] > n - 1)
{
st[lvl] = 0;
lvl--;
if (lvl == -1) break;
unrak(st[lvl]);
st[lvl]++;
continue;
}
if (!fedi(st[lvl])&&érintők[next,st[lvl]])
{
if (lvl == st.Length-1)
{
dump();
break;
}
rak(st[lvl]);
next = köviüres();
lvl++;
if (lvl > 0) st[lvl] = 0;
continue;
}
else {
st[lvl]++;
}
}
Console.ReadKey(true);
}
static bool fedi(int n)
{
for (int i = 0; i < x; i++)
{
for (int k = 0; k < y; k++) if (d[n, i, k] && now[i, k]) return true;
}
return false;
}
static int köviüres()
{
for (int i = 0; i < x; i++)
{
for (int k = 0; k < y; k++) if (!now[i, k]) {
if ((i * y + k) % x == x - 1) Console.WriteLine("volt");
return i * y + k;
}
}
Console.WriteLine("Error");
return 0;
}
static void rak(int n)
{
for (int i = 0; i < x; i++)
{
for (int k = 0; k < y; k++) if (d[n, i, k]) now[i,k] = true;
}
}
static void unrak(int n)
{
for (int i = 0; i < x; i++)
{
for (int k = 0; k < y; k++) if (d[n, i, k]) now[i,k] = false;
}
}
static void dump() {
for (int i = 0; i < x; i++) {
for(int k = 0 ;k < y;k++){
if (now[i, k]) Console.Write("X");
else Console.Write("0");
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine();
}
static void initialize()
{
n = ((x - 1) * (y - 2))*4 + ((x - 2) * (y - 1))*4;
d = new bool[n, x,y];
int ni = 0;
for (int i = 0; i < (x - 2); i++)
{
for (int k = 0; k < (y - 1); k++)
{
d[ni, i, k] = true;
d[ni, i + 1, k] = true;
d[ni, i + 2, k] = true;
d[ni, i, k + 1] = true;
ni++;
d[ni, i + 2, k] = true;
d[ni, i, k + 1] = true;
d[ni, i + 1, k + 1] = true;
d[ni, i + 2, k + 1] = true;
ni++;
d[ni, i, k] = true;
d[ni, i, k + 1] = true;
d[ni, i + 1, k + 1] = true;
d[ni, i + 2, k + 1] = true;
ni++;
d[ni, i, k] = true;
d[ni, i + 1, k] = true;
d[ni, i + 2, k] = true;
d[ni, i + 2, k + 1] = true;
ni++;
}
}
for (int i = 0; i < (x - 1); i++)
{
for (int k = 0; k < (y - 2); k++)
{
d[ni, i, k] = true;
d[ni, i + 1, k] = true;
d[ni, i, k + 1] = true;
d[ni, i, k + 2] = true;
ni++;
d[ni, i, k] = true;
d[ni, i + 1, k + 2] = true;
d[ni, i, k + 1] = true;
d[ni, i, k + 2] = true;
ni++;
d[ni, i + 1, k] = true;
d[ni, i + 1, k + 1] = true;
d[ni, i + 1, k + 2] = true;
d[ni, i, k + 2] = true;
ni++;
d[ni, i + 1, k] = true;
d[ni, i + 1, k + 1] = true;
d[ni, i + 1, k + 2] = true;
d[ni, i, k] = true;
ni++;
}
}
érintők = new bool[y*x,ni];
int num = x*y;
for(int i = 0; i < num;i++){
for(int j = 0;j < ni;j++){
if(d[j,i/x,i%x])érintők[i,j] = true;
}
}
}
}
}