Skip to content

Commit 23dcd28

Browse files
committed
Added random position generator
1 parent bc30834 commit 23dcd28

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

shm/map.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
#include "map.hpp"
22

3+
#include <algorithm>
4+
#include <random>
5+
36
Map::Map() {
4-
//TODO
7+
std::vector<unsigned int> posX(maxX);
8+
std::vector<unsigned int> posY(maxY);
9+
10+
std::iota(posX.begin(), posX.end(), posX.begin());
11+
std::iota(posY.begin(), posY.end(), posY.begin());
12+
13+
std::mt19937 gen(std::random_device{}());
14+
std::shuffle(posX.begin(), posX.end(), gen);
15+
std::shuffle(posY.begin(), posY.end(), gen);
16+
17+
vecOfIslandOnMap_.reserve(initialAmountOfIsland);
18+
19+
std::transform(posX.begin(),
20+
posX.end(),
21+
posY.begin(),
22+
std::back_inserter(vecOfIslandOnMap_),
23+
[](int x, int y) {
24+
return std::make_pair(x, y);
25+
});
526
}

shm/map.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#include "island.hpp"
66

7+
constexpr int initialAmountOfIsland = 10;
8+
constexpr int maxX = 10;
9+
constexpr int maxY = 10;
10+
711
class Map {
812
private:
913
std::vector<Island> vecOfIslandOnMap_;

0 commit comments

Comments
 (0)