Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CHERIFI Khadidja
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
CHERIFI Khadidja
CHERIFI Khadidja
Compare revisions
master to 277bf6b57255e969bcfe1ddaaded9bfd094103c0
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
c19026071/tp3
Select target project
No results found
277bf6b57255e969bcfe1ddaaded9bfd094103c0
Select Git revision
Branches
master
undefined
2 results
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 (6)
Replace Cell.java
· 16a669dd
CHERIFI Khadidja
authored
4 years ago
16a669dd
Replace GameOfLife.java
· 29d78cd6
CHERIFI Khadidja
authored
4 years ago
29d78cd6
Replace GameOfLife.java
· a42b3d5f
CHERIFI Khadidja
authored
4 years ago
a42b3d5f
Replace GameOfLifeGUI.java
· 4576739b
CHERIFI Khadidja
authored
4 years ago
4576739b
Replace Grid.java
· 8e12530a
CHERIFI Khadidja
authored
4 years ago
8e12530a
Replace GridIterator.java
· 277bf6b5
CHERIFI Khadidja
authored
4 years ago
277bf6b5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Cell.java
+6
-3
6 additions, 3 deletions
Cell.java
Grid.java
+68
-11
68 additions, 11 deletions
Grid.java
with
74 additions
and
14 deletions
Cell.java
View file @
277bf6b5
...
...
@@ -6,11 +6,14 @@ public class Cell {
private
boolean
isAlive
;
public
Cell
(){
this
.
isAlive
=
false
;
}
/**
* Determines whether this {@link Cell} is alive or not.
*
*
* @return {@code true} if this {@link Cell} is alive and {@code false} otherwise
*/
...
...
@@ -32,7 +35,7 @@ public class Cell {
/**
* Sets the state of this {@link Cell} to alive.
*
* @param cellState the new state of this {@link Cell}
* @param
*
cellState the new state of this {@link Cell}
*/
public
void
setAlive
()
{
...
...
@@ -42,7 +45,7 @@ public class Cell {
/**
* Sets the state of this {@link Cell} to dead.
*
* @param cellState the new state of this {@link Cell}
* @param
*
cellState the new state of this {@link Cell}
*/
public
void
setDead
()
{
...
...
This diff is collapsed.
Click to expand it.
Grid.java
View file @
277bf6b5
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>.
*/
public
class
Grid
implements
Iterable
<
Cell
>
{
class
Grid
implements
Iterable
<
Cell
>
{
private
final
int
numberOfRows
;
private
final
int
numberOfColumns
;
...
...
@@ -77,6 +74,7 @@ public class Grid implements Iterable<Cell> {
* @return the number of columns in this {@code Grid}
*/
public
int
getNumberOfColumns
()
{
return
numberOfColumns
;
}
...
...
@@ -98,29 +96,78 @@ public class Grid implements Iterable<Cell> {
}
private
boolean
[][]
calculateNextStates
()
{
return
null
;
boolean
[][]
new_stat
=
new
boolean
[
getNumberOfRows
()][
getNumberOfColumns
()];
for
(
int
row
=
0
;
row
<
getNumberOfRows
();
row
++){
for
(
int
col
=
0
;
col
<
getNumberOfColumns
();
col
++)
new_stat
[
row
][
col
]
=
calculateNextState
(
row
,
col
);
}
return
new_stat
;
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
return
false
;
private
boolean
calculateNextState
(
int
rows
,
int
columns
)
{
Cell
cellule
=
getCell
(
rows
,
columns
);
int
nbOfVoisinesVivantes
=
countAliveNeighbours
(
rows
,
columns
);
return
cellule
.
isAliveInNextState
(
nbOfVoisinesVivantes
);
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
0
;
List
<
Cell
>
voisine
=
getNeighbours
(
rowIndex
,
columnIndex
);
Iterator
<
Cell
>
iterator
=
voisine
.
iterator
();
int
voisine_vivant
=
0
;
while
(
iterator
.
hasNext
())
{
if
(
iterator
.
next
().
isAlive
())
voisine_vivant
=
voisine_vivant
+
1
;
}
return
voisine_vivant
;
}
private
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
null
;
List
<
Cell
>
voisine
=
new
LinkedList
<
Cell
>();
voisine
.
add
(
getCell
(
rowIndex
,
columnIndex
-
1
));
voisine
.
add
(
getCell
(
rowIndex
,
columnIndex
+
1
));
voisine
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
));
voisine
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
));
voisine
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
+
1
));
voisine
.
add
(
getCell
(
rowIndex
+
1
,
columnIndex
-
1
));
voisine
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
-
1
));
voisine
.
add
(
getCell
(
rowIndex
-
1
,
columnIndex
+
1
));
return
voisine
;
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
for
(
int
row
=
0
;
row
<
this
.
getNumberOfRows
();
row
++){
for
(
int
col
=
0
;
col
<
this
.
getNumberOfColumns
();
col
++){
Cell
stat
=
getCell
(
row
,
col
);
if
(
nextState
[
row
][
col
]){
stat
.
setAlive
();
}
else
{
stat
.
setDead
();
}
}
}
}
/**
* Sets all {@link Cell}s in this {@code Grid} as dead.
*/
void
clear
()
{
for
(
Iterator
<
Cell
>
gril
=
iterator
();
gril
.
hasNext
();){
Cell
cel
=
gril
.
next
();
cel
.
setDead
();
}
}
/**
...
...
@@ -131,6 +178,16 @@ public class Grid implements Iterable<Cell> {
*/
void
randomGeneration
(
Random
random
)
{
Iterator
<
Cell
>
gril
=
iterator
();
while
(
gril
.
hasNext
()){
Cell
cel
=
gril
.
next
();
boolean
aleatoire
=
random
.
nextBoolean
();
if
(
aleatoire
)
cel
.
setAlive
();
else
cel
.
setDead
();
}
}
}
This diff is collapsed.
Click to expand it.