The data representation was an important part of our code and our project.
Why?
directly affects how efficiently, accurately, and meaningfully information can be processed.
preserves accuracy and prevents misinterpretation.
maximize efficiency in terms of memory usage, Interpretability (easy to understand), debugging, communication among routines, even among members.
allow future scalability and flexibility
ease of sharing between alliances and teammates.
How?
Our data representation is shown below and linked here.
#define NUM_PLOTS 3
struct Point {
float x;
float y;
float z;
};
enum eCrops {
unknown,
tomato,
cabbage,
strawberry,
melon
};
struct Plot {
int id;
Point coords;
eCrops curCrop; // crop id
float timeOfSecondWatering; // helps to know when to harvest
};
Plot plots[NUM_PLOTS];
int growthTime[melon + 1]; // four growth times for the crops
eCrops bonusCropID; // bonus crop from astronaut
// ----------------satellite specific below---------
enum Satellite {
red,
blue
};
void initPlots(Satellite id) {
switch (id) {
case red: //This gives a warning, use x, y, z individually to satisfy c compiler
plots[0].coords = { -0.35, 0.6, -0.5 };
plots[1].coords = { 0.35, 0.6, -0.5 };
plots[2].coords = { 0, 1, -0.5 };
break;
case blue:
plots[0].coords = { -0.35, 0.6, 0.5 };
plots[1].coords = { 0.35, 0.6, 0.5 };
plots[2].coords = { 0, 1, 0.5 };
break;
}
}
void initPlots(Satellite id) {
switch (id) {
case red: //This gives a warning, use x, y, z individually to satisfy c compiler
plots[0].coords.x = -0.35;
plots[0].coords.y = 0.6;
plots[0].coords.z = -0.5;
plots[1].coords.x = 0.35;
plots[1].coords.y = 0.6;
plots[1].coords.z = -0.5;
plots[2].coords.x = 0;
plots[2].coords.y = 1;
plots[2].coords.z = -0.5;
break;
case blue:
plots[0].coords.x = -0.35;
plots[0].coords.y = 0.6;
plots[0].coords.z = 0.5;
plots[1].coords.x = 0.35;
plots[1].coords.y = 0.6;
plots[1].coords.z = 0.5;
plots[2].coords.x = 0;
plots[2].coords.y = 1;
plots[2].coords.z = 0.5;
break;
}
}
/*This will allow you to toggle between red or blue simply by: Satellite satellite = blue; */
void init() {
Satellite satellite = red; /* change to blue if you want to test with blue and everything will be adjusted */
initPlots(satellite);
bonusCropID = unknown;
for (int i = 0; i < NUM_PLOTS; i++) {
plots[i].id = i + 1;
plots[i].curCrop = unknown;
plots[i].timeOfSecondWatering = 0;
}
growthTime[unknown] = 0;
growthTime[tomato] = 6;
growthTime[cabbage] = 8;
growthTime[strawberry] = 5;
growthTime[melon] = 10;
}
We associated the cropID's each of the crops' names using an enum
struct Plot organizes all information associated with a single plot, e.g. plot ID, plot coordinates, curCrop being planted, and timeofSecondWatering calculating from time of watering
The enum Satellite allows us to easily switch the code between red and blue satellites.
bonusCropID makes it easier to get and identify the bonus crop as it identifies it as you get there, initially set to an unknown value.
Easy access to growthTime of each crop