bengotow / javassonne

Automatically exported from code.google.com/p/javassonne
0 stars 1 forks source link

TileBoardIterator out-of-bounds test #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When you call outOfBounds() on the iterator, it goes through an if that
looks like this:

if (location_.car() < data_.getUpperLeftCorner().getLocation().car() ||
location_.cdr() < data_.getUpperLeftCorner().getLocation().cdr() ||
location_.car() > data_.getLowerRightCorner().getLocation().car()||
location_.cdr() > data_.getLowerRightCorner().getLocation().cdr()|| this ==
data_.getUpperLeftCorner()|| this == data_.getLowerRightCorner())

I feel like there should be a better way to do this? Calling
getUpperLeftCorner() actually creates new iterator objects over and over
again. Could we just make the "upperLeftCorner" and "lowerRightCorner" of
the board refer to IntPairs instead of iterators? Seems silly since we're
fetching the IntPairs right out of the iterator and using their internals here.

Original issue reported on code.google.com by bengo...@gmail.com on 5 Feb 2009 at 2:06

GoogleCodeExporter commented 9 years ago
Also - do we need the last two clauses of this statement?

Original comment by bengo...@gmail.com on 5 Feb 2009 at 2:07

GoogleCodeExporter commented 9 years ago
Good points. I wrote that before I had those functions return copies. I'll 
change it 
so I just grab them once. 

The reason I like returning iterators from those functions is so callers can 
get an 
iterator (the point being that they shouldn't worry about how we're referencing 
location?).

And the last 2 clauses are because I figured we'd keep the rule that you have 
to play 
adjacent to a tile already in the board, and the corner iterators aren't 
adjacent to 
tiles.

Original comment by corespace on 5 Feb 2009 at 4:17

GoogleCodeExporter commented 9 years ago
Sweet - that sounds like a good solution. I didn't think about the corner 
iterators
being invalid places to place tiles.

Original comment by bengo...@gmail.com on 5 Feb 2009 at 4:24

GoogleCodeExporter commented 9 years ago

Original comment by corespace on 5 Feb 2009 at 4:30