int i;
for(corn = corns_group->corns, i = 1; corn < &corns_group->corns[corns_group->corns_count]; corn++, i++) {
- printf("corn no. %i coords: %s\n",
+ printf("corn no. %2i coords: %s, is %s\n",
i,
- position_to_string(&corn->position));
+ position_to_string(&corn->position),
+ (corn->is_fake?"fake":"real"));
}
}
position->y = FIRST_CORN_Y_OFFSET_M + CORNS_Y_SPACING_M * position_indexes[1];
}
+void copy_position_values(struct position * source_pos, struct position * dest_pos)
+{
+ dest_pos->x = source_pos->x;
+ dest_pos->y = source_pos->y;
+}
+
+/* ************************** COMPARISON functions *********************************** */
+
+bool positions_are_equal(struct position * pos1, struct position * pos2)
+{
+ if (pos1->x == pos2->x && pos1->y == pos2->y)
+ return true;
+ else
+ return false;
+}
+
+bool contains_group_corn_with_position(struct corns_group * group, struct position * position)
+{
+ struct corn * corn;
+ for (corn = group->corns; corn < &group->corns[group->corns_count]; corn++) {
+ if (positions_are_equal(&corn->position, position))
+ return true;
+ }
+ return false;
+}
+
/* ************************** CREATE & DISPOSE functions ************************** */
/* create dynamic array of [NUM_OF_FAKE_CORNS][POSITION_DIMENSION] and return pointer to it */
return group;
}
+struct corns_group * get_all_corns_positions(int left_right_conf, int center_conf)
+{
+ // prepare result structure
+ struct corns_group * group = malloc(sizeof(struct corns_group));
+
+ // prepare its contents
+ group->corns = malloc(NUM_OF_ALL_CORNS * sizeof(struct corn));
+ group->corns_count = NUM_OF_ALL_CORNS;
+
+ // copy fake corns into newly created structure of all corns
+ struct corns_group * fake_group = get_fake_corns_positions(left_right_conf, center_conf);
+ memcpy(group->corns, fake_group->corns, NUM_OF_FAKE_CORNS * sizeof(struct corn));
+
+ // fill in the rest of the corns
+ // get them
+ struct corn * corn;
+ for(corn = &group->corns[NUM_OF_FAKE_CORNS]; corn < &group->corns[NUM_OF_ALL_CORNS]; corn++) {
+ int i;
+ struct position some_corn_position;
+ for(i = 0; i < NUM_OF_ALL_CORNS; i++) {
+ transform_corn_indexes_into_position(all_corns[i], &some_corn_position);
+ if (!contains_group_corn_with_position(fake_group, &some_corn_position)) {
+ corn->is_fake = false;
+ copy_position_values(&some_corn_position, &corn->position);
+ }
+ }
+ }
+
+ return group;
+}
+
int main() // for testing only
{
int j, k;
for(j=0; j<9; j++) {
for(k=0; k<4; k++) {
puts("---");
- struct corns_group * corns = get_fake_corns_positions(j, k);
+ struct corns_group * corns = get_all_corns_positions(j,k);//get_fake_corns_positions(j, k);
printf("corns configuration no. %d, %d:\n", j, k);
print_corns_positions(corns);
dispose_corns_group(corns);