<commit_before>#include <algorithm>
#include <iostream>

#include "../../include/boids2D/BoidsManager.hpp"

BoidsManager::BoidsManager(MapGenerator& map) 
	: m_map(map), m_updateCoeff(0), m_updatePeriod(10)
{
	m_movableBoids = std::make_shared<Matrix<MovableBoidPtr> >(25, 25);
	m_rootedBoids = std::make_shared<Matrix<RootedBoidPtr> >(25, 25);
}

BoidsManager::~BoidsManager()
{

}

MovableBoidPtr BoidsManager::addMovableBoid(BoidType boidType, glm::vec3 location, glm::vec3 velocity) 
{
	MovableBoidPtr movableBoid;
	MovableParametersPtr parameters = std::make_shared<MovableParameters>(boidType);

	switch(boidType)
	{
		case WOLF:
			movableBoid = std::make_shared<MovableBoid>(location, velocity, WOLF, parameters);
			break;
		case RABBIT:
			movableBoid = std::make_shared<MovableBoid>(location, velocity, RABBIT, parameters);
			break;
		default:
			throw std::invalid_argument("valid boidType required");
			break;
	}
	unsigned int i;
	unsigned int j;
	coordToBox(location, i, j);
    m_movableBoids->add(i, j, movableBoid);
    m_movableBoidsVec.push_back(movableBoid);
    
    return movableBoid;
}

RootedBoidPtr BoidsManager::addRootedBoid(BoidType boidType, glm::vec3 location)
{
	RootedBoidPtr rootedBoid;
	switch(boidType)
	{
		case CARROT:
			rootedBoid = std::make_shared<RootedBoid>(location, CARROT);
			break;
		case TREE:
			rootedBoid = std::make_shared<RootedBoid>(location, TREE);
			break;
		default:
			throw std::invalid_argument("valid boidType required");
			break;
	}
	unsigned int i;
	unsigned int j;
	coordToBox(location, i, j);
    m_rootedBoids->add(i, j, rootedBoid);
	
	return rootedBoid;
}

const std::vector<MovableBoidPtr> & BoidsManager::getMovableBoids() const
{
	return m_movableBoidsVec;
}

const MatrixMovableBoidPtr & BoidsManager::getMovableBoidsMatrix() const
{
	return m_movableBoids;
}


const std::list<RootedBoidPtr> BoidsManager::getRootedBoids(const int & i, const int & j) const
{
	return m_rootedBoids->merge(i,j);
}

const std::vector<RootedBoidPtr> BoidsManager::getAllRootedBoids() const
{
	std::vector<RootedBoidPtr> v;
	for (unsigned int i = 0; i < m_rootedBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_rootedBoids->getNumCol(); ++j) {
			for (std::list<RootedBoidPtr>::const_iterator it = m_rootedBoids->at(i,j).begin(); it != m_rootedBoids->at(i,j).end(); ++it) {
				v.push_back( *it );
			}
		}
	}
	return v;
}

bool BoidsManager::isNight() const
{
	return isNightTime;
}

void BoidsManager::setTimeDay(bool state)
{
	isNightTime = state;
}

const std::list<MovableBoidPtr> BoidsManager::getNeighbour(const int & i, const int & j) const
{
	return m_movableBoids->merge(i,j);
}

Biome BoidsManager::getBiome(const float& x, const float& y) const
{
	return m_map.getBiome(x, y);
}
    

float BoidsManager::getHeight(const float& x, const float& y) const
{
	return m_map.getHeight(x, y);
}


MapGenerator& BoidsManager::getMap() const
{
	return m_map;
}

void BoidsManager::removeDead()
{
	std::list<MovableBoidPtr>::iterator itm;
	for (unsigned int i = 0; i < m_movableBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_movableBoids->getNumCol(); ++j) {
			itm = m_movableBoids->at(i,j).begin();
			while ( itm != m_movableBoids->at(i,j).end()) {
				if (!((*itm)->isFoodRemaining())) {
					(*itm)->disapear();
					itm = m_movableBoids->at(i,j).erase(itm);
					m_movableBoidsVec.erase(std::remove(m_movableBoidsVec.begin(), m_movableBoidsVec.end(), *itm), m_movableBoidsVec.end());
				} else {
					itm++;
				}
			}
		}
	}
	std::list<RootedBoidPtr>::iterator itr;
	for (unsigned int i = 0; i < m_rootedBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_rootedBoids->getNumCol(); ++j) {
			itr = m_rootedBoids->at(i,j).begin();
			while ( itr != m_rootedBoids->at(i,j).end()) {
				if (!((*itr)->isFoodRemaining())) {
					(*itr)->disapear();
					itr = m_rootedBoids->at(i,j).erase(itr);
				} else {
					itr++;
				}
			}
		}
	}
}

bool BoidsManager::getNearestLake(const MovableBoidPtr & boid, glm::vec2 & result) const
{
	return getNearestLake(glm::vec2(boid->getLocation().x, boid->getLocation().y), result);
}

bool BoidsManager::getNearestLake(const glm::vec2 & position, glm::vec2 & result) const
{
	return m_map.getClosestLake(position.x, position.y, result.x, result.y);<commit_msg>Fix bug about boids grid.<commit_after>#include <algorithm>
#include <iostream>

#include "../../include/boids2D/BoidsManager.hpp"

BoidsManager::BoidsManager(MapGenerator& map) 
	: m_map(map), m_updateCoeff(0), m_updatePeriod(10)
{
	m_movableBoids = std::make_shared<Matrix<MovableBoidPtr> >(25, 25);
	m_rootedBoids = std::make_shared<Matrix<RootedBoidPtr> >(25, 25);
}

BoidsManager::~BoidsManager()
{

}

MovableBoidPtr BoidsManager::addMovableBoid(BoidType boidType, glm::vec3 location, glm::vec3 velocity) 
{
	MovableBoidPtr movableBoid;
	MovableParametersPtr parameters = std::make_shared<MovableParameters>(boidType);

	switch(boidType)
	{
		case WOLF:
			movableBoid = std::make_shared<MovableBoid>(location, velocity, WOLF, parameters);
			break;
		case RABBIT:
			movableBoid = std::make_shared<MovableBoid>(location, velocity, RABBIT, parameters);
			break;
		default:
			throw std::invalid_argument("valid boidType required");
			break;
	}
	unsigned int i;
	unsigned int j;
	coordToBox(location, i, j);
    m_movableBoids->add(i, j, movableBoid);
    m_movableBoidsVec.push_back(movableBoid);
    
    return movableBoid;
}

RootedBoidPtr BoidsManager::addRootedBoid(BoidType boidType, glm::vec3 location)
{
	RootedBoidPtr rootedBoid;
	switch(boidType)
	{
		case CARROT:
			rootedBoid = std::make_shared<RootedBoid>(location, CARROT);
			break;
		case TREE:
			rootedBoid = std::make_shared<RootedBoid>(location, TREE);
			break;
		default:
			throw std::invalid_argument("valid boidType required");
			break;
	}
	unsigned int i;
	unsigned int j;
	coordToBox(location, i, j);
    m_rootedBoids->add(i, j, rootedBoid);
	
	return rootedBoid;
}

const std::vector<MovableBoidPtr> & BoidsManager::getMovableBoids() const
{
	return m_movableBoidsVec;
}

const MatrixMovableBoidPtr & BoidsManager::getMovableBoidsMatrix() const
{
	return m_movableBoids;
}


const std::list<RootedBoidPtr> BoidsManager::getRootedBoids(const int & i, const int & j) const
{
	return m_rootedBoids->merge(i,j);
}

const std::vector<RootedBoidPtr> BoidsManager::getAllRootedBoids() const
{
	std::vector<RootedBoidPtr> v;
	for (unsigned int i = 0; i < m_rootedBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_rootedBoids->getNumCol(); ++j) {
			for (std::list<RootedBoidPtr>::const_iterator it = m_rootedBoids->at(i,j).begin(); it != m_rootedBoids->at(i,j).end(); ++it) {
				v.push_back( *it );
			}
		}
	}
	return v;
}

bool BoidsManager::isNight() const
{
	return isNightTime;
}

void BoidsManager::setTimeDay(bool state)
{
	isNightTime = state;
}

const std::list<MovableBoidPtr> BoidsManager::getNeighbour(const int & i, const int & j) const
{
	return m_movableBoids->merge(i,j);
}

Biome BoidsManager::getBiome(const float& x, const float& y) const
{
	return m_map.getBiome(x, y);
}
    

float BoidsManager::getHeight(const float& x, const float& y) const
{
	return m_map.getHeight(x, y);
}


MapGenerator& BoidsManager::getMap() const
{
	return m_map;
}

void BoidsManager::removeDead()
{
	std::list<MovableBoidPtr>::iterator itm;
	for (unsigned int i = 0; i < m_movableBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_movableBoids->getNumCol(); ++j) {
			itm = m_movableBoids->at(i,j).begin();
			while ( itm != m_movableBoids->at(i,j).end()) {
				if (!((*itm)->isFoodRemaining())) {
					(*itm)->disapear();
					itm = m_movableBoids->at(i,j).erase(itm);
				} else {
					itm++;
				}
			}
		}
	}

	for (std::vector<MovableBoidPtr>::iterator i = m_movableBoidsVec.begin(); i != m_movableBoidsVec.end(); ++i)
	{
		if(!((*i)->isFoodRemaining())) {
			(*i)->disapear();
			iter_swap(i, m_movableBoidsVec.end() - 1);
			m_movableBoidsVec.pop_back();
		}
	}

	std::list<RootedBoidPtr>::iterator itr;
	for (unsigned int i = 0; i < m_rootedBoids->getNumLine(); ++i) {
		for (unsigned int j = 0; j < m_rootedBoids->getNumCol(); ++j) {
			itr = m_rootedBoids->at(i,j).begin();
			while ( itr != m_rootedBoids->at(i,j).end()) {
				if (!((*itr)->isFoodRemaining())) {
					(*itr)->disapear();
					itr = m_rootedBoids->at(i,j).erase(itr);
				} else {
					itr++;
				}
			}
		}
	}
}

bool BoidsManager::getNearestLake(const MovableBoidPtr & boid, glm::vec2 & result) const
{
	return getNearestLake(glm::vec2(boid->getLocation().x, boid->getLocation().y), result);
}

bool BoidsManager::getNearestLake(const glm::vec2 & position, glm::vec2 & result) const
{
	return m_map.getClosestLake(position.x, position.y, result.x, result.y);
{'fraction_non_alphanumeric': 0.1571117976885227, 'fraction_numerical': 0.005835907998626845, 'mean_word_length': 5.061026352288488, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1764194', 'n_tokens_mistral': 3746, 'n_tokens_neox': 3463, 'n_words': 618}