@@ -467,55 +467,60 @@ impl MyStrategy {
467
467
}
468
468
return ( position, velocity) ;
469
469
}
470
-
470
+ fn gtp_action ( & self , me : & Robot , target_main : & Vec2 , action : & mut Action ) {
471
+ let target = MyStrategy :: gtp_target_validation ( * target_main, & self . rules , & me) ;
472
+ let dist = me. position ( ) . dist ( target) ;
473
+ let diff = target - me. position ( ) ;
474
+ let angle = ( diff. y ) . atan2 ( diff. x ) ;
475
+ let mut vel = ( 2.0 * ( self . rules . ROBOT_ACCELERATION ) * dist) . sqrt ( ) ;
476
+ if dist <= 0.02 {
477
+ vel = 0.0 ;
478
+ }
479
+ if vel >= self . rules . ROBOT_MAX_GROUND_SPEED {
480
+ vel = self . rules . ROBOT_MAX_GROUND_SPEED ;
481
+ }
482
+ Self :: set_robot_vel ( angle, vel, 0.0 , action) ;
483
+ }
471
484
fn god_simulation ( & mut self , _ball : Ball , _touch_point : Vec3 , _target : Vec3 , _time_availabe : f64 , _k_mode : KickMode ) -> ( bool , Vec3 , f64 , f64 , f64 , f64 ) {
472
- let mut me = self . me . clone ( ) ; //real_me_0.clone();
485
+ let mut me = self . me . clone ( ) ; // self.real_me_0.clone();
486
+ let mut ballCopy = _ball. clone ( ) ;
473
487
// let mut last_me = self.robot_hist_0[0].clone();
474
- // if self.me.id == 2 || self.me.id == 4 {
475
- // last_me = self.robot_hist_1[0].clone();
476
- // me = self.real_me_1.clone();
477
- // }
488
+ if self . me . id == 2 || self . me . id == 4 {
489
+ // last_me = self.robot_hist_1[0].clone();
490
+ me = self . real_me_1 . clone ( ) ;
491
+ }
478
492
let step_time = GLOBAL_STEP_TIME ;
479
- let mut position = me. position3 ( ) ;
480
- let mut vel = me. velocity3 ( ) ;
481
- let ball_pos = _ball. position3 ( ) ;
482
- let touch_point = _touch_point. toVec2 ( ) ;
483
493
let mut result = ( false , Vec3 :: new ( 0.0 , 0.0 , 0.0 ) , 0.0 , 0.0 , 0.0 , 0.0 ) ;
484
494
let mut found_best_sol = false ;
485
495
let mut _vir_robot_target = Vec2 :: new ( 0.0 , 0.0 ) ;
486
496
let mut jump_tick_time = 0.0 ;
487
497
let mut best_jump_speed = 0.0 ;
488
498
let mut best_speed = 0.0 ;
489
- _vir_robot_target = touch_point;
490
499
let mut waste_time = 1000.0 ;
491
500
let mut can_jump = 1000.0 ;
492
501
let mut selected_path = [ Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ; 600 ] ;
493
502
let mut vecDastan = Vec2 :: new ( 0.0 , 0.0 ) ;
494
503
let me_copy = self . me . clone ( ) ;
495
- let robottravel_time = self . travel_time_alt ( position . toVec2 ( ) , vel . toVec2 ( ) , & ( _touch_point. toVec2 ( ) ) ) ;
504
+ let robottravel_time = self . travel_time_alt ( me . position ( ) , me . velocity ( ) , & ( _touch_point. toVec2 ( ) ) ) ;
496
505
if _time_availabe - robottravel_time < step_time {
497
506
waste_time = 0.0 ;
498
507
}
499
-
508
+ let mut virtualAct = Action :: default ( ) ;
500
509
let mut can_touch_ball = false ;
501
510
for i in 0 ..( ( ( _time_availabe) * ( self . rules . TICKS_PER_SECOND as f64 ) ) as usize + 20 ) {
502
- selected_path[ i] = position;
503
- self . my_drawer . draw ( position, 0.5 , ( 1.0 , 0.0 , 0.0 ) ) ;
504
511
512
+ selected_path[ i] = me. position3 ( ) ;
513
+ self . my_drawer . draw ( me. position3 ( ) , 0.5 , ( 1.0 , 0.0 , 0.0 ) ) ;
505
514
let _time = ( i as f64 ) / ( ( self . rules . TICKS_PER_SECOND as f64 ) ) ;
506
- let mut _time_to_reach = self . travel_time_alt ( position . toVec2 ( ) , vel . toVec2 ( ) , & ( touch_point ) ) ;
515
+ let mut _time_to_reach = self . travel_time_alt ( me . position ( ) , me . velocity ( ) , & ( _touch_point . toVec2 ( ) ) ) ;
507
516
let extera_time = _time_availabe - _time_to_reach - _time;
508
517
if extera_time > step_time {
509
518
let maxSpeedDist = self . rules . ROBOT_MAX_GROUND_SPEED * self . rules . ROBOT_MAX_GROUND_SPEED / self . rules . ROBOT_ACCELERATION ;
510
- let mut altPoint = touch_point - ( Vec2 :: new ( 0.0 , 1.0 ) ) ;
511
-
512
-
519
+ let mut altPoint = _touch_point. toVec2 ( ) ; // - (Vec2::new(0.0,1.0));
513
520
if _k_mode == KickMode :: ClearDanger {
514
- altPoint = position . toVec2 ( ) ;
521
+ altPoint = me . position ( ) ;
515
522
}
516
- let stepRes = self . god_step_gp ( position, vel, altPoint, 0.0 ) ;
517
- position = stepRes. 0 ;
518
- vel = stepRes. 1 ;
523
+ self . gtp_action ( & me, & altPoint, & mut virtualAct) ;
519
524
} else {
520
525
521
526
for jSpeedFor in ( 0 ..( self . rules . ROBOT_MAX_JUMP_SPEED as i64 ) + 1 ) . rev ( ) {
@@ -535,7 +540,7 @@ impl MyStrategy {
535
540
let temp_distBeforJumpDown = ( ( j_speed/x_speed) + ( ( j_speed* j_speed) /( x_speed* x_speed) - 2.0 * ( ( self . rules . GRAVITY * ( _touch_point. h - - self . me . radius ) ) /( x_speed* x_speed) ) ) . sqrt ( ) ) / ( self . rules . GRAVITY /( x_speed* x_speed) ) ;
536
541
let jumptimeDown = temp_distBeforJumpDown/x_speed;
537
542
///// jump with maximum jump with maximum speed
538
- let effectiveSpeed = vel . toVec2 ( ) . inner_product ( & ( touch_point - position . toVec2 ( ) ) . normalize ( ) ) ;
543
+ let effectiveSpeed = me . velocity ( ) . inner_product ( & ( _touch_point . toVec2 ( ) - me . position ( ) ) . normalize ( ) ) ;
539
544
let distNeededForThisSpeed = ( x_speed* x_speed - effectiveSpeed* effectiveSpeed) /( 2.0 * self . rules . ROBOT_ACCELERATION ) ;
540
545
541
546
let temp_distBeforJumpUP = ( ( j_speed/x_speed) - ( ( j_speed* j_speed) /( x_speed* x_speed) - 2.0 * ( ( self . rules . GRAVITY * ( _touch_point. h - self . me . radius ) ) /( x_speed* x_speed) ) ) . sqrt ( ) ) / ( self . rules . GRAVITY /( x_speed* x_speed) ) ;
@@ -544,17 +549,17 @@ impl MyStrategy {
544
549
let mut temp_distBeforJump = 10000.0 ;
545
550
let mut jump_time = 10000000.0 ;
546
551
547
- if temp_distBeforJumpUP + distNeededForThisSpeed <= position . toVec2 ( ) . dist ( touch_point ) {
552
+ if temp_distBeforJumpUP + distNeededForThisSpeed <= me . position ( ) . dist ( _touch_point . toVec2 ( ) ) {
548
553
temp_distBeforJump = temp_distBeforJumpUP;
549
554
jump_time= jumptimeUP;
550
555
}
551
- else if temp_distBeforJumpDown + distNeededForThisSpeed <= position . toVec2 ( ) . dist ( touch_point ) {
556
+ else if temp_distBeforJumpDown + distNeededForThisSpeed <= me . position ( ) . dist ( _touch_point . toVec2 ( ) ) {
552
557
temp_distBeforJump = temp_distBeforJumpDown;
553
558
jump_time= jumptimeDown;
554
559
}
555
560
556
- if temp_distBeforJump + distNeededForThisSpeed <= position . toVec2 ( ) . dist ( touch_point ) {
557
- _vir_robot_target = touch_point ;
561
+ if temp_distBeforJump + distNeededForThisSpeed <= me . position ( ) . dist ( _touch_point . toVec2 ( ) ) {
562
+ _vir_robot_target = _touch_point . toVec2 ( ) ;
558
563
jump_tick_time = _time_availabe - jump_time;
559
564
best_jump_speed = j_speed;
560
565
found_best_sol = true ;
@@ -566,36 +571,32 @@ impl MyStrategy {
566
571
}
567
572
let mut _j_for_kick = 0.0 ;
568
573
569
- if _time >= jump_tick_time && ( ( vel . toVec2 ( ) . len ( ) - best_speed) . abs ( ) < step_time* self . rules . ROBOT_ACCELERATION || vel . toVec2 ( ) . len ( ) < 0.1 ) {
574
+ if _time >= jump_tick_time{ //} && ((me.velocity ().len() - best_speed).abs() < step_time*self.rules.ROBOT_ACCELERATION || me.velocity ().len() < 0.1) {
570
575
_j_for_kick = best_jump_speed;
571
576
}
572
- if jump_tick_time < step_time && ( ( me. velocity ( ) . len ( ) - best_speed) . abs ( ) < step_time* self . rules . ROBOT_ACCELERATION || vel . toVec2 ( ) . len ( ) < 0.1 ) {
577
+ if jump_tick_time < step_time && ( ( self . me . velocity ( ) . len ( ) - best_speed) . abs ( ) < step_time* self . rules . ROBOT_ACCELERATION || self . me . velocity ( ) . len ( ) < 0.1 ) {
573
578
can_jump = 0.0 ;
574
579
}
575
580
// println!("best JS {}" , _j_for_kick);
576
- let stepRes = self . god_step ( position , vel , _vir_robot_target , _j_for_kick ) ;
577
- position = stepRes . 0 ;
578
- vel = stepRes . 1 ;
581
+ let idealPath = ( _touch_point . toVec2 ( ) - me . position ( ) ) . th ( ) . deg ( ) ;
582
+ virtualAct . jump_speed = _j_for_kick ;
583
+ Self :: set_robot_vel ( idealPath , self . rules . ROBOT_MAX_GROUND_SPEED , _j_for_kick , & mut virtualAct ) ;
579
584
}
580
- let mut virtualBot = me. clone ( ) ;
581
- virtualBot. set_position ( & position) ;
582
- virtualBot. set_velocity ( & vel) ;
585
+ Simulation :: tick ( & mut me, & mut ballCopy, & virtualAct, & self . rules ) ;
583
586
584
- if position . dist ( ball_pos ) < self . me . radius + self . game . ball . radius {
587
+ if me . position3 ( ) . dist ( _ball . position3 ( ) ) < self . me . radius + self . game . ball . radius {
585
588
can_touch_ball = true ;
586
589
}
587
- if ( position . dist ( _touch_point) < self . rules . ROBOT_MAX_GROUND_SPEED * step_time* 20000.0 || _k_mode == KickMode :: ClearDanger ) && can_touch_ball == true {
590
+ if ( me . position3 ( ) . dist ( _touch_point) < self . rules . ROBOT_MAX_GROUND_SPEED * step_time* 20000.0 || _k_mode == KickMode :: ClearDanger ) && can_touch_ball == true {
588
591
// for j in 0..(((_time_availabe)*(self.rules.TICKS_PER_SECOND as f64)) as usize + 10) {
589
592
// self.my_drawer.draw(selected_path[j],0.5,(1.0,0.0,0.0));
590
593
// }
591
- self . my_drawer . drawText ( format ! ( " can _jump: {}, robot vel {} , bestVel {} , vel sim {}, height {}" , can_jump, me. velocity( ) . len( ) , best_speed, vel. toVec2( ) . len( ) , _touch_point. h) ) ;
592
594
self . my_drawer . draw ( Vec3 :: new ( vecDastan. x , vecDastan. y , 1.0 ) , 1.0 , ( 1.0 , 1.0 , 1.0 ) ) ;
593
595
594
596
result. 5 = can_jump;
595
597
result. 4 = waste_time;
596
598
result. 3 = extera_time;
597
599
result. 2 = best_jump_speed;
598
- result. 1 = Simulation :: simpleRobotBallColideStep ( & virtualBot, & _ball, best_jump_speed, & self . rules ) ;
599
600
result. 0 = true ;
600
601
break ;
601
602
}
@@ -880,7 +881,7 @@ impl MyStrategy {
880
881
////// if robot reach to the best point faster than ball
881
882
if waitForBall > GLOBAL_STEP_TIME {
882
883
let maxSpeedDist = self . rules . ROBOT_MAX_GROUND_SPEED * self . rules . ROBOT_MAX_GROUND_SPEED / self . rules . ROBOT_ACCELERATION ;
883
- touch_point = touch_point - ( Vec2 :: new ( 0.0 , 1.0 ) ) ;
884
+ // touch_point = touch_point - (Vec2::new(0.0,1.0));
884
885
if ( kMode == KickMode :: ClearDanger ) {
885
886
touch_point = self . me . position ( ) . clone ( ) ;
886
887
}
0 commit comments