-
Notifications
You must be signed in to change notification settings - Fork 0
/
Environment.hpp
53 lines (39 loc) · 1.6 KB
/
Environment.hpp
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
//
// Created by Dominic Rutkowski on 2019-03-30.
//
#ifndef CS3210_COURSE_PROJECT_ENVIRONMENT_HPP
#define CS3210_COURSE_PROJECT_ENVIRONMENT_HPP
#include "Obstacle.hpp"
#include "Unit.hpp"
#include "ViableUnit.hpp"
#include <algorithm>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
namespace cs3210 {
// Use Grid as a type alias for a 2D std::vector
template <typename T>
using Grid = std::vector<std::vector<T>>;
class Environment {
private:
Grid<std::shared_ptr<Unit>> grid;
void iterateAnimals(AnimalType animalType);
bool spawnChild(const Animal& animal, const std::vector<std::shared_ptr<Unit>>& spawnLocations);
bool canMoveTo(const Animal& animal, const std::shared_ptr<Unit>& unit);
bool canConsume(const Animal& animal, const Plant& plant);
bool canConsume(const Animal& animal, const Animal& prey);
bool isPredatorOf(const Animal& animal, const std::shared_ptr<Unit>& unit);
bool canMateWith(const Animal& animal, const std::shared_ptr<Unit>& unit);
unsigned int availableEnergy(const Animal& animal, const std::shared_ptr<Unit>& unit);
std::shared_ptr<Unit> parseUnit(char ch, const std::vector<std::string>& speciesLines) const;
std::shared_ptr<Unit> getUnit(int x, int y);
public:
Environment(const std::vector<std::string>& mapLines, const std::vector<std::string>& speciesLines);
void iterate(unsigned int iterations = 1);
std::string toString() const;
};
}
#endif //CS3210_COURSE_PROJECT_ENVIRONMENT_HPP