Search in sources :

Example 6 with Vector2d

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);
}
Also used : SimpleShip(battle.SimpleShip) Vector2d(math.Vector2d)

Example 7 with Vector2d

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);
}
Also used : Vector2d(math.Vector2d)

Example 8 with Vector2d

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;
        }
    }
}
Also used : Vector2d(math.Vector2d)

Example 9 with Vector2d

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();
    }
}
Also used : Action(asteroids.Action) JEasyFrame(utilities.JEasyFrame) Vector2d(math.Vector2d) SimpleBattleState(battle.SimpleBattleState) Action(asteroids.Action)

Example 10 with Vector2d

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;
}
Also used : Vector2d(math.Vector2d)

Aggregations

Vector2d (math.Vector2d)15 JEasyFrame (utilities.JEasyFrame)2 Action (asteroids.Action)1 SimpleBattleState (battle.SimpleBattleState)1 SimpleShip (battle.SimpleShip)1 Random (java.util.Random)1 ElapsedTimer (utilities.ElapsedTimer)1