-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmap.cpp
100 lines (89 loc) · 1.59 KB
/
map.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <vector>
#include <array>
#include <string>
#include <cassert>
#include "food.h"
#include "blob.h"
#include "randNum.h"
#include "map.h"
Map::Map() : m_size{ 20 }
{
}
Map::Map(int size) : m_size{ size }
{
}
void Map::setMapSize(int x)
{
if (x >= 2)
{
m_size = x;
}
else
{
std::cout << "Map size must be at least 2 to create a grid for simulation";
m_size = 2;
}
}
int Map::getMapSize()
{
return m_size;
}
std::vector<Food> Map::populateFood(int amount)
{
std::vector<Food> foodArray;
for (int i{ 0 }; i < amount; ++i)
{
int x{ getRandomNumber(1,m_size) };
int y{ getRandomNumber(1,m_size) };
Food food(x, y);
foodArray.push_back(food);
}
return foodArray;
}
std::array<int, 2> Map::getEdgePosition()
{
int side{ getRandomNumber(1,4) };
std::array<int, 2> xy{ 0,0 };
switch (side)
{
case 1:
{
xy[0] = 0;
xy[1] = getRandomNumber(0, m_size + 1);
break;
}
case 2:
{
xy[0] = m_size+1;
xy[1] = getRandomNumber(0, m_size + 1);
break;
}
case 3:
{
xy[0] = getRandomNumber(0, m_size + 1);
xy[1] = 0;
break;
}
case 4:
{
xy[0] = getRandomNumber(0, m_size + 1);
xy[1] = m_size+1;
break;
}
}
return xy;
}
std::vector<Blob> Map::populateBlobs(Blob &blob, int amount)
{
std::vector<Blob> blobArray;
blob.setMapSize(m_size);
for (int i{ 0 }; i < amount; ++i)
{
std::array<int, 2> xy{ getEdgePosition() };
blob.setName(i + 1);
blob.setPosition(xy[0], xy[1]);
blob.setStepTarget(xy[0], xy[1]);
blobArray.push_back(blob);
}
return blobArray;
}