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

sim.app.tutorial7.Fly Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  Copyright 2006 by Sean Luke and George Mason University
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

package sim.app.tutorial7;
import sim.engine.*;
import sim.util.*;
import sim.field.grid.*;

public class Fly implements Steppable
    {
    private static final long serialVersionUID = 1;

    public void step(SimState state)
        {
        Tutorial7 tut = (Tutorial7) state;
        
        SparseGrid3D flies = tut.flies;
        
        // Move me in a random direction
        Int3D myLoc = flies.getObjectLocation(this);
        int x = flies.stx(myLoc.x + (tut.random.nextBoolean() ? 1 : -1));
        int y = flies.sty(myLoc.y + (tut.random.nextBoolean() ? 1 : -1));
        int z = flies.stz(myLoc.z + (tut.random.nextBoolean() ? 1 : -1));

        flies.setObjectLocation(this, new Int3D(x,y,z));
        
        // Update the projections with, I dunno, some function based on my position :-)
        tut.xProjection.field[y][z] += Math.log(x+2);
        tut.yProjection.field[x][z] += Math.log(y+2);
        tut.zProjection.field[x][y] += Math.log(z+2);
        }
    }
    




© 2015 - 2025 Weber Informatics LLC | Privacy Policy