Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with Gridworld (Java)
New Posts  All Forums:Forum Nav:

Help with Gridworld (Java)

post #1 of 6
Thread Starter 
I want to start a new gridworld, but i dont know how to code an unbounded grid. Searching the internet there is code for it but it doesn't work for me. Can anyone help?
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
post #2 of 6
Can you post the code that is giving you trouble? As well as the error you are receiving.
Edited by ByteMyASCII - 10/25/11 at 7:20am
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x4 955 ASUS Crosshair 3 EVGA 465GTX 1GB 8GB DDR3 1600mhz GSkill/ADATA 
Hard DriveOSMonitorKeyboard
40GB Intel SSD 1TB Western Digital Black Edition Windows 7 x64 Pro Dual 21.5 Sceptre Saitek Eclipse 
PowerCaseMouseMouse Pad
850watt Silverstone Element Coolermaster Haf 932 Razer Lachesis Razer Vespula 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x4 955 ASUS Crosshair 3 EVGA 465GTX 1GB 8GB DDR3 1600mhz GSkill/ADATA 
Hard DriveOSMonitorKeyboard
40GB Intel SSD 1TB Western Digital Black Edition Windows 7 x64 Pro Dual 21.5 Sceptre Saitek Eclipse 
PowerCaseMouseMouse Pad
850watt Silverstone Element Coolermaster Haf 932 Razer Lachesis Razer Vespula 
  hide details  
Reply
post #3 of 6
Thread Starter 
my main class (BugRunner)
Code:
  package info.gridworld.gui;
import info.gridworld.grid.*;
import info.gridworld.actor.*;
import info.gridworld.world.*;


public class BugRunner
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        world.add(new Bug());
        world.add(new Rock());
        world.show();
        world.setGrid(new UnboundedGrid());

    }
}
2nd java file
bug.java
Code:
package info.gridworld.actor;

import info.gridworld.grid.*;

import java.awt.Color;
public class bug extends Actor {

public void act()
{
if (canMove())
move();
else
turn();
}
public void turn()
{
setDirection(getDirection()+Location.HALF_RIGHT);
}
public void move()
{
Grid<Actor> gr=getGrid();
if (gr == null)
return;
    Location loc = getLocation();
    Location next = loc.getAdjacentLocation(getDirection());
    if (gr.isValid(next))
    moveTo(next);
    else
    removeSelfFromGrid();
    Flower flower = new Flower(getColor());
    flower.putSelfInGrid(gr, loc);
}
public boolean canMove()
{
Grid<Actor> gr = getGrid();
if (gr == null)
return false;
    Location loc = getLocation();
Location next = loc.getAdjacentLocation(getDirection());
    if (!gr.isValid(next))
    return false;
    Actor neighbor = gr.get(next);
    return (neighbor == null) || (neighbor instanceof Flower);
}
}

i used the lines from the Gridworld manual smile.gif

the error is unsafe or unchecked method please recompile with -Xlint for details

using JCreator 4.50
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
post #4 of 6
Thread Starter 
bump.


Still having problems and i still don't know how to actually get an unbounded grid setup frown.gif
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
post #5 of 6
It looks like UnboundedGrid is a collection. The warning you are receiving is because your creating a UnboundedGrid without defining the type. Try something along the lines of (new UnboundedGrid<(whatever type)>) I don't exactly know what type it is that you would use because I haven't done GridWorld before but from what I can tell in the API I would guess it would be of type so try something like what is below but, thats just a guess.
Code:
world.setGrid(new UnboundedGrid<ActorWorld>());

Sorry I didn't respond yesterday I was waiting to look at it after work but I kind of got distracted by Battlefield 3 smile.gif

Edit:
Reference for knowing where the warning is coming from: http://stackoverflow.com/questions/197986/what-causes-javac-to-issue-the-uses-unchecked-or-unsafe-operations-warning
Edited by ByteMyASCII - 10/26/11 at 3:16pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x4 955 ASUS Crosshair 3 EVGA 465GTX 1GB 8GB DDR3 1600mhz GSkill/ADATA 
Hard DriveOSMonitorKeyboard
40GB Intel SSD 1TB Western Digital Black Edition Windows 7 x64 Pro Dual 21.5 Sceptre Saitek Eclipse 
PowerCaseMouseMouse Pad
850watt Silverstone Element Coolermaster Haf 932 Razer Lachesis Razer Vespula 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x4 955 ASUS Crosshair 3 EVGA 465GTX 1GB 8GB DDR3 1600mhz GSkill/ADATA 
Hard DriveOSMonitorKeyboard
40GB Intel SSD 1TB Western Digital Black Edition Windows 7 x64 Pro Dual 21.5 Sceptre Saitek Eclipse 
PowerCaseMouseMouse Pad
850watt Silverstone Element Coolermaster Haf 932 Razer Lachesis Razer Vespula 
  hide details  
Reply
post #6 of 6
Thread Starter 
alright i figured it out through many pages of Google Searching.

Made a new class with a random name ( I Chose LameWorld)
Code:
import info.gridworld.grid.*;
import info.gridworld.grid.UnboundedGrid;
import info.gridworld.grid.Location;
import info.gridworld.actor.*;
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.Bug;
import info.gridworld.actor.Rock;



public class LameWorld extends ActorWorld
{
public LameWorld()
{
setGrid(new UnboundedGrid<Actor>());
}
}
then in the main class i made a new world from LameWorld
Code:
import info.gridworld.grid.*;
import info.gridworld.grid.UnboundedGrid;
import info.gridworld.grid.Location;
import info.gridworld.actor.*;
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.Bug;
import info.gridworld.actor.Rock;

public class BugRunner
{
    public static void main(String[] args)
    {
        LameWorld world = new LameWorld();
        world.add(new Bug());
        world.add(new Rock());
        world.show();
    }
}
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
Epic Rig
(9 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T 890FXA-GD70 (MS-7640) Radeon HD 5670 G. Skill 
RAMHard DriveHard DriveOptical Drive
G. Skill WD Green Seagate Samsung Blu Ray reader 
Monitor
i inc 28 inch monitor 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with Gridworld (Java)