Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prog2Aix-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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FERAUD Guillaume
Prog2Aix-tp3
Compare revisions
master to master
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
f19002502/tp3
Select target project
No results found
master
Select Git revision
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
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Completing all methods of Grid.java
· 82d0af34
FERAUD Guillaume
authored
4 years ago
82d0af34
Update randomGeneration method
· b46c5736
FERAUD Guillaume
authored
4 years ago
b46c5736
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Grid.java
+55
-10
55 additions, 10 deletions
Grid.java
with
55 additions
and
10 deletions
Grid.java
View file @
b46c5736
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>.
...
...
@@ -98,29 +95,73 @@ public class Grid implements Iterable<Cell> {
}
private
boolean
[][]
calculateNextStates
()
{
return
null
;
boolean
[][]
state
=
new
boolean
[
numberOfRows
][
numberOfColumns
];
for
(
int
i
=
0
;
i
<
state
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
state
[
i
].
length
;
j
++)
{
if
(
calculateNextState
(
i
,
j
,
cells
[
i
][
j
]
))
state
[
i
][
j
]
=
true
;
else
state
[
i
][
j
]
=
false
;
}
}
return
state
;
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
int
aliveNeighbours
=
countAliveNeighbours
(
rowIndex
,
columnIndex
);
if
(
cell
.
isDead
()
&&
aliveNeighbours
==
3
)
return
true
;
if
(
cell
.
isAlive
()
&&
aliveNeighbours
==
2
||
aliveNeighbours
==
3
)
return
true
;
else
return
false
;
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
0
;
int
aliveNeighbours
=
0
;
for
(
int
i
=
0
;
i
<
getNeighbours
(
rowIndex
,
columnIndex
).
size
();
i
++)
{
Cell
cell
=
getNeighbours
(
rowIndex
,
columnIndex
).
get
(
i
);
boolean
cellState
=
cell
.
isAlive
();
if
(
cellState
)
aliveNeighbours
++;
}
return
aliveNeighbours
;
}
private
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
null
;
List
<
Cell
>
neighbours
=
new
ArrayList
<>();
neighbours
.
add
(
getCell
(
rowIndex
,
columnIndex
+
1
));
neighbours
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
+
1
));
neighbours
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
));
neighbours
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
-
1
));
neighbours
.
add
(
getCell
(
rowIndex
,
columnIndex
-
1
));
neighbours
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
-
1
));
neighbours
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
));
neighbours
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
+
1
));
return
neighbours
;
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
for
(
int
i
=
0
;
i
<
nextState
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
nextState
[
i
].
length
;
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
()
{
boolean
[][]
clearState
=
new
boolean
[
numberOfRows
][
numberOfColumns
];
for
(
int
i
=
0
;
i
<
clearState
.
length
;
i
++)
{
Arrays
.
fill
(
clearState
[
i
],
false
);
}
goToNextState
(
clearState
);
}
/**
...
...
@@ -131,6 +172,10 @@ public class Grid implements Iterable<Cell> {
*/
void
randomGeneration
(
Random
random
)
{
boolean
[][]
randomState
=
new
boolean
[
numberOfRows
][
numberOfColumns
];
for
(
int
i
=
0
;
i
<
randomState
.
length
;
i
++)
{
Arrays
.
fill
(
randomState
[
i
],
random
.
nextBoolean
());
}
goToNextState
(
randomState
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.