RLPark 1.0.0
Reinforcement Learning Framework in Java

HLightSeeker.java

Go to the documentation of this file.
00001 package rlpark.plugin.critterbot.examples;
00002 
00003 import java.awt.Color;
00004 import java.util.Arrays;
00005 
00006 import rlpark.plugin.critterbot.actions.XYThetaAction;
00007 import rlpark.plugin.critterbot.colors.ColoredValue;
00008 import rlpark.plugin.critterbot.environment.CritterbotEnvironment;
00009 import rlpark.plugin.critterbot.environment.CritterbotRobot;
00010 
00011 import zephyr.plugin.core.api.synchronization.Clock;
00012 
00013 public class HLightSeeker {
00014   static final double ActionMax = 20.0;
00015   static final int lightGoal = 2;
00016   static final double alpha = 0.7;
00017 
00018   private final ColoredValue coloredValue = new ColoredValue(Color.CYAN);
00019   private double lightValue;
00020   private final CritterbotEnvironment environment;
00021 
00022   public HLightSeeker(CritterbotEnvironment environment) {
00023     this.environment = environment;
00024   }
00025 
00026   private int lightIndex(int index) {
00027     return (index + 8) % 4;
00028   }
00029 
00030   private int light(int[] lights, int index) {
00031     return lights[lightIndex(index)];
00032   }
00033 
00034   public XYThetaAction getAtp1(double[] obs) {
00035     int[] lights = environment.getCritterbotObservation(obs).light;
00036     lightValue = light(lights, lightGoal);
00037     double rotation = Math.signum(light(lights, lightGoal - 1) - light(lights, lightGoal + 1));
00038     double x = -Math.signum(light(lights, lightGoal) - light(lights, lightGoal + 2));
00039     return new XYThetaAction(x * 10, 0, rotation * 10.0);
00040   }
00041 
00042   public void setLeds(Color[] colors) {
00043     Arrays.fill(colors, coloredValue.getColor(lightValue));
00044   }
00045 
00046   public static void main(String[] args) {
00047     CritterbotEnvironment environment = new CritterbotRobot();
00048     HLightSeeker agent = new HLightSeeker(environment);
00049     Clock clock = new Clock();
00050     while (clock.tick() && !environment.isClosed())
00051       environment.sendAction(agent.getAtp1(environment.waitNewObs()));
00052   }
00053 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark