Skip to content
Snippets Groups Projects
Commit 084fe304 authored by BERTHOUMIEU Aymeric's avatar BERTHOUMIEU Aymeric
Browse files

Merge branch 'Aymeric' into 'master'

Aymeric

See merge request !23
parents 2a12c6ce 6c8df384
Branches
No related tags found
1 merge request!23Aymeric
SRCDIR := src/
main : main.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o
g++ -Wall -std=c++11 -o main main.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o -I $(SRCDIR) -lX11 -lpthread
main : main.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Sensor.o BaseDecorator.o Fin.o Ears.o Shell.o Eyes.o PetFactory.o Statistics.o MoveUtils.o
g++ -Wall -std=c++11 -o main main.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Sensor.o BaseDecorator.o Ears.o Shell.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o -I $(SRCDIR) -lX11 -lpthread
Aquarium.o : $(SRCDIR)Aquarium.h $(SRCDIR)Aquarium.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Aquarium.cpp -I $(SRCDIR)
......@@ -30,12 +30,23 @@ KamikazeBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)KamikazeBehaviour.h
Statistics.o : $(SRCDIR)Statistics.h $(SRCDIR)Statistics.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Statistics.cpp -I $(SRCDIR)
Fin.o : $(SRCDIR)Fin.h $(SRCDIR)Fin.cpp
Fin.o : $(SRCDIR)BaseDecorator.h $(SRCDIR)Fin.h $(SRCDIR)Fin.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Fin.cpp -I $(SRCDIR)
Eyes.o : $(SRCDIR)Eyes.h $(SRCDIR)Eyes.cpp
Ears.o : $(SRCDIR)BaseDecorator.h $(SRCDIR)Sensor.h $(SRCDIR)Ears.h $(SRCDIR)Ears.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Ears.cpp -I $(SRCDIR)
Shell.o : $(SRCDIR)BaseDecorator.h $(SRCDIR)Shell.h $(SRCDIR)Shell.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Shell.cpp -I $(SRCDIR)
Sensor.o : $(SRCDIR)BaseDecorator.h $(SRCDIR)Sensor.h $(SRCDIR)Sensor.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Sensor.cpp -I $(SRCDIR)
BaseDecorator.o : $(SRCDIR)Animal.h $(SRCDIR)BaseDecorator.h $(SRCDIR)BaseDecorator.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)BaseDecorator.cpp -I $(SRCDIR)
Eyes.o : $(SRCDIR)BaseDecorator.h $(SRCDIR)Sensor.h $(SRCDIR)Eyes.h $(SRCDIR)Eyes.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Eyes.cpp -I $(SRCDIR)
PetFactory.o : $(SRCDIR)PetFactory.h $(SRCDIR)PetFactory.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)PetFactory.cpp -I $(SRCDIR)
\ No newline at end of file
......@@ -16,10 +16,10 @@ int main() {
int windowHeight = 800; //480
int delay = 30;
int startingNbPets = 100;
map<string, float> animalsDistribution = {{KamikazeBehaviour::getBehaviourInstance()->getBehaviourName(), 10},
{FearfulBehaviour::getBehaviourInstance()->getBehaviourName(), 30},
{GregariousBehaviour::getBehaviourInstance()->getBehaviourName(), 40},
{"b_multiple", 20}};
map<string, float> animalsDistribution = {{KamikazeBehaviour::getBehaviourInstance()->getBehaviourName(), 25},
{FearfulBehaviour::getBehaviourInstance()->getBehaviourName(), 25},
{GregariousBehaviour::getBehaviourInstance()->getBehaviourName(), 25},
{"b_multiple", 25}};
Aquarium ecosystem(windowWidth, windowHeight, delay, startingNbPets, animalsDistribution);
ecosystem.run();
......
......@@ -163,6 +163,9 @@ void Animal::onCollision(){
}
}
double Animal::getSpeed(){
return speed;
}
int Animal::getLife() const {
return life;
......@@ -200,14 +203,17 @@ void Animal::setCumul(double new_cumul_x,double new_cumul_y){
std::tuple<double, double> Animal::getOrientationSpeed(){
return std::make_tuple(this->orientation,this->speed);
return std::make_tuple(this->orientation,this->getSpeed());
}
void Animal::setOrientationSpeed(double new_orientation,double new_speed){
this->orientation = new_orientation;
this->speed = new_speed;
}
vector<string> Animal::getAccessoriesAndCaptors(){
vector<string> names;
return names;
}
BehaviourStrategy* choose_behaviour() {
BehaviourStrategy* behaviour;
......
......@@ -59,6 +59,7 @@ public :
void setCumul(double new_cumul_x, double new_cumul_y);
tuple<double, double> getOrientationSpeed();
void setOrientationSpeed(double new_orientation, double new_speed);
double getSpeed();
float getVisibility();
double getMaxSpeed();
vector<string> getAccessoriesAndCaptors();
......
//
// Created by Rafinesque on 12/03/2021.
//
#include "BaseDecorator.h"
BaseDecorator::BaseDecorator(Animal& a): wrapAnimal(a){};
//
// Created by Rafinesque on 12/03/2021.
//
#ifndef _BASEDECORATOR_H_
#define _BASEDECORATOR_H_
#include "Animal.h"
/*
* Base of all the decorator Animals are going to be composed by 0,one or several decorators that inherit this class
*/
class BaseDecorator: public Animal {
protected:
Animal& wrapAnimal; // Give access to the decorated object
public:
BaseDecorator(Animal& a);
};
#endif
//
// Created by Rafinesque on 19/03/2021.
//
#include "Ears.h"
#include "stdlib.h"
#include "cmath"
#include "memory"
std::string Ears::NAME = "c_Ears";
Ears::Ears(Animal& animal): Sensor(animal) {}
Ears::~Ears() {}
\ No newline at end of file
//
// Created by Rafinesque on 19/03/2021.
//
#ifndef _EARS_H_
#define _EARS_H_
#include "Sensor.h"
/*
* Ears is a concrete decorator that gives the capacity of decorated object to detect object in the environment
*/
class Ears: public Sensor {
static string NAME;
public:
Ears(Animal& animal); // Constructor that decorate the object in parameter
~Ears();
};
#endif
#include "Eyes.h"
Eyes::Eyes(Animal& a): Animal(a) {};
std::string Eyes::NAME = "a_Eyes";
Eyes::Eyes(Animal& a): Sensor(a) {};
#include "Animal.h"
#include "Sensor.h"
class Eyes: public Animal {
class Eyes: public Sensor {
static string NAME;
public:
Eyes(Animal& a);
static const string getName() {return "name";};
vector<string> getAccessoriesAndCaptors();
};
//
// Created by Rafinesque on 12/03/2021.
//
#include "Fin.h"
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <cstring>
Fin::Fin(Animal& a): Animal(a) {};
std::string Fin::NAME = "a_Fin";
Fin::Fin(Animal& a): BaseDecorator(a), speed(a.getSpeed() * (double)rand()/RAND_MAX * MAX_SPEED + 1){};
double Fin::getSpeed() const{
return speed;
}
void Fin::setSpeed(double speedDeco) {
this->speed = speedDeco;
}
vector<string> Fin::getAccessoriesAndCaptors() {
vector<string> names = wrapAnimal.getAccessoriesAndCaptors();
names.push_back(NAME);
return names;
}
Fin::~Fin(){}
#include "Animal.h"
//
// Created by Rafinesque on 12/03/2021.
//
#ifndef _FIN_H_
#define _FIN_H_
#include "BaseDecorator.h"
/*
* Fin is a concrete decorator that modify the speed of the decorated object
*/
class Fin : public BaseDecorator{
protected:
double speed; // Coefficient that modify the speed of the decorated object
static string NAME;
class Fin : public Animal{
public:
Fin(Animal& a);
static const string getName() {return "name";};
~Fin(); // Destructor
double getSpeed() const;
void setSpeed(double speedDeco);
vector<string> getAccessoriesAndCaptors();
};
#endif
//
// Created by Rafinesque on 20/03/2021.
//
#include "Sensor.h"
Sensor::Sensor(Animal& a): BaseDecorator(a),
capacityOfDetection((double)rand() / (double)RAND_MAX),
minimumDistanceOfPerception(0.),
maximumDistanceOfPerception((double)rand() / (double)RAND_MAX * LIMIT_VIEW + 1) {}
double Sensor::getCapacityOfDetection() const {
return capacityOfDetection;
}
double Sensor::getMaximumDistanceOfPerception() const {
return maximumDistanceOfPerception;
}
double Sensor::getMinimumDistanceOfPerception() const {
return minimumDistanceOfPerception;
}
void Sensor::setCapacityOfDetection(double capacityOfDetection) {
this->capacityOfDetection = capacityOfDetection;
}
void Sensor::setMaximumDistanceOfPerception(double maximumDistanceOfPerception) {
this->maximumDistanceOfPerception = maximumDistanceOfPerception;
}
void Sensor::setMinimumDistanceOfPerception(double minimumDistanceOfPerception) {
this->maximumDistanceOfPerception = minimumDistanceOfPerception;
}
//
// Created by Rafinesque on 19/03/2021.
//
#ifndef _SENSOR_H_
#define _SENSOR_H_
#include "BaseDecorator.h"
/*
* Ears and Eyes are going to heritate from this class there common inherit and method
*/
class Sensor: public BaseDecorator {
protected:
double capacityOfDetection; // Coefficient to use to determine if the object is detectable by the current object
double minimumDistanceOfPerception; // Minimum distance for the object to know there is an object close to him
double maximumDistanceOfPerception; // Maximum distance for the current object to know there is an object close to him
public:
Sensor(Animal& a);
double getCapacityOfDetection() const;
void setCapacityOfDetection(double capacityOfDetection);
double getMinimumDistanceOfPerception() const;
void setMinimumDistanceOfPerception(double minimumDistanceOfPerception);
double getMaximumDistanceOfPerception() const;
void setMaximumDistanceOfPerception(double MaximumDistanceOfPerception);
};
#endif
\ No newline at end of file
//
// Created by Rafinesque on 22/03/2021.
//
#include "Shell.h"
#include "stdlib.h"
std::string Shell::NAME = "a_Shell";
// Create the decorator with the decorated object as attribut, the speedCoef and the armor
Shell::Shell(Animal& a): BaseDecorator(a), probabilityOfFatalCollision(a.getProbabilityOfFatalCollision()/((double)rand()/RAND_MAX*2+1)), speed(a.getSpeed()*probabilityOfFatalCollision) {};
Shell::~Shell(){}
double Shell::getProbabilityOfFatalCollision() const {
return probabilityOfFatalCollision;
}
void Shell::setProbabilityOfFatalCollision(double armor){
this->probabilityOfFatalCollision = probabilityOfFatalCollision;
}
double Shell::getSpeed() const{
return speed;
}
void Shell::setSpeed(double speedDeco) {
this->speed = speedDeco;
}
//
// Created by Rafinesque on 22/03/2021.
//
#ifndef CPP_ECOSYSTEM_PROJECT_SHELL_H
#define CPP_ECOSYSTEM_PROJECT_SHELL_H
#include "BaseDecorator.h"
class Shell: public BaseDecorator {
protected:
double probabilityOfFatalCollision; // Probability of death of the decorated object when there is a collision
double speed;
static string NAME;
public:
Shell(Animal& animal);
~Shell(); // Destructor
double getProbabilityOfFatalCollision() const;
double getSpeed() const;
void setSpeed(double speedDeco);
void setProbabilityOfFatalCollision(double probabilityOfFatalCollision);
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment