Files
c-sharp/Sakk/Program.cs

82 lines
2.7 KiB
C#
Raw Normal View History

2022-04-05 15:08:51 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sakk {
internal class Program {
private static int[,] tabla = new int[8, 8];
public static bool oszlopEllenorzes(int y_index) {
for (int x = 0; x < tabla.GetLength(0); x++)
if (tabla[x, y_index] != 0) //megvizsgaljuk, hogy az adott sorban van e mar babu
return false; //ha talaltunk babut return false
return true; //ha nem adott vissza eddig semmit akkor adjon vissza igazat
}
public static bool sorEllenorzes(int x_index) {
for (int y = 0; y < tabla.GetLength(0); y++)
if (tabla[x_index, y] != 0) //megvizsgaljuk az adott sort az oszlopban
return false; //ha talalt babut akkor return false
return true; //ha nem talalt sehol se babut akkor return true
}
2022-04-09 16:38:03 +02:00
public static void kiir() {
2022-04-05 15:08:51 +02:00
for (int i = 0; i < tabla.GetLength(0); i++) {
for (int j = 0; j < tabla.GetLength(1); j++) {
2022-04-09 16:38:03 +02:00
Console.Write(tabla[i,j] + " ");
}
Console.WriteLine();
}
}
static void Main(string[] args) {
//problema ha el van tolva a sor vagy az oszlop nem rak le 8 babut
//csak egy fajta variaciot tud megcsinalni
Random random = new Random();
List<int[,]> tablak = new List<int[,]>();
//int lehetosegek = 0;
int babuk = 0;
int akt_sor = 0;
bool nem_jo_ketszer = false;
int elozo_poz = 0, elozo_sor = 0;
2022-04-05 15:08:51 +02:00
2022-04-09 16:38:03 +02:00
while(babuk < 9) {
int pozicio = random.Next(0, 7);
Console.WriteLine("pozicio: " + pozicio);
Console.WriteLine("akt sor:" + akt_sor);
if(sorEllenorzes(akt_sor) && oszlopEllenorzes(pozicio)) {
tabla[akt_sor, pozicio] = 1;
elozo_poz = pozicio; //elozo babu elmentese
elozo_sor = akt_sor;
babuk++;
akt_sor++;
2022-04-05 15:08:51 +02:00
}
2022-04-09 16:38:03 +02:00
if(elozo_sor == akt_sor) {
nem_jo_ketszer = true;
if (nem_jo_ketszer) {
tabla = new int[8, 8];
babuk = 0,
}
}
//atnezni van e mar ez a tabla eltarolva
if(babuk == 8) {
tablak.Add(tabla);
}
kiir();
2022-04-05 15:08:51 +02:00
}
2022-04-09 16:38:03 +02:00
2022-04-05 15:08:51 +02:00
Console.ReadKey();
}
}
}