-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.hpp
168 lines (129 loc) · 4.33 KB
/
functions.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <vector>
#include <ostream>
#include <string>
#include <iostream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <climits>
#include <numeric>
using namespace std;
/**
* Converts coordinates from 1-dimensional to n-dimension.
*
* @param dimensions : Number of simulated dimensions
* @param structureSize : Length of cube edge
* @param flatCoordinate : 1-dimensional coordinate
*/
std::vector<int> inflateCoordinates (const int dimensions, const int structureSize,
const long long flatCoordinate );
/**
* Converts from inflated coordinate to 1-dimension
*
* @param coords : Vector of coordinates to be converted
* @param dimensions : Number of simulated dimensions
* @param structureSize : Length of cube edge
*/
long long flattenCoordinate (const std::vector<int>& coords, const int dimensions,
const int structureSize);
/**
* Generates a list of relative movement locations given
* the simulated dimension.
*
* @param dimensions : Number of simulated dimensions
* @param structureSize : Length of cube edge
*/
std::vector<long long> generateRules(const int dimensions, const int structureSize);
/**
* Checks to see if a new location is out of bounds relative
* to the current location.
*
* @param dimension : Number of simulated dimensions
* @param structureSize : Length of cube edge
* @param old_location : Current location as flattened coordinates
* @param new_location : Target location
*/
bool checkBoundaries (const int dimension, const int structureSize,
const long long old_location, const long long new_location);
/**
* Spawns a 1-dimensional representation of the n-dimension cube world
*
* @param dimension : Number of simulated dimensions
* @param structureSize : Length of cube edge
*/
std::vector<int> spawnLattice (const int dimension, const int structureSize);
/**
* Checks whether the current location is a valid extension of the
* seed radius.
*
* @param dimension : Number of simulated dimensions
* @param localOrigin : Half the length of cube edge
* @param currentRadius : Length of main starting seed from origin
* @param structureSize : Length of cube edge
* @param inflatedCoords : Current location as a vector of
inflated coordinates.
*/
int validateRadius (const int dimension, const int localOrigin, const int currentRadius,
const int structureSize, const std::vector<int> inflatedCoords);
/**
* Contains all of the relevant information and information
* for traversal and storage of the floating objects.
*
* @param location : Current location as flattened coordinates
* @param newLocation : Location of requested move
as flattened coordinates
* @param isSeed : Boolean flag determining whether this object
is connected to the starter seed.
* @param falseSeed : Boolean flag determining whether this object
is stuck from encountering another object.
* @param iterations : Number of movement requests since initialization
*/
class Floater {
public:
long long location;
long long newLocation;
bool isSeed;
bool falseSeed;
int iterations;
/**
* Calculates a new move and checks for collision with Floater
* or seed objects.
*
* @param inputLattice : 1-dimensional representation of the cube.
* @param rules : Vector of relative movement rules.
* @param chance : Percentage chance to stick to adjacent seeds.
*/
void requestMove(const std::vector<int>& inputLattice,
const std::vector<long long>& rules, const int chance);
/**
* Sets or resets a Floater object to the starting state.
*
* @param currentRadius : Length of main starting seed from origin
* @param dimensionValue : Number of simulated dimensions
* @param structureSizeValue : Length of cube edge
*/
void init(const int currentRadius, const int dimensionValue,
const int structureSizeValue);
private:
int structureSize;
int dimension;
/**
* Returns the current location as a flattened coordinate.
*/
long long getLocation();
/**
* Attempts to spawn at a random location outside of the
* current radius from the origin.
*
* @param radius : Length of main starting seed from origin
*/
long long spawn(const int radius);
std::vector<bool> calculateRandomDirection();
};