use of math.Vector2d in project SimpleAsteroids by ljialin.
the class FeatureView method paintComponent.
public void paintComponent(Graphics og) {
Graphics2D g = (Graphics2D) og;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
// in order to get a good q-learning agent ...
if (state == null)
return;
SimpleShip ship1 = state.ships[0];
SimpleShip ship2 = state.ships[1];
AgentCentric ac = new AgentCentric(ship1.s, ship1.d);
Vector2d s1 = ac.transform(ship1.s);
g.translate(getWidth() / 2, getHeight() / 2);
SimpleShip ship = new SimpleShip(s1, new Vector2d(0, 0), new Vector2d(0, -1));
g.setColor(Color.blue);
ship.draw(g);
Vector2d s2 = ac.transform(ship2.s);
// just put a dot there
g.setColor(Color.green);
int r = 10;
g.fillOval((int) s2.x - r, (int) s2.y - r, 2 * r, 2 * r);
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class AsteroidsGameState method makeShip.
public void makeShip() {
Ship ship = new Ship(this, new Vector2d(width / 2, height / 2), new Vector2d(), new Vector2d(0, -1));
forwardModel.setShip(ship);
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class ForwardModel method makeSafe.
public void makeSafe(AsteroidsGameState gameState) {
for (Asteroid asteroid : asteroids) {
while (ship.s.dist(asteroid.s) < safeDistance) {
Vector2d s = new Vector2d(rand.nextDouble() * width, rand.nextDouble() * height);
asteroid.s = s;
}
}
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class FeatureView method main.
public static void main(String[] args) throws Exception {
SimpleBattleState state = new SimpleBattleState();
FeatureView fv = new FeatureView().setBattleState(state);
new JEasyFrame(fv, "Feature view");
while (true) {
Thread.sleep(50);
asteroids.Action action = new Action(0, 1, false);
state.ships[0].update(action);
AgentCentric ac = new AgentCentric(state.ships[0].s, state.ships[0].d);
Vector2d tmp = ac.transform(state.ships[1].s);
int r = (int) tmp.mag();
int theta = (int) (180 * tmp.theta() / Math.PI);
System.out.println(r + "\t " + theta);
fv.repaint();
}
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class VoronoiGrid method setRandomPoints.
public VoronoiGrid setRandomPoints(int n) {
this.nPoints = n;
colors = new ArrayList<>();
for (int i = 0; i < n; i++) {
Vector2d p1 = randomPoint();
points.add(p1);
points.add(reflectionXY(p1));
Color color = randColor();
colors.add(color);
colors.add(color);
}
return this;
}
Aggregations