Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jean Descamps
projet_IA04
Commits
8f611efd
Commit
8f611efd
authored
Jan 01, 2022
by
Alexandre Constantin
Browse files
modif niveau (sable plus barrière invisible top)
parent
5bb50955
Changes
5
Hide whitespace changes
Inline
Side-by-side
Boid/agent/boid/boid.go
View file @
8f611efd
...
...
@@ -212,11 +212,11 @@ func (boid *Boid) CheckEdges() bool {
}
else
if
boid
.
Position
.
X
>
constant
.
ScreenWidth
{
boid
.
Position
.
X
=
0
}
if
boid
.
Position
.
Y
<
0
{
boid
.
Position
.
Y
=
constant
.
ScreenHeight
}
else
if
boid
.
Position
.
Y
>
constant
.
ScreenHeight
{
boid
.
Position
.
Y
=
0
}
//
if boid.Position.Y < 0 {
//
boid.Position.Y = constant.ScreenHeight
//
} else if boid.Position.Y > constant.ScreenHeight {
//
boid.Position.Y = 0
//
}
return
false
}
...
...
@@ -292,7 +292,7 @@ func (preda *Predator) ApplyRules(restOfFlock []*Boid) {
//Tuer
for
_
,
Boid
:=
range
restOfFlock
{
if
(
preda
.
Position
.
Distance
(
Boid
.
Position
))
<
1
5
{
if
(
preda
.
Position
.
Distance
(
Boid
.
Position
))
<
1
0
{
Boid
.
Dead
=
true
}
}
...
...
@@ -308,32 +308,32 @@ func (preda *Predator) ApplyRules(restOfFlock []*Boid) {
}
else
if
vPoint
[
0
]
.
X
<
0
{
newP
.
Position
.
X
=
preda
.
Position
.
X
+
constant
.
ScreenWidth
}
if
vPoint
[
0
]
.
Y
>
constant
.
ScreenHeight
{
newP
.
Position
.
Y
=
preda
.
Position
.
Y
-
constant
.
ScreenHeight
}
else
if
vPoint
[
0
]
.
Y
<
0
{
newP
.
Position
.
Y
=
preda
.
Position
.
Y
+
constant
.
ScreenHeight
}
//
if vPoint[0].Y > constant.ScreenHeight {
//
newP.Position.Y = preda.Position.Y - constant.ScreenHeight
//
} else if vPoint[0].Y < 0 {
//
newP.Position.Y = preda.Position.Y + constant.ScreenHeight
//
}
if
vPoint
[
1
]
.
X
>
constant
.
ScreenWidth
{
newP
.
Position
.
X
=
preda
.
Position
.
X
-
constant
.
ScreenWidth
}
else
if
vPoint
[
1
]
.
X
<
0
{
newP
.
Position
.
X
=
preda
.
Position
.
X
+
constant
.
ScreenWidth
}
if
vPoint
[
1
]
.
Y
>
constant
.
ScreenHeight
{
newP
.
Position
.
Y
=
preda
.
Position
.
Y
-
constant
.
ScreenHeight
}
else
if
vPoint
[
1
]
.
Y
<
0
{
newP
.
Position
.
Y
=
preda
.
Position
.
Y
+
constant
.
ScreenHeight
}
//
if vPoint[1].Y > constant.ScreenHeight {
//
newP.Position.Y = preda.Position.Y - constant.ScreenHeight
//
} else if vPoint[1].Y < 0 {
//
newP.Position.Y = preda.Position.Y + constant.ScreenHeight
//
}
}
preda
.
V1
=
vPoint
[
0
]
preda
.
V2
=
vPoint
[
1
]
if
new
{
vPoint2
=
newP
.
Vision
()
if
(
vPoint
[
1
]
.
X
>
constant
.
ScreenWidth
||
vPoint
[
1
]
.
X
<
0
)
||
(
vPoint
[
1
]
.
Y
>
constant
.
ScreenHeight
||
vPoint
[
1
]
.
Y
<
0
)
{
if
vPoint
[
1
]
.
X
>
constant
.
ScreenWidth
||
vPoint
[
1
]
.
X
<
0
{
preda
.
V2
=
vPoint2
[
1
]
}
if
(
vPoint
[
0
]
.
X
>
constant
.
ScreenWidth
||
vPoint
[
0
]
.
X
<
0
)
||
(
vPoint
[
0
]
.
Y
>
constant
.
ScreenHeight
||
vPoint
[
0
]
.
Y
<
0
)
{
if
vPoint
[
0
]
.
X
>
constant
.
ScreenWidth
||
vPoint
[
0
]
.
X
<
0
{
preda
.
V1
=
vPoint2
[
0
]
}
}
...
...
@@ -411,11 +411,11 @@ func (preda *Predator) CheckEdges() bool {
}
else
if
preda
.
Position
.
X
>
constant
.
ScreenWidth
{
preda
.
Position
.
X
=
0
}
if
preda
.
Position
.
Y
<
0
{
preda
.
Position
.
Y
=
constant
.
ScreenHeight
}
else
if
preda
.
Position
.
Y
>
constant
.
ScreenHeight
{
preda
.
Position
.
Y
=
0
}
//
if preda.Position.Y < 0 {
//
preda.Position.Y = constant.ScreenHeight
//
} else if preda.Position.Y > constant.ScreenHeight {
//
preda.Position.Y = 0
//
}
return
false
}
...
...
Boid/agent/wall/wall.go
View file @
8f611efd
...
...
@@ -8,4 +8,5 @@ type Wall struct {
ImageWidth
int
ImageHeight
int
Position
vector
.
Vector2D
TypeWall
int
}
Boid/game/game.go
View file @
8f611efd
...
...
@@ -59,27 +59,27 @@ func NewGame(c chan string, timeOut int) *Game {
// niveau 0: ce niveau est très simple:les poissons sont amenés à se regrouper et se stabiliser rapidement
// rendant leur pêche facile.
g
.
levels
[
0
]
=
NewLevel
(
10000
,
10
,
300
,
100
,
16
+
1
0
,
1
,
4.0
,
1000
,
15
)
g
.
levels
[
0
]
=
NewLevel
(
10000
,
10
,
300
,
100
,
30
0
,
1
,
4.0
,
1000
,
15
)
// niveau 1: ce niveau est identique au niveau 0 à la différence que cette fois-ci les requins attaquent bien
// plus: leur attribue density est diminué de tel sorte à ce qu’il attaque pour une quantité de poisson dans leur
// champ d’attaque inférieur à celle du niveau 0. Le joueur doit donc être plus rapide pour ne pas se faire
// niveau 1: ce niveau est identique au niveau 0 à la différence que cette fois-ci les requins attaquent bien
// plus: leur attribue density est diminué de tel sorte à ce qu’il attaque pour une quantité de poisson dans leur
// champ d’attaque inférieur à celle du niveau 0. Le joueur doit donc être plus rapide pour ne pas se faire
// manger tous ses poisons par les prédateurs.
g
.
levels
[
1
]
=
NewLevel
(
10000
,
10
,
300
,
100
,
16
+
10
,
1
,
4.0
,
1000
,
8
)
g
.
levels
[
1
]
=
NewLevel
(
10000
,
10
,
300
,
100
,
16
+
10
+
300
,
1
,
4.0
,
1000
,
8
)
// niveau 2: ce niveau est dans la continuité du niveau 1 mais ici: le facteur de cohésion diminue, et ceux de
// répulsion intra et inter espèces augmentent ce qui diminue la stabilité dans le comportement des poissons les
// rendant plus complexes à attraper: ils se regroupent moins, et se mélangent plus entre espèces. De plus, la
// niveau 2: ce niveau est dans la continuité du niveau 1 mais ici: le facteur de cohésion diminue, et ceux de
// répulsion intra et inter espèces augmentent ce qui diminue la stabilité dans le comportement des poissons les
// rendant plus complexes à attraper: ils se regroupent moins, et se mélangent plus entre espèces. De plus, la
// taille maximale du filet diminue.
g
.
levels
[
2
]
=
NewLevel
(
500
,
100
,
100
,
75
,
16
+
10
,
2.0
,
4.0
,
700
,
8
)
g
.
levels
[
2
]
=
NewLevel
(
500
,
100
,
100
,
75
,
16
+
10
+
300
,
2.0
,
4.0
,
700
,
8
)
// niveau 3: pour ce niveau, on reprend le niveau 2 et on augmente le niveau difficulté en réduisant le niveau
// de stabilité de manière similaire à ce qui fut fait pour le niveau 2. En plus, on rend les prédateurs plus
// niveau 3: pour ce niveau, on reprend le niveau 2 et on augmente le niveau difficulté en réduisant le niveau
// de stabilité de manière similaire à ce qui fut fait pour le niveau 2. En plus, on rend les prédateurs plus
// agressifs en utilisant le même procédé utilisé dans le niveau 1.
g
.
levels
[
3
]
=
NewLevel
(
50
,
100
,
75
,
75
,
16
+
10
,
2.0
,
4.0
,
700
,
5
)
g
.
levels
[
3
]
=
NewLevel
(
50
,
100
,
75
,
75
,
16
+
10
+
300
,
2.0
,
4.0
,
700
,
5
)
// niveau 4: pour ce niveau on reprend le niveau 3 et on rajoute des murs/ bombes pour favoriser le chaos et
// rendre plus difficile la tâche d’'attraper les poissons. De plus les poissons sont moins en cohésion et vont
// niveau 4: pour ce niveau on reprend le niveau 3 et on rajoute des murs/ bombes pour favoriser le chaos et
// rendre plus difficile la tâche d’'attraper les poissons. De plus les poissons sont moins en cohésion et vont
// plus vite et bien sûr, les prédateurs sont encore plus agressifs :).
g
.
levels
[
4
]
=
NewLevel
(
50
,
100
,
50
,
75
,
16
+
10
+
2
*
48
,
2.0
,
5.0
,
700
,
3
)
...
...
@@ -160,7 +160,7 @@ func (g *Game) setGame(currentLevel int, initScore int) {
// Pour éviter que les agents apparaisent au dessus ou en dessous des murs de bombes:
// on les fait apparaitre horizontalement en ligne au mileu de l'écran:
middle
:=
constant
.
ScreenHeight
/
2
x
,
y
:=
rand
.
Float64
()
*
float64
(
constant
.
ScreenWidth
-
w
),
float64
(
middle
)
x
,
y
:=
rand
.
Float64
()
*
float64
(
constant
.
ScreenWidth
-
w
),
float64
(
middle
+
100
)
min
,
max
:=
-
variable
.
MaxForce
,
variable
.
MaxForce
vx
,
vy
:=
rand
.
Float64
()
*
(
max
-
min
)
+
min
,
rand
.
Float64
()
*
(
max
-
min
)
+
min
...
...
@@ -182,16 +182,50 @@ func (g *Game) setGame(currentLevel int, initScore int) {
// Mise en place des murs/bombes en fonction du niveau
wallIndex
:=
0
//bombe oeil droit:
wallIndex
=
g
.
eyeWallBomb
(
constant
.
ScreenWidth
*
0.5
,
constant
.
ScreenHeight
*
0.4
,
wallIndex
)
// bombe bouche
wallIndex
=
g
.
mouthWallBomb
(
constant
.
ScreenWidth
*
0.4
,
constant
.
ScreenHeight
*
0.55
,
wallIndex
)
//bombe oeil gauche:
wallIndex
=
g
.
eyeWallBomb
(
constant
.
ScreenWidth
*
0.4
,
constant
.
ScreenHeight
*
0.4
,
wallIndex
)
if
g
.
currentLevel
>=
1
{
wallIndex
=
g
.
eyeWallBomb
(
constant
.
ScreenWidth
*
0.5
,
constant
.
ScreenHeight
*
0.4
,
wallIndex
)
// bombe bouche
wallIndex
=
g
.
mouthWallBomb
(
constant
.
ScreenWidth
*
0.4
,
constant
.
ScreenHeight
*
0.55
,
wallIndex
)
//bombe oeil gauche:
wallIndex
=
g
.
eyeWallBomb
(
constant
.
ScreenWidth
*
0.4
,
constant
.
ScreenHeight
*
0.4
,
wallIndex
)
}
if
g
.
currentLevel
>
3
{
//Toit de Bombe:
wallIndex
=
g
.
sideWallBomb
(
true
,
wallIndex
)
//Sol de Bombe:
g
.
sideWallBomb
(
false
,
wallIndex
)
wallIndex
=
g
.
sideWallBomb
(
false
,
wallIndex
)
}
if
g
.
currentLevel
<
4
{
w
,
h
:=
variable
.
SandImage
.
Size
()
for
sx
:=
0
;
sx
<
100
;
sx
++
{
g
.
Flock
.
Walls
[
wallIndex
]
=
&
wall
.
Wall
{
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
(
float64
(
h
-
5
)
*
float64
(
sx
)),
Y
:
constant
.
ScreenHeight
-
1
},
TypeWall
:
1
,
}
wallIndex
++
}
for
sx
:=
0
;
sx
<
100
;
sx
++
{
g
.
Flock
.
Walls
[
wallIndex
]
=
&
wall
.
Wall
{
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
(
float64
(
h
-
5
)
*
float64
(
sx
)),
Y
:
constant
.
ScreenHeight
-
(
float64
(
h
-
5
))},
TypeWall
:
1
,
}
wallIndex
++
}
for
sx
:=
0
;
sx
<
100
;
sx
++
{
g
.
Flock
.
Walls
[
wallIndex
]
=
&
wall
.
Wall
{
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
float64
(
h
-
5
)
*
float64
(
sx
),
Y
:
-
1
},
TypeWall
:
2
,
}
wallIndex
++
}
}
// Positionement des murs aléatoire: on garde au cas où...
...
...
@@ -312,11 +346,19 @@ func (g *Game) Draw(screen *ebiten.Image) {
w
,
h
=
variable
.
WallImage
.
Size
()
for
_
,
wall
:=
range
g
.
Flock
.
Walls
{
op
.
GeoM
.
Reset
()
op
.
GeoM
.
Translate
(
-
float64
(
w
)
/
2
,
-
float64
(
h
)
/
2
)
// op.GeoM.Rotate(math.Pi / 2)
op
.
GeoM
.
Translate
(
wall
.
Position
.
X
,
wall
.
Position
.
Y
)
screen
.
DrawImage
(
variable
.
WallImage
,
&
op
)
if
wall
.
TypeWall
==
0
{
op
.
GeoM
.
Reset
()
op
.
GeoM
.
Translate
(
-
float64
(
w
)
/
2
,
-
float64
(
h
)
/
2
)
// op.GeoM.Rotate(math.Pi / 2)
op
.
GeoM
.
Translate
(
wall
.
Position
.
X
,
wall
.
Position
.
Y
)
screen
.
DrawImage
(
variable
.
WallImage
,
&
op
)
}
else
if
wall
.
TypeWall
==
1
{
op
.
GeoM
.
Reset
()
op
.
GeoM
.
Translate
(
-
float64
(
w
)
/
2
,
-
float64
(
h
)
/
2
)
// op.GeoM.Rotate(math.Pi / 2)
op
.
GeoM
.
Translate
(
wall
.
Position
.
X
,
wall
.
Position
.
Y
)
screen
.
DrawImage
(
variable
.
SandImage
,
&
op
)
}
}
//Draw GUI
...
...
@@ -443,6 +485,7 @@ func (g *Game) mouthWallBomb(xPos float64, yPos float64, currentWallIndex int) i
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
x
,
Y
:
y
},
TypeWall
:
0
,
}
wallIndex
++
}
...
...
@@ -495,6 +538,7 @@ func (g *Game) eyeWallBomb(xPos float64, yPos float64, currentWallIndex int) int
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
x
,
Y
:
y
},
TypeWall
:
0
,
}
wallIndex
++
}
...
...
@@ -533,6 +577,7 @@ func (g *Game) sideWallBomb(top bool, currentWallIndex int) int {
ImageWidth
:
w
,
ImageHeight
:
h
,
Position
:
Vector2D
{
X
:
float64
(
x
),
Y
:
float64
(
y
)},
TypeWall
:
0
,
}
wallIndex
++
}
...
...
Boid/main.go
View file @
8f611efd
...
...
@@ -30,6 +30,14 @@ func init() {
variable
.
WallImage
=
ebiten
.
NewImage
(
bombW
,
bombH
)
variable
.
WallImage
.
DrawImage
(
bomb
,
op
)
sand
,
_
,
err
:=
ebitenutil
.
NewImageFromFile
(
"utils/fish/sand2.png"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
sW
,
sH
:=
sand
.
Size
()
variable
.
SandImage
=
ebiten
.
NewImage
(
sW
,
sH
)
variable
.
SandImage
.
DrawImage
(
sand
,
op
)
fish1
,
_
,
err
:=
ebitenutil
.
NewImageFromFile
(
"utils/fish/poisson-2.png"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
Boid/utils/fish/sand2.png
0 → 100644
View file @
8f611efd
1.56 KB
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment