jeu_de_la_vie_nherve 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/jeu_de_la_vie_nherve.rb +94 -0
  2. metadata +46 -0
@@ -0,0 +1,94 @@
1
+
2
+ #taille = ARGV[0].to_i
3
+ taille = 30
4
+ matrice = Array.new(taille)
5
+ for i in 0..taille-1
6
+ tableau = Array.new(taille)
7
+ for j in 0..taille-1
8
+ if(rand(5)==4)
9
+ tableau[j]=1
10
+ else
11
+ tableau[j]=0
12
+ end
13
+ end
14
+ matrice[i]=tableau
15
+ end
16
+
17
+ def affichage(matrice)
18
+ matrice.each do |tab|
19
+ ligne=''
20
+ tab.each do |i|
21
+ if i==1
22
+ ligne=ligne+'o'
23
+ else
24
+ ligne=ligne+' '
25
+ end
26
+ end
27
+ puts ligne
28
+ end
29
+ end
30
+
31
+ def etatSuivant(matrice)
32
+ taille = matrice.count
33
+ maMatrice = Array.new(taille)
34
+ for i in 0..taille-1
35
+ maMatrice[i]=Array.new(taille)
36
+ end
37
+ for l in 0..taille-1
38
+ for c in 0..taille-1
39
+ compteur = 0
40
+
41
+ if l>0
42
+ compteur = compteur + matrice [l-1][c]
43
+ if c>0
44
+ compteur = compteur + matrice [l-1][c-1]
45
+ end
46
+ if c<taille-1
47
+ compteur = compteur + matrice [l-1][c+1]
48
+ end
49
+ end
50
+
51
+ if c>0
52
+ compteur = compteur + matrice [l][c-1]
53
+ end
54
+ if c<taille-1
55
+ compteur = compteur + matrice [l][c+1]
56
+ end
57
+
58
+ if l<taille-1
59
+ compteur = compteur + matrice [l+1][c]
60
+ if c>0
61
+ compteur = compteur + matrice [l+1][c-1]
62
+ end
63
+ if c<taille-1
64
+ compteur = compteur + matrice [l+1][c+1]
65
+ end
66
+ end
67
+
68
+ if compteur == 3
69
+ maMatrice[l][c]=1
70
+ elsif compteur == 2
71
+ maMatrice[l][c]=matrice[l][c]
72
+ else
73
+ maMatrice[l][c]=0
74
+ end
75
+ end
76
+ end
77
+ for l in 0..taille-1
78
+ for c in 0..taille-1
79
+ matrice[l][c] = maMatrice[l][c]
80
+ end
81
+ end
82
+ end
83
+
84
+ system "clear"
85
+ affichage(matrice)
86
+
87
+ cpt=0
88
+ while(cpt<1000)
89
+ cpt=cpt+1
90
+ etatSuivant(matrice)
91
+ sleep(0.1)
92
+ system "clear"
93
+ affichage(matrice)
94
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeu_de_la_vie_nherve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicolas Hervé
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Un jeu avec plein de cellules qui crevent
15
+ email: nicolas.herve@y-nov.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/jeu_de_la_vie_nherve.rb
21
+ homepage: http://www.google.fr/
22
+ licenses:
23
+ - nherve
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.23
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Le jeu de la vie
46
+ test_files: []