473,466 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Anyone know this year's GridWorld code? I need help on making a class.

60 New Member
Expand|Select|Wrap|Line Numbers
  1. public class fly extends Actor
  2. {
  3.     public fly()
  4.     {
  5.         setColor(Color.BLACK);
  6.     }
  7.  
  8.     public fly(Color flyColor)
  9.     {
  10.         setColor(flyColor);
  11.     }
  12.  
  13.     public void act()
  14.     {
  15.         if (canMove())
  16.         {
  17.             move();
  18.         }
  19.         else
  20.         {
  21.             turn();
  22.         }
  23.     }
  24.  
  25.     public void move()
  26.     {
  27.         if (getGrid() == null)
  28.         {
  29.             return;
  30.         }
  31.         ArrayList<Actors> actors = getActors();
  32.         processActors(actors);
  33.         ArrayList<Location> moveLocs = getMoveLocations();
  34.         Location loc = selectMoveLocation(moveLocs);
  35.         makeMove(loc);
  36.     }
  37.  
  38.     public ArrayList<Actor> getActors()
  39.     {
  40.         return getGrid().getOccupiedLocations(getLocation());
  41.     }
  42.  
  43.     public void processActors(ArrayList<Actor> actors)
  44.     {
  45.         for (Actor a : actors)
  46.         {
  47.             if (!(a instanceof Rock) && !(a instanceof Critter) && !(a instanceof fly) && !(a instanceof Bug))
  48.             {
  49.                 a.removeSelfFromGrid();
  50.             }
  51.         }
  52.     }
  53.  
  54.     public ArrayList<Location> getMoveLocations()
  55.     {
  56.         return getGrid().get //NEED HELP HERE!
  57.     }
  58.  
  59.     public Location selectMoveLocation(ArrayList<Location> locs)
  60.     {
  61.         int n = locs.size();
  62.         if (n == 0)
  63.         {
  64.             return getLocation();
  65.         }
  66.         int r = (int)(Math.random() * n);
  67.         return locs.get(r);
  68.     }
  69.  
  70.     public void makeMove(Location loc)
  71.     {
  72.         if (loc == null)
  73.         {
  74.             removeSelfFromGrid();
  75.         }
  76.         else
  77.         {
  78.             moveTo(loc);
  79.         }
  80.     }    
  81. }
The above code is my idea for a fly class that moves around a bounded grid randomly. I cannot "eat" rocks, bugs, critters, and other flies. My problem is in the getMoveLocations method. I want it to be able to move randomly to any spot. But there is no method in the actor or grid class that says getValidMoveLocations. I think you need the getOccupiedLocation and subtract it from the grid? It's just an idea though.

Thanks
Mar 22 '08 #1
4 2119
JosAH
11,448 Recognized Expert MVP
I don't know what GridWorld is; are you talking about this one?

kind regards,

Jos
Mar 22 '08 #2
Energizer100
60 New Member
I don't know what GridWorld is; are you talking about this one?

kind regards,

Jos

Yeah it is. I basically have to create a new type of Actor.
Mar 22 '08 #3
JosAH
11,448 Recognized Expert MVP
Yeah it is. I basically have to create a new type of Actor.
I skimmed a bit through the API documentation for the Grid and found the method
getEmptyAdjacentLocations(Location loc). That should be a starting point.

kind regards,

Jos
Mar 23 '08 #4
Energizer100
60 New Member
I skimmed a bit through the API documentation for the Grid and found the method
getEmptyAdjacentLocations(Location loc). That should be a starting point.

kind regards,

Jos

Yeah, my idea for it was to make a new ArrayList.

So it would be something like,

Expand|Select|Wrap|Line Numbers
  1. ArrayList<Actor> valLocs = getGrid - getOccupiedLocations.
something along those lines
Mar 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: S C A | last post by:
Dear All: I'm not sure if this is even possible but does anyone know about using ActiveX controls (a Microsoft-specific technology) in Java? I am having a heck of a time finding some similar...
2
by: Jim | last post by:
Hi, Does anyone know of an available java class that will encrypt to cipher text consisting of only printable ascii characters? One of the things I need it for is to encrypt strings that will...
1
by: stapak | last post by:
I have a common (I guess) problem. I need to store my address book in format that would be independent on any e-mail clients - preferably in XML - to work sometimes on raw data. I tried to find...
8
by: Neil Rowe | last post by:
Hi all I am writing an App at the moment and I need to be able to download & Upload xml files from an ftp server. Does anyone know how this can be done without using a third party component. ...
0
by: Steve Mauldin | last post by:
I am trying to get from files the keywords saved as part of the properties under the summary tab. I am able to get the Title, and Comments using the following code but I need to get the keywords...
15
by: Pucca | last post by:
I'm getting an error when I tried to use this BerConverter class in my C# code. Even though the Interent doc says that it runs on Win2000 sp4, I just thgouth I'll double check. Does anyone know...
6
by: Marc | last post by:
The below snippet does not work...anyone know how to reference the procedure 'DrawCross()'? Private Sub MarkVORToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As...
6
by: Don | last post by:
I am looking for a C/C++ code spell checker, a tool that checks for spelling errors in C++ source code. Linux/Unix platforms. Prefer command line tool. Open source preferred, but will consider...
4
by: ttja | last post by:
does anyone know how to create the code for making a slope field? so if i insert a function using gui or something it'll graph the slopes for the function on the graphic screen. here's wat i have so...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.