Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Questions on HW9-Sp2005

Want to know how those villagers really did mill about in "The Hunchback of Notre Dame"? Time to figure it out!

Any Questions?



When I type this in cmd, "C:\cs>java - cp java-source;. CrowdSim" I get
Unrecognized option: -
Could not create the Java virtual machine.


I don't know – Sebastian or Jonny? I rarely use java with command options from the command line. But I do know that in UNIX, it should be "-cp" not "- cp" (note the extra space between "-" and "cp") Mark Guzdial

Mark is correct–the problem is that you put a space between the "-" and "cp". Should be "java -cp java-source;. CrowdSim" #4

I've been asked whether you should have different villager types, or should they all look the same. There is no requirement to have different types, but I'll offer up to 10 points extra credit for having three or more types (e.g., maybe 5 points for two types.) ! Mark Guzdial

How big should the world be?
Your call. Mark Guzdial

are we supposed to draw the villagers like how you drew the birds?
Again, your call – be creative. Yes, you can draw the villagers, but you can use anything in the MediaSources (waving Ken's and Wolverine's) or anything else you can find. Mark Guzdial

is gifs not allowed? i tried using a gif picture and nothing shows up.
No, only JPEGs are guaranteed to work with our Picture class. Some GIFs sometimes do work, but I can't figure out the rhyme or reason of it. Mark Guzdial

in the command prompt i keep getting "Exception in thread "main" java.lang.NoClassDefFoundError : my class" what does that mean?

What's the name of your class? Do you have a main() in it? Try running it from inside DrJava with F2 key ("Run Document's Main Method" under Tools menu). That error may be clearer to you. Mark Guzdial
Also, make sure that you're in your cs 1316 directory. In my case, I have Mark's latest stuff in c:\cs1316\java-source, and my personal code in c:\cs1316. In order to run my program from the command line, I first do a "cd \cs1316", which puts me in the c:\cs1316 folder. From there I can do a "java -cp java-source;. MyProgramName", which tells java to look both in the current directory (c:\cs1316) and in the java source directory (c:\cs1316\java-source). If this doesn't help you out, feel free to come to my office hours Friday from 12-1 or email me with specific details and we can get you up and running. #4


do the villagers have to be humans?

Nope. No requirement Mark Guzdial

eek - I get this simple error when trying to compile my VillagerAgent class:
 File: C:\CS1316\mark-java-source-v2\VillagerAgent.java  [line: 54]
Error: incompatible types
found   : Agent
required: VillagerAgent

and it corresponds to this line of code
 public void act(int t){    
      // Tell it that this really is a VillagerSimulation
      VillagerSimulation mySim = (VillagerSimulation) simulation;
      speed = (randNumGen.nextInt(5)+1);//general speed for milling about
      this.forward(randNumGen.nextInt( 5)+1);  //they mill around 
      int neighbors = countInRange((50), simulation.getAgents());
      if (neighbors==0){
        VillagerAgent closestperson= this.getClosest(100, mySim.getAgents());//this LINE CAUSES THE ERROR
        if (closestperson != null){
          this.turnToFace(closestperson);
          this.forward(4);
        }
      }

I'm reluctant to cast (VillagerAgent) because then I receive an error when I try to use countInRange()... Please help me see how I can make this work. Thanks =) Jamie Student48

#4: I don't see why countInRange() wouldn't work if you made the cast. But you can also just treat the closest person as an Agent (even though it really is a VillagerAgent). So you could do
        Agent closestperson= this.getClosest(100, mySim.getAgents());


Try this, Jamie. VillagerAgent closestperson= (VillagerAgent) this.getClosest(100, mySim.getAgents());//this LINE CAUSES THE ERROR
Mark Guzdial|

i unfortunatly don't understand the math behind turnToFace. what can i change to reverse it to 'turnAway?'
turnToFace, then turn(180). That turns directly towards, then exactly away. Mark Guzdial

Where can I get the EventQueue() class?
Isn't it in the .zip on the Syllabus page? Mark Guzdial

When I compile the new Simulation class, I get an error saying that it doesn't recognize the method drawOn(Picture). Where is that method, anyway? I looked in Picture, SimplePicture, Turtle and in all the SceneElement classes...
It's in World.java Mark Guzdial
Latest versions of each:
World.java
EventQueue.java

in the directions it says that the villagers

whats the difference btw changing direction of movement and changing the direction they're facing?
Look at the Birds that I drew – their faces go in different directions, even if they're not moving in those directions. We're trying to model villagers milling about and chatting, so they shift in place, and look around, and walk a bit. Mark Guzdial

i'm having trouble getting my villages to be able to respond to the NBD's positions. in the bird simulation from class the birds just ran in an opposite direction of a stationary sun/egg. this hw requires the villagers to respond to a moving bully. how can i pipe the bully's x and y position to the villager class so i can get them to move away from that position?
The Simulation creates the bully in setUp(), right? Keep an instance variable in the simulation that references the bully. Now, a villager can ask the bully's X and Y by asking for simulation.bully.getXPos() and simulation.bully.getYPos(). Also, if you check out SimpleTurtle, you'll see that turtles know their heading (getHeading()). Consider using something like the below code. Mark Guzdial
// Remember the current heading
double myHeading = getHeading();
// Now, figure out the heading to the bully
turnToFace(simulation.bully);
// Was I facing the bully?  Is my new heading the same as my old?
if (myHeading == getHeading())
{// if so, turn away
turn(180);}
else {//go back to your old heading
setHeading(myHeading);}





MY program compiles and runs, it just seems to quit randomly and gives me the following error...

java.lang.ClassCastException:
at BirdAgent.act(BirdAgent.java:50)
at Simulation.run(Simulation.java:109)

The only casting I've done so far is this:
BirdSimulation mySim = (BirdSimulation) simulation;
BirdAgent closePerson = (BirdAgent)this.getClosest(100, mySim.getAgents());

Also, right now i have the turnToFace line commented out b/c otherwise I get the same error before the first time step.

Which of these is at line 50 in BirdAgent? Did you try making the 100 into 100.0 so that it's a double and not an int? Mark Guzdial


how much do you consider a couple of steps for those villagers w/ noone around? and what's the speed of the fleeing one (fleeing from other villagers/NBD)?
It's entirely your call. Maybe 4 and 10? Make it the way you think it looks good. Mark Guzdial

what's the idfference between changing direction of movement versus changing direction they're facing?
I just answered that – read further up. Mark Guzdial

Regarding the question above about the ClassCastException, when turnToFace is not commented out i get a NullPointerException at...
SimpleTurtle.turnToFace(SimpleTurtle.java:532)
at BirdAgent.act(BirdAgent.java:54)"

I tried 100.0 instead of 100, but there was no difference. I don't really understand what this error means in term of my code.

I managed to resolve the question from above. On a different note, can we use different numbers for our variables than the ones listed in the HW description. With my pictures it's hard to see whats going on on such a small scale. Thank you-

Yes, it's okay to use different numbers. Mark Guzdial


my facing different directions isn't really noticable when you run it since my villagers are relatively symmetrical, but as long as it works and it's in the code, that's ok?
Yep. Mark Guzdial

java.lang.ClassCastException:
at VillageAgent.act(VillageAgent.java:50)
at Simulation.run(Simulation.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
Uh, thank you for sharing? What does line 50 look like? Mark Guzdial

trying to make a linked list in my nbd agent java so i can find when it's close to the villagers, but i keep getting this as an error twice:
File: C:\Documents and Settings\Owner\My Documents\School\1.2\CS1316\java-source\NBDAgent.java [line: 9]
Error: cannot resolve symbol
symbol : class REMOVEDkedList
location: class NBDAgent
Did you import java.util.REMOVEDkedList ? Mark Guzdial

Here is the current state of my java-sources. Call it "final." mark-java-source-v3-final.zip Mark Guzdial



I just figured out why people are getting cast exceptions on searching for the closest person. You're casting it to your CrowdAgent, right? What if the closest agent is a BullyAgent? Can't cast that to CrowdAgent, right? Here's a solution: Declare public REMOVEDkedList crowd; in your simulation class, then in your setUp of your crowd crowd.add(person);. Now, instead of searching simulation.getAgents() for your find closest person, search in simulation.crowd. Mark Guzdial

I'm having trouble just getting the pictures of the villagers to show up instead of the turtles. What sorts of changes am I to be making to Mr. Guzdial's endStep(int t) method so that villagers show up instead of turtles, if that's the problem? I guess I'm a little confused on how to set up turtles that know what their pictures are, or just not making the connection between villagers and pictures and how endStep knows about both of them... whew!
Remember that Agent has a myPic instance variable. If your agent has that assigned, my code should work for you (assuming that you have a FrameSequence opened in your simulation's setUp) Mark Guzdial

crowd is declared in my simulation and when i try to use it in my agent it says it cannot resolve the symbol... how can i use it in both?
Is crowd public? If so, simulation.crowd should work from agent. If it's not public, you can make a public accessor crowd(). Mark Guzdial

this is in my VillagerAgent class:
if (t>10){
        //int myX = this.getXPos();
        //int myY = this.getYPos();
        //int greenX = mySim.greenGuy.getXPos();
        //int greenY = mySim.greenGuy.getYPos();
        if (this.getDistance(mySim.greenGuy.getXPos(), mySim.greenGuy.getYPos()) <= 50)
              {
        //if ( (greenX <=(myX+30)) && (greenX >= (myX-30))){
          //if ((greenY <=(myY+30)) && (greenY >=(myY-30))){
            // Remember the current heading
            double myHeading = getHeading();
            // Now, figure out the heading to the greenGuy
            turnToFace(mySim.greenGuy);
            // Was I facing the greenGuy?  Is my new heading the same as my old?
            if (myHeading == getHeading())
            {// if so, turn away
              turn(180);
              forward(50);
            }
            else {//go back to your old heading
              setHeading(myHeading);
              forward(speed);            
            }
         
        }
      } 

it seems to me like the villagers should turn away from and move away from my greenGuy (who is mean). when i watch my simulation, it doesn't quite "look" like the villagers are moving away. i'm kind of expecting a "parting of the red sea" effect... but would that be incorrect? please help me - have i left a base uncovered or is this working but negligible to the normal eye? "jamie" Student48
I think you've combined two rules, Jamie. If you're within 50 of the bad guy, just turn away and run. OTHERWISE, nobody walks toward the bad guy. Pull your loop out of the IF, and make the body of the IF (a) turn toward the bad guy, (b) turn 180, (c) forward(speed). Mark Guzdial

When I try to run my program, this is what is said in the interactions...

Welcome to DrJava.
> CrowdSimulation cs = new CrowdSimulation();

> cs.setUp();

There are no frames to show yet. When you add a frame it will be shown

java.lang.NullPointerException:
at CrowdAgent.(CrowdAgent.java:98)
at CrowdSimulation.setUp(CrowdSimulation.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
>

What?
Check what's at line 98 of CrowdAgent. It sounds like you are using a variable there that has no value yet. Mark Guzdial


i've learned that watching the turtles in their "world" is a little more helpful than watching my "villagers." does a turtle's position correlate to x,y position (0,0) of the villager jpg?

Yes, it's supposed to – that's what the code in endStep() ought to be doing. Mark Guzdial


I have already finished, however when I would like to generate my movie the frames in the Temp folder I created are all blank and are 0 bytes in size. I have the latest version of the java-source, and the code works and displays just fine. So why does it only have difficulty being written to file to view later?

Hmm, don't know – it should work fine. If you want to mail me your code, I can generate it here. What directory did you create your frames in (note: the one you created in setUp()) Mark Guzdial


If we don't know how to compile jpgs into a movie, do we send Prof. Guzdial our jpgs?
Absolutely – I'd be glad to do it for you. Mark Guzdial

I created the frames in "C:/jdk1.5.0_01/MediaSources/Temp/".
Try something simpler like "C:/Temp/" and see how it works. Mark Guzdial

That, interestingly enough, worked quite well. Is there a reason it could not be in a high tiered folder?

Several possible reasons: (a) Maybe you didn't get the jdk,etc. spelling JUST right, (b) maybe you don't have write permission in that directory (my favorite theory) so you couldn't create new files there. Mark Guzdial



Link to this Page