public double queryBestState(Transition t) { double energy = t.getNextState().getOgreEnergy(); double distance = t.getNextState().getEnemyDistance(); double vAttack = FQ_learner.nearestValue(energy, distance, 0); double vEvade = FQ_learner.nearestValue(energy, distance, 1); if (vAttack > vEvade) return vAttack; else return vEvade; }
protected void paintComponent(Graphics g) { super.paintComponent(g); g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double energy, distance, scaledVal; int horizSize = 100; int index = 0; float v; int boxsize = 5; for (int y = 0; y < horizSize; y++) { for (int x = 0; x < horizSize; x++) { energy = (double) x / (double) horizSize; // x axis is my // energy distance = (double) y / (double) horizSize; // y axis is the // distance scaledVal = (10.0 + FQ_learner.nearestValue(energy, distance, action)) / 20.0; v = (float) scaledVal; if (v < 0) v = 0; // System.out.println(v); g2.setPaint(new Color(v, v, v, 1)); g2.fill(new Rectangle2D.Double(x * boxsize, y * boxsize, boxsize, boxsize)); index++; } } // System.out.println("painted"); }
public int getBestAction(OgreState state) { double energy = state.getOgreEnergy(); double distance = state.getEnemyDistance(); double action0 = FQ_learner.nearestValue(energy, distance, 0); double action1 = FQ_learner.nearestValue(energy, distance, 1); // state.print(); // System.out.println("act0:"+action0); // System.out.println("act1:"+action1); if (action0 > action1) { return 0; } else { return 1; } }