-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
125 lines (108 loc) · 2.96 KB
/
Program.cs
File metadata and controls
125 lines (108 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
namespace Console_8Queen
{
class Program
{
static int sol;
static char[,] tableau = new char[8, 8];
static void ponerReina(int i, int j)
{
tableau[i, j] = 'X';
}
static void quitarReina(int i, int j)
{
tableau[i, j] = '.';
}
static bool posicionSegura(int m, int n)
{
if (tableau[m, n] != 'X')
{
for (int a = 0; a < 8; a++)
{
for (int b = 0; b < 8; b++)
{
if ((a + b) == (m + n))
{
if (tableau[a, b] == 'X')
{
return false;
}
}
if ((a - b) == (m - n))
{
if (tableau[a, b] == 'X')
{
return false;
}
}
if (a == m)
{
if (tableau[a, b] == 'X')
{
return false;
}
}
if (b == n)
{
if (tableau[a, b] == 'X')
{
return false;
}
}
}
}
}
else
return false;
return true;
}
private static void inicializar()
{
sol = 1;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
tableau[i, j] = '.';
}
}
}
static void afficher()
{
Console.WriteLine("Solucion " + sol);
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
Console.Write("|_" + tableau[i, j] + "_");
}
Console.Write("|");
Console.WriteLine();
}
sol++;
}
private static void tester(int i)
{
for (int j = 0; j < 8; j++)
{
if (posicionSegura(j, i))
{
ponerReina(j, i);
if (i < 7)
{
tester(i + 1);
}
else
afficher();
quitarReina(j, i);
}
}
}
static void Main(string[] args)
{
inicializar();
tester(0);
Console.ReadKey();
}
}
}