Problem in TileMapBoard isValidPlacement()

0 views
Skip to first unread message

Ben Gotow

unread,
Mar 15, 2009, 5:10:55 PM3/15/09
to javas...@googlegroups.com
Hey Kyle,

I've been working on implementing the "confirm placement" part of the turn and I've refactored the BoardController's placeTile() function a bit to make it work. I'm having an odd issue, though. When you go to place your tile, the board reports that the place you chose is not valid because the temp tile next to it (with uniqueIdentifier "not assigned" and "null" for all features) isn't a match.

Is there something I messed up that was making this work before? It seems like temp tiles are hanging around from previous turns and interfering when you try to place the tile, but I can't figure it out.

- Ben

Kyle Prete

unread,
Mar 15, 2009, 9:35:31 PM3/15/09
to javas...@googlegroups.com
Aw hell. Ok, here's what we can do. Make a new tile feature that matches everything, and make the default Tile constructor set each of its sides to that feature. You think that will fix it?

-Kyle

Ben Gotow

unread,
Mar 15, 2009, 10:38:27 PM3/15/09
to javas...@googlegroups.com
Hey Kyle,

I was just looking at this some more, and I just added a section of code to the "isValidPlacement()" function so that the temp tiles are ignored. See code below :-) It might be a little slower because we have to determine if they're in the temp-tiles array, but it seems to be working... Your way sounds more efficient, but I'm not sure it matters too much?

TileBoardGenIterator localIter = new TileBoardGenIterator(iter);
// iterate left and check if features match
Tile left = localIter.leftCopy().current();
Tile top = localIter.upCopy().current();
Tile right = localIter.rightCopy().current();
Tile bottom = localIter.downCopy().current();


// we want to make sure the tiles we're looking at in the adjacent
// squares are not temp. tiles. This could lead to illeigal "feature
// bindings" and this function returning false unnecessarily.
if (tempTileLocations_.contains(localIter.leftCopy().getLocation()))
left = null;
if (tempTileLocations_.contains(localIter.rightCopy().getLocation()))
right = null;
if (tempTileLocations_.contains(localIter.upCopy().getLocation()))
top = null;
if (tempTileLocations_.contains(localIter.downCopy().getLocation()))
bottom = null;


if (left != null && !tileFeatureBindings_.featuresBind(left
.featureIdentifierInRegion(Region.Right), tile
.featureIdentifierInRegion(Region.Left)))
return false;
// iterate up and check if features match
if (top != null && !tileFeatureBindings_.featuresBind(top
.featureIdentifierInRegion(Region.Bottom), tile
.featureIdentifierInRegion(Region.Top)))
return false;
// iterate right and check if features match
if (right != null && !tileFeatureBindings_.featuresBind(right
.featureIdentifierInRegion(Region.Left), tile
.featureIdentifierInRegion(Region.Right)))
return false;
// iterate down and check if features match
if (bottom != null && !tileFeatureBindings_.featuresBind(bottom
.featureIdentifierInRegion(Region.Top), tile
.featureIdentifierInRegion(Region.Bottom)))
return false;
// make sure at least one of the adjacent tiles exists
if (left == null && top == null && right == null && bottom == null)
return false;
Ben Gotow
-----------------------------------

Kyle Prete

unread,
Mar 15, 2009, 11:38:31 PM3/15/09
to javas...@googlegroups.com
Looks good, but if you want to do it this way, I'd recommend calling each iterator copy only once (sure it's more lines of code, but it keeps you from throwing out iterators you're about to use again)

-Kyle

Ben Gotow

unread,
Mar 15, 2009, 11:39:12 PM3/15/09
to javas...@googlegroups.com
Ahh - good call - I didn't even think about that. I'll go ahead and update it next time I commit.

- Ben
Reply all
Reply to author
Forward
0 new messages