generated from europybots2024/template_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
180 lines (169 loc) Β· 8.05 KB
/
bot.py
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
169
170
171
172
173
174
175
176
177
178
179
180
# SPDX-License-Identifier: BSD-3-Clause
# flake8: noqa F401
import random
import numpy as np
from vendeeglobe import (
Checkpoint,
Heading,
Instructions,
Location,
MapProxy,
Vector,
WeatherForecast,
config,
)
from vendeeglobe.utils import distance_on_surface
from vendeeglobe import config
CREATOR = "π¦ β β πβΓπΓββ β π" # This is your team name
class Bot:
"""
This is the ship-controlling bot that will be instantiated for the competition.
"""
print(config.checkpoints[0])
print(config.checkpoints[1])
def __init__(self):
self.team = CREATOR # Mandatory attribute
self.avatar = "../../afonsos_bot/kraken.png" # Optional attribute
self.course_plus = [
(Checkpoint(latitude=43.797109, longitude=-11.264905, radius=50), False),
(Checkpoint(longitude=-29.908577, latitude=17.999811, radius=50), False),
(Checkpoint(latitude=11.639738, longitude=-52.786058, radius=10), False),
(Checkpoint(latitude=11.820852, longitude=-60.555078, radius=10), False),
(Checkpoint(latitude=11.706513, longitude=-62.714800, radius=5), True),
(Checkpoint(latitude=14.950796, longitude=-73.025302, radius=15), True),
(Checkpoint(latitude=10.184482, longitude=-79.971065, radius=5), True),
(Checkpoint(latitude=9.477217, longitude=-79.951065, radius=5), True),
(Checkpoint(latitude=9.193906, longitude=-80.009630, radius=5), True),
(Checkpoint(latitude=8.869758, longitude=-79.461705, radius=5), True),
(Checkpoint(latitude=4.202637, longitude=-78.753701, radius=5), True),
(Checkpoint(latitude=3.802786, longitude=-87.740018, radius=5), True),
(Checkpoint(latitude=3.601631, longitude=-112.727503, radius=5), False),
(Checkpoint(latitude=2.806318, longitude=-168.943864, radius=1950), False),
(Checkpoint(latitude=-5.600926, longitude=-153.607253, radius=5), False),
(Checkpoint(latitude=-14.600926, longitude=-160.607253, radius=5), False),
(Checkpoint(latitude=-16.861951, longitude=-169.998368, radius=5), False),
(Checkpoint(latitude=-20.444844, longitude=-172.330914, radius=5), False),
(Checkpoint(latitude=-41.289193, longitude=-176.327763, radius=5), False),
(Checkpoint(latitude=-44.648524, longitude=174.505348, radius=5), False),
(Checkpoint(latitude=-49.497799, longitude=169.788539, radius=10), False),
(Checkpoint(latitude=-40.079012, longitude=110.808236, radius=10), False),
(Checkpoint(latitude=-15.668984, longitude=77.674694, radius=1190), False),
(Checkpoint(latitude=-37.071050, longitude=20.809699, radius=5), False),
(Checkpoint(latitude=-15.500300, longitude=4.349726, radius=5), False),
(Checkpoint(latitude=-2.500340, longitude=-8.445598, radius=5), False),
(Checkpoint(latitude=9.593052, longitude=-22.881598, radius=5), False),
(Checkpoint(latitude=16.538295, longitude=-20.081214, radius=5), False),
(Checkpoint(latitude=43.249473, longitude=-21.292899, radius=5), False),
(Checkpoint(
latitude=config.start.latitude,
longitude=config.start.longitude,
radius=5,
), True),
]
self.course = [
Checkpoint(latitude=43.797109, longitude=-11.264905, radius=50),
Checkpoint(longitude=-29.908577, latitude=17.999811, radius=50),
Checkpoint(latitude=11.639738, longitude=-52.786058, radius=10),
Checkpoint(latitude=11.820852, longitude=-60.555078, radius=10),
Checkpoint(latitude=11.706513, longitude=-62.714800, radius=5),
Checkpoint(latitude=14.950796, longitude=-73.025302, radius=15),
Checkpoint(latitude=10.184482, longitude=-79.971065, radius=5),
Checkpoint(latitude=9.477217, longitude=-79.951065, radius=5),
Checkpoint(latitude=9.193906, longitude=-80.009630, radius=5),
Checkpoint(latitude=8.869758, longitude=-79.461705, radius=5),
Checkpoint(latitude=4.202637, longitude=-78.753701, radius=5),
Checkpoint(latitude=3.802786, longitude=-87.740018, radius=5),
Checkpoint(latitude=3.601631, longitude=-112.727503, radius=5),
Checkpoint(latitude=2.806318, longitude=-168.943864, radius=1950),
Checkpoint(latitude=-5.600926, longitude=-153.607253, radius=5),
Checkpoint(latitude=-14.600926, longitude=-160.607253, radius=5),
Checkpoint(latitude=-16.861951, longitude=-169.998368, radius=5),
Checkpoint(latitude=-20.444844, longitude=-172.330914, radius=5),
Checkpoint(latitude=-41.289193, longitude=-176.327763, radius=5),
Checkpoint(latitude=-44.648524, longitude=174.505348, radius=5),
Checkpoint(latitude=-49.497799, longitude=169.788539, radius=10),
Checkpoint(latitude=-40.079012, longitude=110.808236, radius=10),
Checkpoint(latitude=-15.668984, longitude=77.674694, radius=1190),
Checkpoint(latitude=-37.071050, longitude=20.809699, radius=5),
Checkpoint(latitude=-15.500300, longitude=4.349726, radius=5),
Checkpoint(latitude=-2.500340, longitude=-8.445598, radius=5),
Checkpoint(latitude=9.593052, longitude=-22.881598, radius=5),
Checkpoint(latitude=16.538295, longitude=-20.081214, radius=5),
Checkpoint(latitude=43.249473, longitude=-21.292899, radius=5),
Checkpoint(
latitude=config.start.latitude,
longitude=config.start.longitude,
radius=5,
),
]
def run(
self,
t: float,
dt: float,
longitude: float,
latitude: float,
heading: float,
speed: float,
vector: np.ndarray,
forecast: WeatherForecast,
world_map: MapProxy,
):
"""
This is the method that will be called at every time step to get the
instructions for the ship.
Parameters
----------
t:
The current time in hours.
dt:
The time step in hours.
longitude:
The current longitude of the ship.
latitude:
The current latitude of the ship.
heading:
The current heading of the ship.
speed:
The current speed of the ship.
vector:
The current heading of the ship, expressed as a vector.
forecast:
The weather forecast for the next 5 days.
world_map:
The map of the world: 1 for sea, 0 for land.
"""
instructions = Instructions()
for ch_plus in self.course_plus:
ch = ch_plus[0]
is_critical = ch_plus[1]
dist = distance_on_surface(
longitude1=longitude,
latitude1=latitude,
longitude2=ch.longitude,
latitude2=ch.latitude,
)
jump = dt * np.linalg.norm(speed)
if dist < 2.0 * ch.radius + jump:
instructions.sail = min(ch.radius / jump, 1)
else:
instructions.sail = 1.0
if dist < ch.radius:
ch.reached = True
if not ch.reached:
s = np.linalg.norm(speed)
if is_critical or s > 25 or np.isnan(s) or s == 0:
instructions.location = Location(
longitude=ch.longitude, latitude=ch.latitude
)
else:
x = ch.longitude + random.gauss(0, min(5/s, 4))
if x < 180:
x += 360
elif x > 180:
x -= 360
y = ch.latitude + random.gauss(0, min(5/s, 4))
instructions.location = Location(
longitude=x, latitude=y
)
break
return instructions