Skip to content
Snippets Groups Projects
Commit 6ff21a5e authored by shinedday's avatar shinedday
Browse files

Update core to 0.0.4

parent 31a1fcae
Branches
No related tags found
No related merge requests found
Showing
with 203 additions and 85 deletions
"""
class antHillExample
"""
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from antExample import AntExample
from pyAmakCore.classes.amas import Amas
class AntHillExample(Amas):
class AntHillExample(AmasIHM):
def __init__(self, env):
super().__init__(env)
self.__observer = None
def get_Agents_Sorted(self):
agents = self.get_agents()
agents.sort(key=lambda x: x.get_id())
return agents
def on_initial_agents_creation(self) -> None:
for i in range(50):
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
def on_cycle_end(self) -> None:
self.__observer.updateCycle(self.get_environment(), self)
def attach(self, observer: 'Controleur') -> None:
self.__observer = observer
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
\ No newline at end of file
......@@ -7,7 +7,6 @@ from pyAmakIHM.classes.fenetre import Fenetre
from controleurAntsExample import ControleurAntsExample
from worldExample import WorldExample
from antHillExample import *
from threading import Thread
fenetre = Fenetre("Prototype Ants")
......
"""
class antHillExample
"""
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from antExample import AntExample
from pyAmakCore.classes.amas import Amas
class AntHillExample(Amas):
class AntHillExample(AmasIHM):
def __init__(self, env):
super().__init__(env)
self.__observer = None
def on_initialization(self):
self.set_execution_policy(ExecutionPolicy.TWO_PHASES)
def get_Agents_Sorted(self):
agents = self.get_agents()
agents.sort(key=lambda x: x.get_id())
return agents
def on_initial_agents_creation(self) -> None:
for i in range(50):
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
def on_cycle_end(self) -> None:
self.__observer.updateCycle(self.get_environment(), self)
def attach(self, observer: 'Controleur') -> None:
self.__observer = observer
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
\ No newline at end of file
"""
class antHillExample
"""
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from antExample import AntExample
from pyAmakCore.classes.amas import Amas
class AntHillExample(Amas):
class AntHillExample(AmasIHM):
def __init__(self, env):
super().__init__(env)
self.__observer = None
def get_Agents_Sorted(self):
agents = self.get_agents()
agents.sort(key=lambda x: x.get_id())
return agents
def on_initial_agents_creation(self) -> None:
for i in range(50):
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
def on_cycle_end(self) -> None:
self.__observer.updateCycle(self.get_environment(), self)
def attach(self, observer: 'Controleur') -> None:
self.__observer = observer
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
\ No newline at end of file
"""
class antHillExample
"""
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from antExample import AntExample
from pyAmakCore.classes.amas import Amas
from pyAmakCore.exception.override import ToOverrideWarning
class AntHillExample(Amas):
class AntHillExample(AmasIHM):
def __init__(self, env):
super().__init__(env)
self.__observer = None
def get_Agents_Sorted(self):
agents = self.get_agents()
agents.sort(key=lambda x: x.get_id())
return agents
def on_initialization(self) -> None:
ToOverrideWarning.enable_warning(False)
def on_initial_agents_creation(self) -> None:
for i in range(50):
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
def on_cycle_end(self) -> None:
self.__observer.updateCycle(self.get_environment(), self)
def attach(self, observer: 'Controleur') -> None:
self.__observer = observer
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
\ No newline at end of file
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from philosophersExample import PhilosophersExample
from pyAmakCore.classes.amas import Amas
from tableExample import TableExample
class PhilosophersAmasExamples(Amas):
class PhilosophersAmasExamples(AmasIHM):
def __init__(self):
super().__init__(TableExample())
self.__observer = None
def get_Agents_Sorted(self):
agents = self.get_agents()
agents.sort(key=lambda x: x.get_id())
return agents
def on_initial_agents_creation(self):
ps = []
......@@ -29,10 +25,4 @@ class PhilosophersAmasExamples(Amas):
ps[0].add_neighbour(ps[len(ps) - 1])
ps[len(ps) - 1].add_neighbour(ps[0])
self.add_agents(ps)
def attach(self, observer: 'Controleur') -> None:
self.__observer = observer
def on_cycle_end(self):
self.__observer.updateCycle(self.get_environment(), self)
self.add_agents(ps)
\ No newline at end of file
"""
class antExample
"""
from math import *
from random import randint
from pyAmakCore.classes.agent import Agent
from color import Color
class AntExample(Agent):
def __init__(self,
amas: 'antHillExample',
startX: float,
startY: float
) -> None:
super().__init__(amas)
self._dx = startX
self._dy = startY
self._color = Color.BLACK
self._old_color = Color.BLACK
self.__my_next_color = self._color
def get_color(self):
return self._color
def get_dx(self):
return self._dx
def get_dy(self):
return self._dy
def get_old_color(self):
return self._old_color
def on_perceive(self) -> None:
self.reset_neighbour()
for agent in self.get_amas().get_agents():
if agent != self :
self.__my_next_color = agent.get_color()
def on_act(self) -> None:
# couleur
if self.__my_next_color == self._color:
color = {
1: Color.BLUE,
2: Color.BLACK,
3: Color.RED,
4: Color.YELLOW,
5: Color.GREEN
}
if randint(1, 100) <= 4:
self._color = color.get(randint(1, 5))
else :
self._color = self.__my_next_color
# déplacement
self._dx += (randint(-1, 1) * self.get_environment().coef_deplacement)
self._dy += (randint(-1, 1) * self.get_environment().coef_deplacement)
if self._dx < self.get_environment().xmin:
self._dx = self.get_environment().xmin
if self._dx > self.get_environment().xmax:
self._dx = self.get_environment().xmax
if self._dy < self.get_environment().ymin:
self._dy = self.get_environment().ymin
if self._dy > self.get_environment().ymax:
self._dy = self.get_environment().ymax
def on_cycle_begin(self):
self._old_color = self._color
"""
class antHillExample
"""
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from antExample import AntExample
class AntHillExample(AmasIHM):
def __init__(self, env):
super().__init__(env)
def on_initial_agents_creation(self) -> None:
for i in range(2):
self.add_agent(AntExample(self, self.get_environment().xmax/2, self.get_environment().ymax/2))
\ No newline at end of file
"""
Class antsLaunchExample
"""
from random import seed
from pyAmakIHM.classes.fenetre import Fenetre
from controleurAntsExample import ControleurAntsExample
from worldExample import WorldExample
from antHillExample import *
from threading import Thread
fenetre = Fenetre("Prototype Ants")
seed()
env = WorldExample(0, fenetre.get_canvas_width(), 0, fenetre.get_canvas_height(), 7)
amas = AntHillExample(env)
controleur = ControleurAntsExample(fenetre, amas)
def main():
controleur.start()
main()
from enum import *
class Color(Enum):
BLACK= auto()
RED=auto()
BLUE=auto()
GREEN=auto()
YELLOW=auto()
\ No newline at end of file
from color import Color
from pyAmakIHM.classes.controleur import Controleur
class ControleurAntsExample(Controleur):
def __init__(self, fenetre, amas):
super().__init__(fenetre, amas)
self.__ants = []
self.__numberAnts = 2
def initialisation(self):
widthCanvas = self.get_fenetre().get_canvas_width()
heightCanvas = self.get_fenetre().get_canvas_height()
for i in range(self.__numberAnts):
self.__ants.append(self.draw_image(widthCanvas / 2, heightCanvas / 2, 'images/blackAnt.png'))
def updateWindow(self, env, amas):
ants = amas.get_Agents_Sorted()
for i in range(len(ants)):
x = ants[i].get_dx()
y = ants[i].get_dy()
color = ants[i].get_color()
if color != ants[i].get_old_color():
self.remove_element(self.__ants[i])
if color == Color.BLUE:
self.__ants[i] = self.draw_image(x, y, 'images/blueAnt.png')
elif color == Color.GREEN:
self.__ants[i] = self.draw_image(x, y, 'images/greenAnt.png')
elif color == Color.RED:
self.__ants[i] = self.draw_image(x, y, 'images/redAnt.png')
elif color == Color.YELLOW:
self.__ants[i] = self.draw_image(x, y, 'images/yellowAnt.png')
elif color == Color.BLACK:
self.__ants[i] = self.draw_image(x, y, 'images/blackAnt.png')
self.move_image(self.__ants[i], x, y)
proof_of_concept/2_phases_agent_cycle/images/blackAnt.png

537 B

proof_of_concept/2_phases_agent_cycle/images/blueAnt.png

630 B

proof_of_concept/2_phases_agent_cycle/images/greenAnt.png

627 B

proof_of_concept/2_phases_agent_cycle/images/redAnt.png

629 B

proof_of_concept/2_phases_agent_cycle/images/yellowAnt.png

630 B

"""
Class worldExample
"""
from pyAmakCore.classes.environment import Environment
class WorldExample(Environment):
def __init__(self, xmin, xmax, ymin, ymax, coef_deplacement):
super().__init__()
self.xmin = xmin
self.xmax = xmax
self.ymin = ymin
self.ymax = ymax
self.coef_deplacement = coef_deplacement
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment