AddPiece, RemovePiece and "landing"

Hello,

so I am slightly confused: The board is a double array of PieceType entries with null indicating an empty field. Now obviously pieces can not be stored on the board permanently because once a row gets deleted the pieces get destroyed (In particular you can’t call removePiece on the remains of an L piece for example, that would make no sense). The exception to that should be the current piece which is “falling”. Once it hits the ground it “dissolves” into a part of the board.

So is there any limit on adding or removing pieces? The way I understand it the game flow is modeled by adding a falling piece and then to simulate falling and rotating by removing it and either placing a copy one field below or a rotation on the same field. In particular all valid sequences of adding and removing (symbolized by + and - here) should be of the form +(-+)*, i.e. you always start by adding something and move/rotate it by removing/readding it.

No.

is not relevant for this part of the project.

removePiece() should work whenever canRemovePiece() returns true, which it does whenever the board at that position has pieces of correct type and correct shape. Similarly for addPiece().

1 Like

Thanks, so I should also not check if the piece that I remove was once one “contiguous” piece? For example if I have an empty playing field that is five fields wide and sufficiently high and I get four I pieces which I bring into horizontal alignment and drop them so that they occupy the lower left 4x4 square. If I then were to call removePiece on an I that I turned clockwise once, row = 2 and row = getNumberOfColumns() - 4 this would be valid?

Indeed, you do not need to check this. You in particular do not need to track history or the evolution of pieces over time.

Yes.