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
COMTI Matteo
Prog2Aix-tp3
Commits
a34eeb44
Commit
a34eeb44
authored
4 years ago
by
Mattéo
Browse files
Options
Downloads
Patches
Plain Diff
getNeighbours done
countAliveNeighbours done calculateNextState done calculateNextStates done
parent
5809143d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Grid.java
+21
-2
21 additions, 2 deletions
Grid.java
with
21 additions
and
2 deletions
Grid.java
+
21
−
2
View file @
a34eeb44
import
java.util.*
;
import
static
com
.
sun
.
tools
.
doclint
.
Entity
.
ne
;
import
static
com
.
sun
.
tools
.
doclint
.
Entity
.
or
;
/**
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
*/
...
...
@@ -95,11 +98,22 @@ public class Grid implements Iterable<Cell> {
}
private
boolean
[][]
calculateNextStates
()
{
return
null
;
boolean
[][]
nextStates
=
new
boolean
[
numberOfRows
][
numberOfColumns
];
for
(
Cell
cell
:
this
)
{
for
(
int
i
=
0
;
i
==
numberOfRows
-
1
;
i
++)
{
for
(
int
j
=
0
;
j
==
numberOfColumns
-
1
;
j
++)
{
nextStates
[
i
][
j
]
=
calculateNextState
(
i
,
j
,
cell
);
}
}
}
return
nextStates
;
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
return
false
;
if
(
cell
.
isAlive
())
{
return
(
countAliveNeighbours
(
rowIndex
,
columnIndex
)
==
2
)
||
(
countAliveNeighbours
(
rowIndex
,
columnIndex
)
==
3
);
}
else
return
false
;
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
...
...
@@ -125,6 +139,11 @@ public class Grid implements Iterable<Cell> {
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
Iterator
<
Cell
>
iterator
=
iterator
();
while
(
iterator
.
hasNext
())
{
Cell
cell
=
iterator
.
next
();
cell
.
isAlive
()
=
nextState
[][];
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
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