Check this out… I’m trying to figure out why PieceMover generates an “AddPiece” but the SendToLocation does not. Biggest mystery is in the last code fragment.
So in the 12554 instance, the PieceMover is running the following code to for its part of the move (line 570 of the 3.2.17 PieceMover):
if (mergeWith == null) {
comm = comm.append(movedPiece(dragging, p));
comm = comm.append(map.placeAt(dragging, p));
if (!(dragging instanceof Stack) &&
!Boolean.TRUE.equals(dragging.getProperty(Properties.NO_STACK))) {
final Stack parent = map.getStackMetrics().createStack(dragging);
if (parent != null) {
comm = comm.append(map.placeAt(parent, p));
}
}
}
The second part of the move from SendToLocation calls into Map.placeOrMerge and runs:
Command c = apply(new DeckVisitorDispatcher(new Merger(this, pt, p)));
if (c == null || c.isNull()) {
c = placeAt(p, pt);
// If no piece at destination and this is a stacking piece, create
// a new Stack containing the piece
if (!(p instanceof Stack) &&
!Boolean.TRUE.equals(p.getProperty(Properties.NO_STACK))) {
final Stack parent = getStackMetrics().createStack(p);
if (parent != null) {
c = c.append(placeAt(parent, pt));
}
}
}
So that’s ALMOST the same logic. What’s different is the existence of the call to “movedPiece” in the first version before the placedAt-ing starts.
The movedPiece does this:
setOldLocation(p);
Command c = null;
if (!loc.equals(p.getPosition())) {
c = markMoved(p, true);
}
if (p.getParent() != null) {
final Command removedCommand = p.getParent().pieceRemoved(p);
c = c == null ? removedCommand : c.append(removedCommand);
}
return c;
But I don’t see anything in there that’s raising red flags for this (although it’s interesting that SendToLocation version apparently isn’t checking to see if piece needs to be “removed” from an earlier parent – but I don’t think we’re seeing a pieceRemoved command sequence in our final command string anyway)
So given that both versions seem to ultimately call into Map.placeAt(), what I’m now trying to figure out is why the call from PieceMover seems to generate an AddPiece command (as well as a MovePiece) command, but the SendToLocation call does NOT:
public Command placeAt(GamePiece piece, Point pt) {
Command c = null;
if (GameModule.getGameModule().getGameState().getPieceForId(piece.getId()) == null) {
piece.setPosition(pt);
addPiece(piece);
GameModule.getGameModule().getGameState().addPiece(piece);
c = new AddPiece(piece);
}
else {
MoveTracker tracker = new MoveTracker(piece);
piece.setPosition(pt);
addPiece(piece);
c = tracker.getMoveCommand();
}
return c;
}
See they both call Map.addPiece() but we’re only actually getting an AddPiece command on the PieceMover version. Could we be seeing a problem in (gulp) MoveTracker? That’s a rabbit hole I haven’t been down yet, I’ve just been “assuming it works”.
Or actually, the TOP part of the “if” DOES manually insert an AddPiece into the command, but the bottom part doesn’t. So for some reason PieceMover apparently goes through the top part and the SendToLocation goes through the bottom part? That seems… odd. I would have expected them to both go through the bottom part.
And I’m still left wondering what the AddPiece is “for” and why it is only put in the sequence sometimes.
Any insights will be received with great gratitude!
Brian