Skip to content

Commit 6501d09

Browse files
author
Loïc Vanden Bemden
committed
Release v2.0 pushed
1 parent 07c9c02 commit 6501d09

30 files changed

+1511
-479
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# Blob Simulation & Detection
22
Détection d'un blob dans une image ainsi que détection des comprimés de nourriture. Simulation d'un blob dans PyGame à travers un système multi-agents à connaissance partagée.
33

4+
## Release 2.0 - *27/05/2019*
5+
6+
Le passage à cette release invalide les fichiers de sauvegarde précédents, le format ayant été modifié.
7+
8+
### Modifications :
9+
+ Logique du blob améliorée (les fourmis ont un horizon de vue, les exploratrices ont deux modes de fonctionnement et le blob calcule mieux la quantité de fourmis qu’il peut utiliser)
10+
+ Utilisation de la nourriture améliorée (le lien entre détection et virtuel est plus réaliste, la nourriture peut s’épuiser et il est plus facile d’ajouter ou retirer de la nourriture en grande quantité)
11+
+ Transformation d'une série de fichiers vers un format json (notamment les fichiers player et blob)
12+
+ Déplacement d'une série de variables dans des fichiers de configuration et création des fichiers de configuration "par défaut"
13+
+ Simplification du changement de couleurs de l'interface
14+
+ Ajout d'un script de comparaison entre deux sauvegardes
15+
16+
La nouvelle interface de la simulation produira des images comme celle-ci :
17+
18+
![Interface de simulation](example/test-run.jpg?raw=true "Interface de simulation")
19+
20+
21+
Pour exécuter le script de comparaison sur un exemple :
22+
`python compare.py --first example/test.board --second example/test-run.board`
23+
24+
L'image affichée sera la suivante :
25+
26+
![Comparaison entre deux simulations](example/test-compare.jpg?raw=true "Comparaison entre deux simulations")
27+
28+
429
## Release 1.1 - *13/05/2019*
530
Correction de bugs, réorganisation du code en dossiers et fichiers.
631
Les trois exécutables se trouvent maintenant ici :

compare.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (C) 2019 - UMons
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2.1 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
import argparse
18+
from simulation import board
19+
import pygame
20+
from pygame.locals import QUIT
21+
22+
23+
def main():
24+
ap = argparse.ArgumentParser()
25+
ap.add_argument("--first", required=True, help="first board file")
26+
ap.add_argument("--second", required=True, help="second board file")
27+
ap.add_argument("-s", "--scale", type=float, default=10, help="scale display (default: x10")
28+
ap.add_argument("-o", "--output", type=str, help="give a name to save the jpeg file")
29+
args = ap.parse_args()
30+
31+
board_1 = board.Board(0,0)
32+
board_1.load(args.first)
33+
34+
board_2 = board.Board(0,0)
35+
board_2.load(args.second)
36+
37+
board_comp = board_1.compare(board_2)
38+
39+
if board_comp is None:
40+
return
41+
42+
pygame.init()
43+
44+
width = int(board_1.width * args.scale)
45+
height = int(board_1.height * args.scale)
46+
window = pygame.display.set_mode((width, height))
47+
48+
game_surface = pygame.Surface((board_1.width, board_1.height))
49+
pixel_array = pygame.PixelArray(game_surface)
50+
for x in range(board_1.width):
51+
for y in range(board_1.height):
52+
pixel_array[x,y] = (0, 0, 0)
53+
54+
val = max(-255, min(board_comp.get_blob(x, y), 255))
55+
if val < 0:
56+
val = - val # int(-val/2) + 125
57+
pixel_array[x, y] = (val/4, val/4, val)
58+
elif val > 0:
59+
val = val # int(val/2) + 125
60+
pixel_array[x, y] = (val, val/4, val/4)
61+
else:
62+
if not board_comp.is_touched(x, y):
63+
if board_1.is_touched(x, y):
64+
pixel_array[x, y] = (75, 75, 125)
65+
else:
66+
pixel_array[x, y] = (125, 75, 75)
67+
68+
if board_comp.has_food(x, y):
69+
pixel_array[x, y] = (0, board_comp.foods[x, y], 0)
70+
71+
del pixel_array
72+
73+
game_window = pygame.transform.scale(game_surface, (width, height))
74+
75+
window.blit(game_window, (0, 0))
76+
pygame.display.flip()
77+
78+
ended = False
79+
while not ended:
80+
pygame.time.wait(10)
81+
for event in pygame.event.get():
82+
if event.type == QUIT:
83+
ended = True
84+
85+
if args.output is not None:
86+
pygame.image.save(window, args.output)
87+
88+
89+
if __name__ == "__main__":
90+
main()

detection/config.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
{"Aspect Ratio": 0.4, "Discrete Height": 40, "Discrete Width": 100, "Limits": [[136, 268], [5484, 208], [5452, 3296], [136, 3308]], "Low Food Color": [92, 140, 168], "High Food Color": [202, 226, 238]}
1+
{
2+
"Aspect Ratio": 0.4,
3+
"Discrete Height": 240,
4+
"Discrete Width": 600,
5+
"High Food Color": [
6+
214,
7+
230,
8+
237
9+
],
10+
"Limits": [
11+
[136, 268],
12+
[5484, 208],
13+
[5452, 3296],
14+
[136, 3308]
15+
],
16+
"Low Food Color": [
17+
150,
18+
185,
19+
198
20+
],
21+
"Min Food Size": 60
22+
}

0 commit comments

Comments
 (0)