Skip to content

Commit c4f3cfe

Browse files
authored
Merge pull request #85 from jCodingStuff/kim
RandomBot works nicely now
2 parents 60cce90 + 452defa commit c4f3cfe

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

core/src/com/group/golf/ai/RandomBot.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public class RandomBot implements Bot{
2424
private final Course course;
2525
private Random rand;
2626
double MAXFORCE = 100.0;
27-
int numGuesses = 10;
27+
int numGuesses = 2;
2828
double forceX = 0;
2929
double forceY = 0;
30-
30+
int counter = 0;
3131

3232
/**
3333
* Create a new RandomBot instance
@@ -53,17 +53,18 @@ private double GetRandomForce(double maximum){
5353

5454
/**
5555
* 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
5757
*/
5858

59-
private double GetBestRandomChoice(double best) {
59+
private double GetBestRandomChoice(double goal) {
6060
double closest = Double.POSITIVE_INFINITY;
6161
double choice;
6262
for (int i = 0; i < numGuesses; i++){
6363
choice = this.rand.nextDouble() * MAXFORCE;
6464

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;
6768
}
6869
System.out.println(closest);
6970
return closest;
@@ -72,16 +73,19 @@ private double GetBestRandomChoice(double best) {
7273

7374
@Override
7475
public void makeMove() {
76+
7577
double[] goal = this.course.getGoal();
7678
System.out.println(Arrays.toString(goal));
7779
forceX = GetBestRandomChoice(goal[0]);
7880
forceY = GetBestRandomChoice(goal[1]);
7981
while(!checkPath()){
8082
forceX = GetBestRandomChoice(goal[0]);
81-
System.out.println(forceX);
83+
//System.out.println(forceX);
8284
forceY = GetBestRandomChoice(goal[1]);
8385
}
84-
this.engine.hit(forceX, forceY);
86+
this.engine.hit(forceX, -forceY);
87+
counter += 1;
88+
System.out.print(counter);
8589
}
8690

8791
private boolean checkPath(){

0 commit comments

Comments
 (0)