GridWorld Problem

SparseGrid

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 13103 Views - Last Post: 01 May 2012 - 09:22 AM Rate Topic: -----

#16 Rekmesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 15-September 08

Re: GridWorld Problem

Posted 13 March 2009 - 12:29 AM

Yes I have indeed kept that in mind while coding the grid. AbstractGrid<E> defines methods common to all grids, therefore chose to extend that class. I might just try and extend bounded grid and see how it goes, after all it is essentially a boundedGrid... The reason I said the second statement that implements Grid<E> doesn't work is because I would have to define all the other methods including the ones that AbstractGrid<E> already defines.

This post has been edited by Rekmesh: 13 March 2009 - 12:53 AM

Was This Post Helpful? 0
  • +
  • -

#17 Rekmesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 15-September 08

Re: GridWorld Problem

Posted 15 March 2009 - 08:44 PM

Is there anyone out there that knows how to fix this problem?
I tried to fix it by using an array of arraylists and having sparsegrid extend BoundedGrid but that doesn't work either...
Was This Post Helpful? 0
  • +
  • -

#18 Th3weez  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 23-March 09

Re: GridWorld Problem

Posted 23 March 2009 - 05:23 PM

Hmmmmm

This post has been edited by Th3weez: 23 March 2009 - 05:26 PM

Was This Post Helpful? 1

#19 dragonsword40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-May 12

Re: GridWorld Problem

Posted 01 May 2012 - 08:58 AM

First off I copied everything from the resource file for gridworld to my own packages and classes, but kept the same names. First thing I recommend is keep the Tester in the default package, but move the other two to info.gridworld.grid package. The second thing I did was I made a copy of the image BoundedGrid.gif and changed the copies name to SparseGrid.gif, so that instead of null appearing next to what is the SparseGrid command in the menu there is an image of a grid next to that command. The third thing I noticed is that for the UnboundedGrid and BoundedGrid they both use 2 values for the thing that holds the data, while yours only uses one. I'm currently working on changing the code, so I have yet to find the complete solution, but those three things could help.

Also I moved the addcommand for the Sparse grid directly into the World Class and below is what that looks like
 
public World(Grid<T> g){
    gr = g;
    gridClassNames = new TreeSet<String>();
    occupantClassNames = new TreeSet<String>();
    addGridClass("info.gridworld.grid.BoundedGrid");
    addGridClass("info.gridworld.grid.UnboundedGrid");
    addGridClass("info.gridworld.grid.SparseGrid");
}


Was This Post Helpful? 0
  • +
  • -

#20 dragonsword40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-May 12

Re: GridWorld Problem

Posted 01 May 2012 - 09:22 AM

Plus for the isValid method you should just use the method that is in BoundedGrid, which is what is below. You don't have to have that long if else statement. The computer will check what is below itself, and whether that is true or false that is what it will return.

public boolean isValid(Location loc)
    {
        return 0 <= loc.getRow() && loc.getRow() < getNumRows()
                && 0 <= loc.getCol() && loc.getCol() < getNumCols();
    }
 


also in your isValid method you have equals signs next to the less than row and col part you should remove those equals signs the equals for the 0 part though are suppose to stay.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2