Tobis Programm forked to not destroy your golden files
Fork of Robocode by
source/Mapping.cpp@41:462d379e85c4, 2017-04-10 (annotated)
- Committer:
- cittecla
- Date:
- Mon Apr 10 14:52:23 2017 +0000
- Revision:
- 41:462d379e85c4
- Parent:
- 40:a46667b62671
- Child:
- 44:7118b23b0fd7
- Child:
- 46:8b52c7b34d34
Completed select_target function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cittecla | 12:91c2e07d2b5b | 1 | /** |
cittecla | 12:91c2e07d2b5b | 2 | * Mapping function library |
cittecla | 12:91c2e07d2b5b | 3 | * Handels Mapping of the arena and LEGO-stones |
cittecla | 12:91c2e07d2b5b | 4 | **/ |
cittecla | 12:91c2e07d2b5b | 5 | |
cittecla | 38:3526c36e4c73 | 6 | #include "Mapping.h" |
cittecla | 41:462d379e85c4 | 7 | #include "Pathfinding.h" |
cittecla | 38:3526c36e4c73 | 8 | |
cittecla | 12:91c2e07d2b5b | 9 | |
cittecla | 13:57f5a7876d2f | 10 | void mapping() |
cittecla | 13:57f5a7876d2f | 11 | { |
cittecla | 28:274e1d4ecac5 | 12 | //pseudo code |
cittecla | 41:462d379e85c4 | 13 | // check_sensor(left); |
cittecla | 41:462d379e85c4 | 14 | //check_sensor(right); |
cittecla | 28:274e1d4ecac5 | 15 | } |
cittecla | 28:274e1d4ecac5 | 16 | |
cittecla | 38:3526c36e4c73 | 17 | |
cittecla | 41:462d379e85c4 | 18 | int select_target() |
cittecla | 41:462d379e85c4 | 19 | { |
cittecla | 41:462d379e85c4 | 20 | position myPos = get_current_pos(); |
cittecla | 41:462d379e85c4 | 21 | position diff = {0}; |
cittecla | 41:462d379e85c4 | 22 | target.x = 0; |
cittecla | 41:462d379e85c4 | 23 | int closest_dist = 10000; |
cittecla | 41:462d379e85c4 | 24 | int current_dist = 0; |
cittecla | 41:462d379e85c4 | 25 | |
cittecla | 41:462d379e85c4 | 26 | for(int i = 0; i < row; i++) { |
cittecla | 41:462d379e85c4 | 27 | for(int j = 0; j < col; j++) { |
cittecla | 41:462d379e85c4 | 28 | if(obstacle_list[i][j] == 2) { |
cittecla | 41:462d379e85c4 | 29 | diff.x = abs(myPos.x - j); |
cittecla | 41:462d379e85c4 | 30 | diff.y = abs(myPos.y - i); |
cittecla | 41:462d379e85c4 | 31 | current_dist = diff.x * diff.y; |
cittecla | 41:462d379e85c4 | 32 | if(current_dist < closest_dist) { |
cittecla | 41:462d379e85c4 | 33 | closest_dist = current_dist; |
cittecla | 41:462d379e85c4 | 34 | target.x = j; |
cittecla | 41:462d379e85c4 | 35 | target.y = i; |
cittecla | 41:462d379e85c4 | 36 | } |
cittecla | 41:462d379e85c4 | 37 | } |
cittecla | 41:462d379e85c4 | 38 | } |
cittecla | 41:462d379e85c4 | 39 | } |
cittecla | 41:462d379e85c4 | 40 | if(target.x == 0) { |
cittecla | 41:462d379e85c4 | 41 | return 47; // No Target found |
cittecla | 41:462d379e85c4 | 42 | } else { |
cittecla | 41:462d379e85c4 | 43 | return 36; // Target found |
cittecla | 41:462d379e85c4 | 44 | } |
cittecla | 41:462d379e85c4 | 45 | } |
cittecla | 41:462d379e85c4 | 46 | |
cittecla | 41:462d379e85c4 | 47 | int remove_target() |
cittecla | 41:462d379e85c4 | 48 | { |
cittecla | 41:462d379e85c4 | 49 | obstacle_list[target.y][target.x] = 0; |
cittecla | 40:a46667b62671 | 50 | return 0; |
cittecla | 40:a46667b62671 | 51 | } |
cittecla | 40:a46667b62671 | 52 | |
cittecla | 41:462d379e85c4 | 53 | int switch_target_red() |
cittecla | 41:462d379e85c4 | 54 | { |
cittecla | 41:462d379e85c4 | 55 | obstacle_list[target.y][target.x] = 0; |
cittecla | 41:462d379e85c4 | 56 | return 0; |
cittecla | 40:a46667b62671 | 57 | } |
cittecla | 40:a46667b62671 | 58 | |
cittecla | 40:a46667b62671 | 59 | |
cittecla | 40:a46667b62671 | 60 | |
cittecla | 40:a46667b62671 | 61 | |
cittecla | 40:a46667b62671 | 62 | |
cittecla | 38:3526c36e4c73 | 63 | /* |
cittecla | 28:274e1d4ecac5 | 64 | void chack_sensor(sensor) |
cittecla | 28:274e1d4ecac5 | 65 | { |
cittecla | 28:274e1d4ecac5 | 66 | get_distance(); |
cittecla | 28:274e1d4ecac5 | 67 | if(sensor < 80cm || sensor > 10cm) { |
cittecla | 28:274e1d4ecac5 | 68 | calculate_position(sensor, distance); |
cittecla | 28:274e1d4ecac5 | 69 | check_map(position.this, obstacle); |
cittecla | 28:274e1d4ecac5 | 70 | if(map.no-entry){ |
cittecla | 28:274e1d4ecac5 | 71 | check_if_obstacle(distance); |
cittecla | 28:274e1d4ecac5 | 72 | update_map(); |
cittecla | 28:274e1d4ecac5 | 73 | } |
cittecla | 28:274e1d4ecac5 | 74 | } |
cittecla | 14:9e2ce5880fb0 | 75 | } |
cittecla | 28:274e1d4ecac5 | 76 | |
cittecla | 28:274e1d4ecac5 | 77 | void get_distance(sensor) |
cittecla | 28:274e1d4ecac5 | 78 | { |
cittecla | 28:274e1d4ecac5 | 79 | sensor.value; |
cittecla | 28:274e1d4ecac5 | 80 | return value; |
cittecla | 28:274e1d4ecac5 | 81 | } |
cittecla | 28:274e1d4ecac5 | 82 | |
cittecla | 28:274e1d4ecac5 | 83 | void calcualte_position(sensor, distance) |
cittecla | 28:274e1d4ecac5 | 84 | { |
cittecla | 28:274e1d4ecac5 | 85 | do math; |
cittecla | 28:274e1d4ecac5 | 86 | return position; |
cittecla | 28:274e1d4ecac5 | 87 | } |
cittecla | 28:274e1d4ecac5 | 88 | |
cittecla | 28:274e1d4ecac5 | 89 | void check_if_obstacle(distance) |
cittecla | 28:274e1d4ecac5 | 90 | { |
cittecla | 28:274e1d4ecac5 | 91 | move_scanner(); |
cittecla | 28:274e1d4ecac5 | 92 | distance2 = get_distance(sensor); |
cittecla | 28:274e1d4ecac5 | 93 | reset_scanner(); |
cittecla | 28:274e1d4ecac5 | 94 | if(distance -5cm < distance2 && distance +5cm > distance2) { |
cittecla | 28:274e1d4ecac5 | 95 | return 1; |
cittecla | 28:274e1d4ecac5 | 96 | } else { |
cittecla | 28:274e1d4ecac5 | 97 | return 0; |
cittecla | 28:274e1d4ecac5 | 98 | } |
cittecla | 29:e7d0208bf2af | 99 | }*/ |