]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
corns: add function that returns all corns' position and (fake/real) information
authorFilip Jares <filipjares@post.cz>
Thu, 22 Apr 2010 21:18:10 +0000 (23:18 +0200)
committerFilip Jares <filipjares@post.cz>
Thu, 22 Apr 2010 21:40:32 +0000 (23:40 +0200)
src/robofsm/corns_configs.c
src/robofsm/corns_configs.h

index 5f285f67d3f533a26e34f60c79216d32a5974c53..4a5322e482c2b6acf7989262823f4930fc6210aa 100644 (file)
@@ -39,9 +39,10 @@ void print_corns_positions(struct corns_group * corns_group)
        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"));
        }
 }
 
@@ -76,6 +77,32 @@ void transform_corn_indexes_into_position(int * position_indexes, struct positio
        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 */
@@ -150,13 +177,44 @@ struct corns_group * get_fake_corns_positions(int left_right_conf, int center_co
        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);
index 0fb6e087e7d2e57b356e2c0339a68a609e1a7dc4..4b4fc30f0a9d538cfc75d7b4e74172539647950a 100644 (file)
@@ -36,7 +36,7 @@ struct corns_group {
 int **get_fake_corns_positions_indexes_for_configurations(int left_right_conf, int center_conf);
 void dispose_corns_positions_indexes(int **positions);
 struct corns_group * get_fake_corns_positions(int left_right_conf, int center_conf);
-struct corn_position * get_all_corns_positions();
+struct corns_group * get_all_corns_positions(int left_right_conf, int center_conf);
 void print_corns_positions(struct corns_group * corns_group);