forked from JuvignyEnsta/Fourmi2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequential.py
More file actions
64 lines (40 loc) · 1.4 KB
/
sequential.py
File metadata and controls
64 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
# Hide PyGame welcome message
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
import time
import numpy as np
import pygame as pg
from maze import Maze
from colony import Colony
from display import display
from constants import *
def main(seed: int = 123) -> None:
np.random.seed(seed)
pg.init()
screen = pg.display.set_mode((8 * HEIGHT, 8 * WIDTH))
pos_nest = np.array([0, 0])
pos_food = np.array([WIDTH - 1, HEIGHT - 1])
maze = Maze(WIDTH, HEIGHT)
colony = Colony(NUM_ANTS, pos_nest)
running = True
food_counter = 0
elapsed = np.array([])
while running:
start = time.time()
display(screen, maze, colony.pose_ants)
pg.display.update()
maze.pheromones = colony.update(maze, pos_food)
collected = colony.food_collected
food_counter += collected
elapsed = np.append(elapsed, time.time() - start)
print(f"{(1.0 / elapsed).mean():.2f} FPS | food: {food_counter}", end="\r")
if food_counter >= 10_000:
running = False
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
print(f"{(1.0 / elapsed).mean():.2f} FPS | food: {food_counter}")
pg.image.save(screen, f"sim_1_{(1.0 / elapsed).mean():.0f}.png")
pg.quit()
if __name__ == "__main__":
main()