@@ -24,10 +24,10 @@ public class RandomBot implements Bot{
24
24
private final Course course ;
25
25
private Random rand ;
26
26
double MAXFORCE = 100.0 ;
27
- int numGuesses = 10 ;
27
+ int numGuesses = 2 ;
28
28
double forceX = 0 ;
29
29
double forceY = 0 ;
30
-
30
+ int counter = 0 ;
31
31
32
32
/**
33
33
* Create a new RandomBot instance
@@ -53,17 +53,18 @@ private double GetRandomForce(double maximum){
53
53
54
54
/**
55
55
* generates random options and searches for the best out of 10 guesses
56
- * @param best the Best choice sofar
56
+ * @param goal the Best choice sofar
57
57
*/
58
58
59
- private double GetBestRandomChoice (double best ) {
59
+ private double GetBestRandomChoice (double goal ) {
60
60
double closest = Double .POSITIVE_INFINITY ;
61
61
double choice ;
62
62
for (int i = 0 ; i < numGuesses ; i ++){
63
63
choice = this .rand .nextDouble () * MAXFORCE ;
64
64
65
- // choice closer than best
66
- if (Math .abs (choice - best ) < Math .abs (closest - best )) closest = choice ;
65
+ // choice closer than goal
66
+ if (Math .abs (choice - goal ) < Math .abs (closest - goal ))
67
+ closest = choice ;
67
68
}
68
69
System .out .println (closest );
69
70
return closest ;
@@ -72,16 +73,19 @@ private double GetBestRandomChoice(double best) {
72
73
73
74
@ Override
74
75
public void makeMove () {
76
+
75
77
double [] goal = this .course .getGoal ();
76
78
System .out .println (Arrays .toString (goal ));
77
79
forceX = GetBestRandomChoice (goal [0 ]);
78
80
forceY = GetBestRandomChoice (goal [1 ]);
79
81
while (!checkPath ()){
80
82
forceX = GetBestRandomChoice (goal [0 ]);
81
- System .out .println (forceX );
83
+ // System.out.println(forceX);
82
84
forceY = GetBestRandomChoice (goal [1 ]);
83
85
}
84
- this .engine .hit (forceX , forceY );
86
+ this .engine .hit (forceX , -forceY );
87
+ counter += 1 ;
88
+ System .out .print (counter );
85
89
}
86
90
87
91
private boolean checkPath (){
0 commit comments