@@ -24,7 +24,6 @@ pub struct MyStrategy{
24
24
rules : Rules ,
25
25
game : Game ,
26
26
action : Action ,
27
- posPID : PID
28
27
}
29
28
30
29
impl Default for MyStrategy {
@@ -35,7 +34,6 @@ impl Default for MyStrategy {
35
34
rules : Rules { ..Default :: default ( ) } ,
36
35
game : Game { ..Default :: default ( ) } ,
37
36
action : Action { ..Default :: default ( ) } ,
38
- posPID : PID :: new ( 5.0 , 0.0 , 0.0 ) ,
39
37
}
40
38
}
41
39
}
@@ -83,37 +81,71 @@ fn get_bisect(seg: &Seg2, vec: &Vec2) -> Seg2{
83
81
84
82
impl MyStrategy {
85
83
84
+ fn will_hit_the_ball ( & self ) -> bool {
85
+ let mut me = self . me . clone ( ) ;
86
+ let mut ball = self . game . ball . clone ( ) ;
87
+ let mut action = self . action ;
88
+ let r = & self . rules ;
89
+ for _ in 0 ..100 {
90
+ Self :: pure_gk ( & me, & ball, r, & mut action, true ) ;
91
+ let ( col, vel) = Simulation :: tick ( & mut me, & mut ball, & action, & self . rules ) ;
92
+ if col && vel. y > 1.0 {
93
+ println ! ( "COL: {}, {:?}" , col, vel) ;
94
+ return true
95
+ }
96
+ }
97
+ false
98
+ }
86
99
87
- fn gk ( & mut self ) {
88
- let y_goal = self . rules . arena . depth /-2.0 + 3.0 ;
89
- let ball_pos = self . game . ball . position ( ) ;
100
+ fn pure_gk ( me : & Robot , ball : & Ball , rules : & Rules , action : & mut Action , s : bool ) {
101
+ let y_goal = rules. arena . depth /-2.0 + 3.0 ;
102
+ let ball_pos = ball. position ( ) ;
90
103
let goal_line = Seg2 {
91
- origin : Vec2 { x : self . rules . arena . goal_width /2.0 , y : y_goal} ,
92
- terminal : Vec2 { x : self . rules . arena . goal_width /-2.0 , y : y_goal}
104
+ origin : Vec2 { x : rules. arena . goal_width / 2.0 , y : y_goal} ,
105
+ terminal : Vec2 { x : rules. arena . goal_width /-2.0 , y : y_goal}
93
106
} ;
94
- let ball_seg = Seg2 :: new ( self . game . ball . position ( ) , self . game . ball . velocity ( ) * 100.0 ) ;
107
+ let ball_seg = Seg2 :: new ( ball. position ( ) , ball. velocity ( ) * 100.0 ) ;
95
108
let biset = get_bisect ( & goal_line, & ball_pos) ;
96
109
let mut target = biset. terminal ( ) ;
97
- if self . game . ball . velocity ( ) . y < -1.0 { // KICK
98
- target = goal_line. intersection ( ball_seg) ;
110
+ if ball. velocity ( ) . y < -1.0 { // KICK
111
+ // if ball.position().y < -15.0 {
112
+ // target = ball.position();
113
+ // } else {
114
+ target = goal_line. intersection ( ball_seg) ;
115
+ // }
99
116
if !target. is_valid ( ) {
100
117
target = Vec2 :: new ( ball_pos. x , y_goal) ;
101
118
}
102
- } else if self . game . ball . position ( ) . y < 0.0 {
103
- target = Vec2 { x : self . game . ball . position ( ) . x , y : y_goal} ;
119
+ } else if ball. position ( ) . y < 0.0 {
120
+ target = Vec2 { x : ball. position ( ) . x , y : y_goal} ;
104
121
}
105
- if target. x < self . rules . arena . goal_width /-2.0 + 1.5 {
106
- target. x =self . rules . arena . goal_width /-2.0 + 1.5 ;
107
- } else if target. x > self . rules . arena . goal_width /2.0 - 1.5 {
108
- target. x = self . rules . arena . goal_width /2.0 - 1.5 ;
122
+ if target. x < rules. arena . goal_width /-2.0 + 1.5 {
123
+ target. x =rules. arena . goal_width /-2.0 + 1.5 ;
124
+ } else if target. x > rules. arena . goal_width /2.0 - 1.5 {
125
+ target. x = rules. arena . goal_width /2.0 - 1.5 ;
109
126
}
110
127
111
- self . gtp ( & target) ;
112
- self . action . jump_speed = 0.0 ;
113
- if ball_pos. dist ( self . me . position ( ) ) < 3.0 && self . game . ball . height ( ) > 2.5 {
114
- self . action . jump_speed = self . rules . ROBOT_MAX_JUMP_SPEED ;
128
+ Self :: gtp ( & target, me, rules, action) ;
129
+
130
+ if s {
131
+ action. jump_speed = rules. ROBOT_MAX_JUMP_SPEED ;
132
+ action. target_velocity_y = action. jump_speed ;
133
+ } else {
134
+ action. jump_speed = 0.0 ;
135
+ action. target_velocity_y = action. jump_speed ;
115
136
}
137
+ }
116
138
139
+ fn gk ( & mut self ) {
140
+ let y_goal = self . rules . arena . depth /-2.0 + 3.0 ;
141
+ if self . game . ball . position ( ) . y < self . me . position ( ) . y {
142
+ self . kick ( & Vec2 :: new ( 0.0 , -y_goal) ) ;
143
+ } else {
144
+ Self :: pure_gk ( & self . me , & self . game . ball , & self . rules , & mut self . action , false ) ;
145
+ if self . will_hit_the_ball ( ) {
146
+ self . action . jump_speed = self . rules . ROBOT_MAX_JUMP_SPEED ;
147
+ }
148
+ }
117
149
}
118
150
119
151
fn ballTouchPrediction ( & mut self ) -> Vec2 {
@@ -184,14 +216,13 @@ impl MyStrategy {
184
216
if robotvel. len ( ) > 25.0 {
185
217
jump = self . game . ball . height ( ) * 4.0 ;
186
218
}
187
- self . set_robot_vel ( idealPath* 3.1415 /180.0 , 100.0 , jump) ;
219
+ Self :: set_robot_vel ( idealPath* 3.1415 /180.0 , 100.0 , jump, & mut self . action ) ;
188
220
} else {
189
221
/////
190
222
if self . game . ball . height ( ) >= 6.0 {
191
223
let touchPrediction = self . ballTouchPrediction ( ) ;
192
224
let mut locationByPredict = touchPrediction + ( touchPrediction - * target) . normalize ( ) * ( 0.1 + self . me . radius + self . game . ball . radius + ( self . game . ball . height ( ) - self . game . ball . radius ) * 0.2 ) + ballVel * 0.05 ;
193
-
194
- self . gtp ( & locationByPredict) ;
225
+ Self :: gtp ( & locationByPredict, & self . me , & self . rules , & mut self . action ) ;
195
226
} else {
196
227
197
228
////// New prediction
@@ -233,7 +264,7 @@ impl MyStrategy {
233
264
}
234
265
235
266
236
- self . set_robot_vel ( idealPath* DEG2RAD , 100.0 , jump) ;
267
+ Self :: set_robot_vel ( idealPath* DEG2RAD , 100.0 , jump, & mut self . action ) ;
237
268
}
238
269
}
239
270
@@ -244,36 +275,34 @@ fn pm(&mut self, target: &Vec2) {
244
275
245
276
}
246
277
247
- fn gtp ( & mut self , targetMain : & Vec2 ) {
278
+ fn gtp ( targetMain : & Vec2 , me : & Robot , _rules : & Rules , action : & mut Action ) {
248
279
249
280
let mut target = * targetMain;
250
- if ( target) . y > self . rules . arena . depth / 2.0 {
251
- ( target) . y = self . rules . arena . depth / 2.0 ;
281
+ if ( target) . y > _rules . arena . depth / 2.0 {
282
+ ( target) . y = _rules . arena . depth / 2.0 ;
252
283
}
253
- if target. y < self . rules . arena . depth / -2.0 {
254
- target. y = self . rules . arena . depth / -2.0 ;
284
+ if target. y < _rules . arena . depth / -2.0 {
285
+ target. y = _rules . arena . depth / -2.0 ;
255
286
}
256
- if target. x > self . rules . arena . width / 2.0 {
257
- target. x = self . rules . arena . width / 2.0 ;
287
+ if target. x > _rules . arena . width / 2.0 {
288
+ target. x = _rules . arena . width / 2.0 ;
258
289
}
259
- if target. x < self . rules . arena . width / -2.0 {
260
- target. x = self . rules . arena . width / -2.0 ;
290
+ if target. x < _rules . arena . width / -2.0 {
291
+ target. x = _rules . arena . width / -2.0 ;
261
292
}
262
293
263
- let dist = self . me . position ( ) . dist ( target) ;
264
- let diff = target - self . me . position ( ) ;
294
+ let dist = me. position ( ) . dist ( target) ;
295
+ let diff = target - me. position ( ) ;
265
296
let angle = ( diff. y ) . atan2 ( diff. x ) ;
266
- let a = self . posPID . run ( dist) ;
267
- println ! ( "{}**{}**{}" , dist, angle, a) ;
268
- self . set_robot_vel ( angle, a , 0.0 ) ;
297
+ Self :: set_robot_vel ( angle, 5.0 * dist , 0.0 , action) ;
269
298
270
299
271
300
}
272
301
273
- fn set_robot_vel ( & mut self , angle : f64 , vel : f64 , jump : f64 ) {
274
- self . action = Action {
302
+ fn set_robot_vel ( angle : f64 , vel : f64 , jump : f64 , action : & mut Action ) {
303
+ * action = Action {
275
304
target_velocity_x : vel* angle. cos ( ) ,
276
- target_velocity_y : 0 .0,
305
+ target_velocity_y : 15 .0,
277
306
target_velocity_z : vel* angle. sin ( ) ,
278
307
jump_speed : jump,
279
308
use_nitro : false ,
0 commit comments