Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Game of life Template
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
MALEK Hiba
Game of life Template
Commits
42c0645a
Commit
42c0645a
authored
5 months ago
by
hiba1907
Browse files
Options
Downloads
Patches
Plain Diff
Realisation des derinieres taches du ttp jeu de la vie
parent
c695e6fc
No related branches found
No related tags found
No related merge requests found
Pipeline
#41726
passed
5 months ago
Stage: build
Stage: test
Changes
22
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/model/ConstantCellInitializer.java
+5
-6
5 additions, 6 deletions
src/main/java/model/ConstantCellInitializer.java
src/main/java/model/NextGenerationInitializer.java
+18
-9
18 additions, 9 deletions
src/main/java/model/NextGenerationInitializer.java
with
23 additions
and
15 deletions
src/main/java/model/ConstantCellInitializer.java
+
5
−
6
View file @
42c0645a
...
...
@@ -11,20 +11,19 @@ import matrix.MatrixInitializer;
* @param <T> the type of content of each cell
*/
public
class
ConstantCellInitializer
<
T
>
implements
MatrixInitializer
<
Cell
<
T
>>
{
//TODO: ajouter la/les propriétes nécessaires
private
final
T
defaultValue
;
/** Make a new {@link MatrixInitializer} with cells containing a {@link Cell} with the same
* value.
*
* @param defaultValue the value stored in each cell.
*/
public
ConstantCellInitializer
(
T
defaultValue
)
{
//TODO: à compléter
}
this
.
defaultValue
=
defaultValue
;
}
@Override
public
Cell
<
T
>
initialValueAt
(
Coordinate
coordinate
)
{
//
TODO: à compléter
return
n
ull
;
//
retourne la nouvelle cellule avec la valeur constante par def
return
n
ew
Cell
<>(
defaultValue
)
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/model/NextGenerationInitializer.java
+
18
−
9
View file @
42c0645a
package
model
;
import
java.util.ArrayList
;
import
java.util.List
;
import
controller.Simulation
;
import
matrix.Coordinate
;
import
matrix.MatrixInitializer
;
import
matrix.ListMatrix
;
import
controller.Simulation
;
import
matrix.MatrixInitializer
;
/**
* An initializer for a {@link ListMatrix} of states, where each state is computed based on the value
...
...
@@ -13,7 +17,7 @@ import controller.Simulation;
*/
public
class
NextGenerationInitializer
<
S
extends
State
<
S
>>
implements
MatrixInitializer
<
S
>
{
//TODO: ajouter les propriétés nécessaires
private
final
CellularAutomatonSimulation
<
S
>
simulation
;
/** Create a {@link MatrixInitializer} to compute the next generation in
* a 2D cellular automaton.
...
...
@@ -21,13 +25,18 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @param simulation the {@link Simulation} representing the cellular automaton.
*/
public
NextGenerationInitializer
(
CellularAutomatonSimulation
<
S
>
simulation
)
{
//TODO: à compléter
this
.
simulation
=
simulation
;
}
@Override
public
S
initialValueAt
(
Coordinate
coordinate
)
{
//TODO: à compléter
return
null
;
public
S
initialValueAt
(
Coordinate
coordinate
)
{
List
<
Coordinate
>
neighbours
=
coordinate
.
orthodiagonalNeighbours
();
List
<
S
>
states
=
new
ArrayList
<>();
for
(
Coordinate
neighbour:
neighbours
){
states
.
add
(
this
.
simulation
.
at
(
wrap
(
neighbour
)).
get
());
}
return
this
.
simulation
.
at
(
coordinate
).
get
().
update
(
states
);
}
/** Computes the grid {@link Coordinate} for an arbitrary {@link Coordinate}, even outside
...
...
@@ -39,10 +48,10 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @return a corresponding {@link Coordinate}, that is inside the grid.
*/
Coordinate
wrap
(
Coordinate
coordinate
)
{
//TODO: à compléter
//Il faut recalculer les coordonnées x et y modulo les dimensions de la grille.
//Pour le modulo, utiliser la fonction ci-dessous, qui s'assure que le résultat est positif.
return
null
;
return
new
Coordinate
(
modulo
(
coordinate
.
x
(),
this
.
simulation
.
numberOfColumns
()),
modulo
(
coordinate
.
y
(),
this
.
simulation
.
numberOfRows
()));
}
/** The non-negative remainder of n divided by d.
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment