All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bdi.examples.hunterprey.ldahunter.potentialfield.FieldModel Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

The newest version!
/*
 * FieldModel.java
 * Copyright (c) 2004 by University of Hamburg. All Rights Reserved.
 * Departament of Informatics. 
 * Distributed Systems and Information Systems.
 *
 * Created by 9walczak on Sep 24, 2004.  
 * Last revision $Revision: 2562 $ by:
 * $Author: pokahr $ on $Date: 2005-04-26 16:31:45 +0200 (Di, 26 Apr 2005) $.
 */
package jadex.bdi.examples.hunterprey.ldahunter.potentialfield;

import jadex.extension.envsupport.math.IVector2;
import jadex.extension.envsupport.math.Vector1Double;
import jadex.extension.envsupport.math.Vector1Int;
import jadex.extension.envsupport.math.Vector2Double;
import jadex.extension.envsupport.math.Vector2Int;


/**
 *
 */
public final class FieldModel
{
	final int w;
	final int h;

	/**
	 * obstacles obstacle in field model
	 */
	public final boolean[][] obstacles;

	/**
	 * visits
	 */
	public final int[][] visits;

	final int[][] distance;

	/**
	 * Constructor: FieldModel.
	 * @param w width
	 * @param h height
	 */
	public FieldModel(int w, int h)
	{
		this.w = w;
		this.h = h;
		obstacles = new boolean[w][h];
		distance = new int[w][h];
		visits = new int[w][h];
	}

	/**
	 * @param loc the location the values should be stored to (in, out)
	 * @return false if this location has distance <= 0, true if location changed
	 */
	public final boolean getNearerLocation(final IVector2 loc)
	{
		final int ix = loc.getXAsInteger();
		final int iy = loc.getYAsInteger();
		int ox = ix;
		int oy = iy;
		double height = distance[ix][iy];
		if(height<0.0) return false;

		if(distance[(ix+1)%w][iy]d)
		{ // found new way to x, y
			distance[x][y] = d;
			reverse = goD(x, y, step);
			if(reverse+1d)
		{ // found new way to x, y
			distance[x][y] = d;
			reverse = goL(x, y, step);
			if(reverse+1d)
		{ // found new way to x, y
			distance[x][y] = d;
			reverse = goU(x, y, step);
			if(reverse+1d)
		{ // found new way to x, y
			distance[x][y] = d;
			reverse = goR(x, y, step);
			if(reverse+10;)
		{
			for(int j = h; j-->0;)
			{
				distance[i][j] = Integer.MAX_VALUE-2;
			}
		}
	}

	/**
	 * @param x
	 * @param y
	 * @param r
	 * @param round
	 */
	public void clearRange(int x, int y, int r, int round)
	{
		for(int i = x-r; i<=x+r; i++)
		{
			for(int j = y-r; j<=y+r; j++)
			{
				visits[(i+w)%w][(j+h)%h] = round;
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy