swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Entry level Java -- port of simpleObjCBug


From: Tim Howe
Subject: Re: Entry level Java -- port of simpleObjCBug
Date: Wed, 17 Oct 2001 13:45:05 -0700

Greetings,

Appended is a port of simpleObjCBug (with a makefile). I also have a ports
of some of the others, which I can provide to anyone who would like them.

- Tim



SimpleJBug.java:
--------
import swarm.Globals;

class SimpleJBug
{

static public void main (String[] args)
{
 int worldXSize = 80;
 int worldYSize = 80;

 int xPos = 40;
 int yPos = 40;

 int i;

    Globals.env.initSwarm ("SimpleJBug", "0", "address@hidden", args);

 Bug aBug = new Bug ();  // Make us aBug please!
     // and initialize it
 aBug.setX$Y (xPos, yPos);
 aBug.setWorldSizeX$Y (worldXSize, worldYSize);

 for(i = 0; i < 100; i++)
  aBug.step ();    // Tell it to act

System.out.println ("Todo: why do the 2 random calls return the same result
...");
System.out.println ("... so x == y always?");

}
}
--------
Bug.java:
--------
import swarm.Globals;

class Bug
{

private int _xPos;
private int _yPos;
private int _worldXSize;
private int _worldYSize;

void setX$Y (int x, int y)
{
 _xPos = x;
 _yPos = y;
 System.out.println ("I started at X = " + _xPos + " Y = " + _xPos);
}

void setWorldSizeX$Y (int xSize, int ySize)
{
 _worldXSize = xSize;
 _worldYSize = ySize;
}

void step ()
{
 _xPos += Globals.env.uniformIntRand.getIntegerWithMin$withMax (-1, 1);
 _yPos += Globals.env.uniformIntRand.getIntegerWithMin$withMax (-1, 1);

 _xPos = (_xPos + _worldXSize) % _worldXSize;
 _yPos = (_yPos + _worldYSize) % _worldYSize;

 System.out.println ("I moved to X = " + _xPos + " Y = " + _xPos);
}

}
--------
makefile:
--------
JAVA_CLASS = \
Bug.class \
SimpleJBug.class
# Javac "makes" only the immediate references of a file that is javac'd, so
# without relying on knowledge of the dependencies within the .java files,
we
# have to compile them all explicitly to be sure of compiling properly.



# The default target is to run the program. Running the program from the
# makefile ensures that we never run obsolete code unwittingly:
run : executable runcurrent

runcurrent :
 $(SWARMHOME)/bin/javaswarm SimpleJBug

executable : $(JAVA_CLASS)

clean :
 rm -f *.class

.SUFFIXES: .java-ifdef .java .class .applet .applic

# Setup-free applic from .java, for versions of make that do support
# empty target suffixes:
.java :
 make $*.class
 java $*

# Setup-free applic from .class, for versions of make that do support
# empty target suffixes:
.class :
 java $*

# Setup-free applet from .java, for versions of make that do not support
# empty target suffixes:
.java.applet :
 make $*.class
 appletviewer $*.java

# Setup-free applic from .java, for versions of make that do not support
# empty target suffixes:
.java.applic :
 make $*.class
 java $*

# Setup-free .class from .java:
.java.class :
 $(SWARMHOME)/bin/javacswarm $<
--------



----- Original Message -----
From: "Marcus G. Daniels" <address@hidden>
To: <address@hidden>
Sent: Wednesday, October 17, 2001 1:20 PM
Subject: Re: Entry level Java


> >>>>> "CM" == Methot, Chris <address@hidden> writes:
>
> CM> As a novice I hit on Swarm and decided to use Java because
> CM> of its insistence on correct programming technique (garbage
> CM> collection and logic checking).  I am just completing my first
> CM> Java course (I can flash and scroll text with the best of them).
>
> Java doesn't have much to say about correct programming technique.
> Take a look at http://www.haskell.org for a language that does.
>
> CM> I tried the SDG csss tutorial sample but the tar file has no Make
> CM> file, many unneeded Java files and I am not able to get it to
> CM> compile.
>
> This will do it:
>
>   javacswarm *.java agent2d/*.java
>   javaswarm ObserverSwarm
>
> CM> 2 Questions: Has there been any additional simple self-teaching
> CM> progressive Java examples added since January of 2000?
>
> Not really.
>
> CM> Would it be possible (with some guidance) to port Hello_world or
> CM> simpleCBug (ultimately ending up with the examples I need) or perhaps
> CM> they are designed to teach Objective C++ Swarm and have lots of
> CM> extraneous stuff not needed in Java Swarm?
>
> Sure, people experiment with porting the simple bug / tutorial series,
> but I don't think anything has really been published.  It's not like
> there is anything magical about those models.  It could be any
> relatively simple model.  Maybe doing something new would be more
> motivating, or maybe not.
>
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
>
>

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]