-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.cs
More file actions
97 lines (90 loc) · 2.97 KB
/
Test.cs
File metadata and controls
97 lines (90 loc) · 2.97 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wolfram {
class Test {
const int VOISINNAGE = 2;
const int TAILLE = 300;
const int ITE = 300;
const int regle = 62;
static void Main (string [] args) {
int [] grille = new int [TAILLE];
int [] temp = new int [TAILLE];
Random r = new Random();
for (int i = 0 ; i < TAILLE ; i++) {
if (r.NextDouble() > 0.5)
grille [i] = 1;
else
grille [i] = 0;
}
//grille[150] = 1;
afficherGrille(grille);
for (int i = 0 ; i < ITE ; i++) {
for (int j = 0 ; j < TAILLE ; j++) {
temp [j] = calculEtatCellule(j,grille);
}
grille = new int [TAILLE];
grille = temp;
afficherGrille(grille);
temp = new int [TAILLE];
}
Console.Read();
}
static int calculEtatCellule (int cell,int [] grille) {
int ret = 0;
int voisinAllume = calculVoisin(cell,grille);
String masque = Convert.ToString(regle,2);
//masque = masque + "0";
while (masque.Length - 1 < VOISINNAGE * 2 + 1)
masque = "0" + masque;
char [] masq = masque.ToCharArray();
Array.Reverse(masq);
if (masq [voisinAllume].Equals('1'))
ret = 1;
return ret;
}
static int calculVoisin (int cell,int [] grille) {
int nbAllume = 0;
int cellTemp = cell;
int iDroite = VOISINNAGE;
int iGauche = VOISINNAGE;
while (iDroite > 0) {
cellTemp--;
iDroite--;
if (cellTemp == -1)
cellTemp = TAILLE - 1;
if (grille [cellTemp] == 1)
nbAllume++;
}
cellTemp = cell;
while (iGauche > 0) {
cellTemp++;
iGauche--;
if (cellTemp == TAILLE)
cellTemp = 0;
if (grille [cellTemp] == 1)
nbAllume++;
}
if (grille [cell] == 1)
nbAllume++;
return nbAllume;
}
static void afficherGrille (int [] grille) {
for (int j = 0 ; j < TAILLE ; j++) {
if (grille [j] == 1) {
Console.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
Console.ResetColor();
}
else {
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
Console.ResetColor();
}
}
Console.WriteLine();
}
}
}