Package net.javlov.world.grid

Source Code of net.javlov.world.grid.GridAgentBody

/*
* Javlov - a Java toolkit for reinforcement learning with multi-agent support.
*
* Copyright (c) 2009 Matthijs Snel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package net.javlov.world.grid;

import java.awt.Shape;

import net.javlov.Agent;
import net.javlov.State;
import net.javlov.VectorState;
import net.javlov.world.BasicAgentBody;

public class GridAgentBody extends BasicAgentBody {

  protected VectorState[][] gridStates;
 
  public GridAgentBody() {}
 
  public GridAgentBody(Shape figure) {
    super(figure);
  }
 
  @Override
  public State<double[]> getObservation(Agent agent) {
    State<double[]> st = super.getObservation(agent);
    //rubbish
    if ( gridStates != null ) {
      double[] pos = st.getData();
      if ( pos.length != 2 )
        throw new IllegalStateException("Preloading states only works with GridGPSSensor");
      return gridStates[(int)pos[0]][(int)pos[1]];
    }
    return st;
  }
 
  public void preLoadStates(int width, int height) {
    gridStates = new VectorState[width][height];
    for ( int i = 0; i < width; i++ )
      for ( int j = 0; j < height; j++ )
        gridStates[i][j] = new VectorState(new double[]{i, j});
  }
}
TOP

Related Classes of net.javlov.world.grid.GridAgentBody

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.