public bool HardDrop() { tspin = elibigleForTspin; elibigleForTspin = TspinType.NONE; while (TryMove(pieceRotation, pieceX, pieceY + 1)) { } for (int i = current.states.GetLength(1) - 1; i >= 0; i--) { Pair <sbyte> block = current.states[pieceRotation, i]; SetCell(block.x + pieceX, block.y + pieceY, current.type); } ushort[] newBoard = new ushort[40]; linesCleared = 0; for (int y = 39; y >= 0; y--) { bool rowFilled = board[y] == 0b0000001111111111; if (rowFilled) { linesCleared += 1; } else { newBoard[y + linesCleared] = board[y]; } } board = newBoard; SetPiece(rng.NextPiece()); if (!PieceFits(pieceRotation, pieceX, pieceY)) { blockOut = true; } held = false; return(!blockOut); }
private bool Rotate(int rot) { elibigleForTspin = TspinType.NONE; int len = current.offsetTable.GetLength(1); for (int i = 0; i < len; i++) { Pair <sbyte> fromOffset = current.offsetTable[pieceRotation, i]; Pair <sbyte> toOffset = current.offsetTable[rot, i]; int xOffset = fromOffset.x - toOffset.x; int yOffset = fromOffset.y - toOffset.y; if (TryMove((byte)rot, pieceX + xOffset, pieceY - yOffset)) { if (current == Tetrimino.T) { int filledCorners = 0; bool topLeft = GetCell(pieceX - 1, pieceY - 1) != CellType.EMPTY; if (topLeft) { filledCorners += 1; } bool topRight = GetCell(pieceX + 1, pieceY - 1) != CellType.EMPTY; if (topRight) { filledCorners += 1; } bool bottomLeft = GetCell(pieceX - 1, pieceY + 1) != CellType.EMPTY; if (bottomLeft) { filledCorners += 1; } bool bottomRight = GetCell(pieceX + 1, pieceY + 1) != CellType.EMPTY; if (bottomRight) { filledCorners += 1; } if (filledCorners > 2) { bool isFull = pieceRotation switch { 0 => topLeft && topRight, 1 => topRight && bottomRight, 2 => bottomLeft && bottomRight, _ => bottomLeft && topLeft }; if (isFull || (yOffset == -2 && (xOffset == 1 || xOffset == -1))) { elibigleForTspin = TspinType.FULL; } else { elibigleForTspin = TspinType.MINI; } } } return(true); } } return(false); }
public void SetPiece(Tetrimino piece) { current = piece; pieceX = 4; pieceY = 19; pieceRotation = 0; elibigleForTspin = TspinType.NONE; TryMove(pieceRotation, pieceX, 20); }
private bool TryMove(byte rot, int x, int y) { if (PieceFits(rot, x, y)) { pieceX = x; pieceY = y; pieceRotation = rot; elibigleForTspin = TspinType.NONE; return(true); } return(false); }