Skip to content

Commit 9e1d853

Browse files
committed
changes
1 parent f5f5105 commit 9e1d853

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

core/src/com/group/golf/Physics/Physics.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public Physics(Course course, Ball ball) {
3838

3939
}
4040

41+
public Physics(Physics other) {
42+
this.course = other.course;
43+
this.ball = other.ball;
44+
this.collision = other.collision;
45+
this.offsets = other.offsets;
46+
this.scales = other.scales;
47+
this.water = other.water;
48+
}
49+
4150

4251
/**
4352
* Sets the acceleration , velocity and position
@@ -245,4 +254,8 @@ public boolean isWater() {
245254
public void setWater(boolean water) {
246255
this.water = water;
247256
}
257+
258+
public void setCollision(Collision collision) {
259+
this.collision = collision;
260+
}
248261
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class GeneticBot implements Bot {
2626

2727
private int counter = 0;
2828

29-
private static final int POPULATION_SIZE = 100;
29+
private static final int POPULATION_SIZE = 50;
3030
private static final int DNA_LENGTH = 5;
31-
private static final double MAX_FORCE = 3000;
31+
private static final double MAX_FORCE = 500;
3232

3333
private static final int GENERATION_LIMIT = 5;
3434
private static final double MUTATION_RATE = 0.01;
@@ -52,8 +52,6 @@ public GeneticBot(Course course, Ball ball) {
5252
this.virtualBall = new Ball(ball);
5353
this.virtualBall.setPosition(this.course.getStart()[0], this.course.getStart()[1]);
5454

55-
this.virtualEngine = new Physics(course, this.virtualBall);
56-
5755
this.crossOver = new AverageCrossOver(this);
5856
this.mutation = new AlterMutation();
5957
this.computer = new InverseScoreComputer();
@@ -75,12 +73,16 @@ public void makeMove() {
7573
@Override
7674
public void setPhysics(Physics physics) {
7775
this.engine = physics;
76+
this.virtualEngine = new Physics(physics);
77+
this.virtualEngine.setBall(this.virtualBall);
7878
}
7979

8080
@Override
8181
public void setCollision(Collision collision) {
8282
this.collision = collision;
8383
this.virtualCollision = new Collision(collision);
84+
this.virtualCollision.setBall(this.virtualEngine.getBall());
85+
this.virtualEngine.setCollision(this.virtualCollision);
8486
this.startEvolution();
8587
}
8688

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class botMartijn implements Bot {
2121

2222
//Constants for the method Score
2323
private static final double WATER_SCORE = 0.0; //needs adjusting by trial and error
24-
private static final double DISTANCE_SCORE = 0.0; //needs adjusting by trial and error
25-
private static final double PREVIOUS_SCORE = 0.0; //needs adjusting by trial and error
24+
private static final double DISTANCE_SCORE = 0.6; //needs adjusting by trial and error
25+
private static final double PREVIOUS_SCORE = 0.3; //needs adjusting by trial and error
2626
private static final double METHOD4 = 0.0;
2727

2828

@@ -48,19 +48,23 @@ public botMartijn(Course course, Ball ball) {
4848

4949
this.virtualBall = new Ball(ball);
5050
this.virtualBall.setPosition(this.course.getStart()[0], this.course.getStart()[1]);
51-
this.virtualEngine = new Physics(course, this.virtualBall);
5251

5352
this.maxForce = this.ball.getMass() * this.course.getVmax(); //open for adjustment
5453
}
5554

5655
@Override
5756
public void setPhysics(Physics physics) {
5857
this.engine = physics;
58+
this.virtualEngine = new Physics(physics);
59+
this.virtualEngine.setBall(this.virtualBall);
5960
}
6061

6162
@Override
6263
public void setCollision(Collision collision) {
6364
this.collision = collision;
65+
this.virtualCollision = new Collision(collision);
66+
this.virtualCollision.setBall(this.virtualEngine.getBall());
67+
this.virtualEngine.setCollision(this.virtualCollision);
6468
}
6569

6670
@Override

core/src/com/group/golf/screens/BotScreen.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import com.group.golf.Course;
1717
import com.group.golf.Golf;
1818
import com.group.golf.Physics.Physics;
19-
import com.group.golf.ai.Bot;
20-
import com.group.golf.ai.DumBot;
21-
import com.group.golf.ai.GeneticBot;
22-
import com.group.golf.ai.RandomBot;
19+
import com.group.golf.ai.*;
2320
import com.group.golf.math.Computable;
2421
import com.group.golf.math.Function;
2522

@@ -164,7 +161,7 @@ public void changed(ChangeEvent event, Actor actor) {
164161
martijn.setTouchable(Touchable.disabled);
165162
dum.setTouchable(Touchable.disabled);
166163
back.setTouchable(Touchable.disabled);
167-
Bot genBot = new GeneticBot(course, ball);
164+
Bot genBot = new botMartijn(course, ball);
168165
this.game.setScreen(new CourseScreen(this.game, this.course, this.ball, genBot));
169166
this.screen.dispose();
170167
}

0 commit comments

Comments
 (0)