Bug:Invisible piece is added to board when newPiece is added

Hi,

When I add a new piece to a board with a game piece palette an invisible extra piece is added at the same location. When the intentionally created piece is moved the invisible piece moves with it but when the intentionally created piece is deleted by the delete trait the extra piece isn’t deleted.

When a new piece is added to the board above an existing piece, an invisible piece is not added. But when this piece is moved to an empty hex an invisible piece is created on that hex and then is moved when the intentionally created piece is moved.

I found this bug when I was developing my new Vassal strategy game (I’m not ready to announce what I’m working on) and then I experienced this bug when I tested it in Zap Wars this morning.

To test this bug in Zap Wars I’ve modified the incrementButtonPressed() function by adding these statements:

GameState gs = mod.getGameState();
Chatter chatter = mod.getChatter();
		
for(GamePiece piece : gs.getAllPieces())
{
       chatter.show("ID:" + piece.getId() + " Location:" + piece.getPosition().toString());
}

The chatter output after adding a fuzzy space ship to an empty board is this:

My PC’s specs:

  • Model: I Assembled It
  • Windows 8.1 64bit
  • CPU: Intel Celeron G1610 2.6ghz Dual Core
  • RAM: 8GB DDR3
  • Video Card: AMD HD 7750 1GB GDDR5
  • Vassal version: 3.2.11
  • Java version: 1.6.0_34

Hi Joe,

That’s the way Vassal works.

The invisible ‘piece’ is the Stack that the unit resides in. A Stack is a separate GamePiece from the the units that reside in it.

That’s because the moving unit is merged into the existing Stack at the location.

Because a stackable piece can’t live on a board by itself, it has to be in a Stack, so a new Stack is created at the destination and moved when the piece moves.

The empty stacks are left on the board ready for when the next piece is moved on to that location. I believe they are filtered out when the game is saved.

In custom code you need to be award of this. If you are iterating through the GamePiece on a Map, you will need to check if they are an instanceof Stack and ignore them.

Thus spake Joe12:

I first experienced this bug when I was developing my new Vassal
strategy game (I’m not ready to announce what I’m working on) and then I
experienced this bug when I tested it in Zap Wars this morning.

The Zap Wars module is broken. Try testing your code in a fresh module.


J.

Thanks for your help guys.