Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FirefighterStarter
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
OUALAN Yanis
FirefighterStarter
Commits
cac78e2b
Commit
cac78e2b
authored
7 months ago
by
Yanis O
Committed by
melizzzz
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Changement de la logique de taille dans FireFighterScenario
parent
3f56cf62
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/model/FireFighterScenario.java
+28
-29
28 additions, 29 deletions
src/main/java/model/FireFighterScenario.java
src/main/java/util/TargetStrategy.java
+1
-1
1 addition, 1 deletion
src/main/java/util/TargetStrategy.java
with
29 additions
and
30 deletions
src/main/java/model/FireFighterScenario.java
+
28
−
29
View file @
cac78e2b
package
model
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
util.Matrix
;
...
...
@@ -8,19 +9,22 @@ import util.Position;
public
class
FireFighterScenario
implements
Board
<
Entity
>{
private
Matrix
<
Entity
>
matrix
private
Matrix
<
Entity
>
matrix
;
private
int
step
;
public
FireFighterScenario
(
int
boardSize
){
this
.
matrix
=
new
Matrix
();
this
.
matrix
=
new
Matrix
<
Entity
>();
this
.
step
=
0
;
}
public
Entity
getState
(
Position
position
){
if
(
position
.
x
()
>
matrix
.
size
()
||
position
.
y
()
>
matrix
.
get
(
0
).
size
()){
if
(
position
.
x
()
>
matrix
.
size
()
||
position
.
y
()
>
matrix
.
size
()){
throw
new
IllegalArgumentException
(
"The position x:"
+
position
.
x
()
+
" y:"
+
position
.
y
()
+
" is out of the board."
);
}
return
matrix
.
get
(
position
.
x
()
).
get
(
position
.
y
());
return
matrix
.
get
(
position
.
x
()
,
position
.
y
());
}
public
void
setState
(
Entity
state
,
Position
position
){
matrix
.
get
(
position
.
x
()).
set
(
position
.
y
(),
state
);
matrix
.
set
(
position
.
x
(),
position
.
y
(),
state
);
}
...
...
@@ -29,38 +33,33 @@ public class FireFighterScenario implements Board<Entity>{
}
public
int
columnCount
(){
return
matrix
.
get
(
0
).
size
();
return
matrix
.
size
();
// On considère que la matrice est toujours une matrice carré
}
/**
* Update the board to its next generation or state. This method may modify the
* internal state of the board and return a list of positions that have changed
* during the update.
*
* @return A list of positions that have changed during the update.
*/
public
List
<
Position
>
updateToNextGeneration
()
{
for
(
ArrayList
<
Entity
>
l
:
matrix
){
for
(
Entity
e
:
l
){
ArrayList
<
Position
>
changedPositions
=
new
ArrayList
<>();
Iterator
<
Entity
>
iterator
=
matrix
.
iterator
();
while
(
iterator
.
hasNext
())
{
Entity
e
=
iterator
.
next
();
Position
p
=
new
Position
(
e
.
getPosition
().
x
(),
e
.
getPosition
().
y
());
e
.
nextTurn
(
this
);
if
(!
e
.
getPosition
().
equals
(
p
))
{
changedPositions
.
add
(
p
);
}
}
return
matrix
;
return
changedPositions
;
}
/**
* Reset the board to its initial state.
*/
public
void
reset
(){
throw
new
IllegalStateException
(
"Method not implemented"
);
matrix
.
clear
(
);
}
/**
* Get the current step number or generation of the board.
*
* @return The current step number or generation.
*/
public
int
stepNumber
(){
return
0
;
return
this
.
step
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/util/TargetStrategy.java
+
1
−
1
View file @
cac78e2b
...
...
@@ -17,7 +17,7 @@ public class TargetStrategy {
* @param targets positions that are targeted.
* @return the position next to the current position that is on the path to the closest target.
*/
Position
neighborClosestToFire
(
Position
position
,
Collection
<
Position
>
targets
,
public
Position
neighborClosestToFire
(
Position
position
,
Collection
<
Position
>
targets
,
Map
<
Position
,
List
<
Position
>>
neighbors
)
{
Set
<
Position
>
seen
=
new
HashSet
<
Position
>();
HashMap
<
Position
,
Position
>
firstMove
=
new
HashMap
<
Position
,
Position
>();
...
...
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