Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ADAM-FARESSE-tp3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FARESSE Adam
ADAM-FARESSE-tp3
Compare revisions
master to 8d3445ff8d9c50f329fdb149aa83f9f33d96f70d
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
f18010428/tp3
Select target project
No results found
8d3445ff8d9c50f329fdb149aa83f9f33d96f70d
Select Git revision
Branches
master
1 result
Swap
Target
das.s/tp3
Select target project
das.s/tp3
f19002502/tp3
r17010960/tp3
l19004806/tp3
y19010055/tp3
o18034026/tp3
z18029613/tp3
p19021289/tp3
d19027596/tp3
f18010428/tp3
f19003868/tp3
c19022214/tp3
c19017929/tp3
m16014784/tp3
a19028956/tp3
c19026071/tp3
h18008908/tp3
17 results
master
Select Git revision
Branches
master
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (7)
JE test un commit pour voir si cela fonctionne depuis intellij
· 7672771d
adam
authored
4 years ago
7672771d
Delete TP3BIS.iml
· cc9e4b6e
FARESSE Adam
authored
4 years ago
cc9e4b6e
Delete misc.xml
· 254238a0
FARESSE Adam
authored
4 years ago
254238a0
Delete modules.xml
· eb1845fe
FARESSE Adam
authored
4 years ago
eb1845fe
Delete vcs.xml
· 71ca8681
FARESSE Adam
authored
4 years ago
71ca8681
Nouvelle classe Grid
· e68dbee2
adam
authored
4 years ago
e68dbee2
Merge remote-tracking branch 'origin/master' into master
· 8d3445ff
adam
authored
4 years ago
8d3445ff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Grid.java
+59
-14
59 additions, 14 deletions
Grid.java
with
59 additions
and
14 deletions
Grid.java
View file @
8d3445ff
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.*
;
/**
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
...
...
@@ -87,7 +84,7 @@ public class Grid implements Iterable<Cell> {
* <ul>
* <li>Any live {@link Cell} with fewer than two live neighbours dies, i.e. underpopulation.</li>
* <li>Any live {@link Cell} with two or three live neighbours lives on to the next
* generation.</li>
*
* generation.</li>
* <li>Any live {@link Cell} with more than three live neighbours dies, i.e. overpopulation.</li>
* <li>Any dead {@link Cell} with exactly three live neighbours becomes a live cell, i.e.
* reproduction.</li>
...
...
@@ -96,31 +93,69 @@ public class Grid implements Iterable<Cell> {
void
nextGeneration
()
{
goToNextState
(
calculateNextStates
());
}
public
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
colummIndex
)
{
List
<
Cell
>
listofNeighbours
=
new
ArrayList
<
Cell
>(
0
);
listofNeighbours
.
add
(
getCell
(
rowIndex
+
1
,
colummIndex
-
1
));
listofNeighbours
.
add
(
getCell
(
rowIndex
+
1
,
colummIndex
));
listofNeighbours
.
add
(
getCell
(
rowIndex
+
1
,
colummIndex
+
1
));
listofNeighbours
.
add
(
getCell
(
rowIndex
,
colummIndex
+
1
));
listofNeighbours
.
add
(
getCell
(
rowIndex
-
1
,
colummIndex
+
1
));
listofNeighbours
.
add
(
getCell
(
rowIndex
-
1
,
colummIndex
));
listofNeighbours
.
add
(
getCell
(
rowIndex
-
1
,
colummIndex
-
1
));
listofNeighbours
.
add
(
getCell
(
rowIndex
,
colummIndex
-
1
));
return
listofNeighbours
;
private
boolean
[][]
calculateNextStates
()
{
return
null
;
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
int
AliveNeighbours
=
0
;
for
(
Cell
Neighbour
:
getNeighbours
(
rowIndex
,
columnIndex
)){
if
(
Neighbour
.
isAlive
())
AliveNeighbours
++;
}
return
AliveNeighbours
;
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
){
if
(
countAliveNeighbours
(
rowIndex
,
columnIndex
)==
3
&&
!
getCell
(
rowIndex
,
columnIndex
).
isAlive
())
return
true
;
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
if
(
getCell
(
rowIndex
,
columnIndex
).
isAlive
()
&&
(
countAliveNeighbours
(
rowIndex
,
columnIndex
)==
2
||
countAliveNeighbours
(
rowIndex
,
columnIndex
)
==
3
))
return
true
;
else
return
false
;
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
0
;
private
boolean
[][]
calculateNextStates
()
{
boolean
[][]
tableau
=
new
boolean
[
numberOfRows
][
numberOfColumns
];
for
(
int
row
=
0
;
row
<
numberOfRows
;
row
++){
for
(
int
column
=
0
;
column
<
numberOfColumns
;
column
++){
tableau
[
row
][
column
]=
calculateNextState
(
row
,
column
);
}
}
return
tableau
;
}
private
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
null
;
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
for
(
int
i
=
0
;
i
<
numberOfRows
;
i
++)
{
for
(
int
j
=
0
;
j
<
numberOfColumns
;
j
++)
{
if
(
nextState
[
i
][
j
])
getCell
(
i
,
j
).
setAlive
();
else
getCell
(
i
,
j
).
setDead
();
}
}
}
/**
* Sets all {@link Cell}s in this {@code Grid} as dead.
*/
void
clear
()
{
for
(
int
i
=
0
;
i
<
numberOfRows
;
i
++)
{
for
(
int
j
=
0
;
j
<
numberOfColumns
;
j
++)
{
getCell
(
i
,
j
).
setDead
();
}
}
}
/**
...
...
@@ -131,6 +166,16 @@ public class Grid implements Iterable<Cell> {
*/
void
randomGeneration
(
Random
random
)
{
for
(
int
i
=
0
;
i
<
numberOfRows
;
i
++)
{
for
(
int
j
=
0
;
j
<
numberOfColumns
;
j
++)
{
if
(
random
.
nextBoolean
())
getCell
(
i
,
j
).
setAlive
();
else
getCell
(
i
,
j
).
setDead
();
}
}
}
}
This diff is collapsed.
Click to expand it.