public void CopyFrom(STBoard board) { this.mWidth = board.mWidth; this.mHeight = board.mHeight; this.mCells = new byte[this.mWidth * this.mHeight]; board.mCells.CopyTo(this.mCells, 0); }
// The following counts the number of cells (0..4) of a piece that would // be eliminated by dropping the piece. public int CountPieceCellsEliminated ( STPiece piece ) { if (null == this.mCells) { return(0); } if (false == piece.IsValid( )) { return(0); } // Copy piece and board so that this measurement is not destructive. STBoard copyOfBoard = new STBoard(); copyOfBoard.CopyFrom(this); STPiece copyOfPiece = new STPiece(); copyOfPiece.CopyFrom(piece); // Drop copy of piece on to the copy of the board copyOfBoard.FullDropAndCommitPieceToBoard(copyOfPiece); // Scan rows. For each full row, check all board Y values for the // piece. If any board Y of the piece matches the full row Y, // increment the total eliminated cells. int pieceCellsEliminated = 0; int width = 0; int height = 0; width = copyOfBoard.GetWidth( ); height = copyOfBoard.GetHeight( ); int y = 0; for (y = 1; y <= height; y++) { bool fullRow = false; fullRow = true; // hypothesis int x = 0; for (x = 1; ((x <= width) && (true == fullRow)); x++) { byte cellValue = (byte)0; cellValue = copyOfBoard.GetCell(x, y); if ((byte)0 == cellValue) { fullRow = false; } } if (true == fullRow) { // Find any matching board-relative Y values in dropped copy of piece. int totalCells = 0; totalCells = piece.GetTotalCells( ); int cellIndex = 0; for (cellIndex = 1; cellIndex <= totalCells; cellIndex++) { int boardX = 0; int boardY = 0; copyOfPiece.GetTranslatedCellXY(cellIndex, ref boardX, ref boardY); if (boardY == y) { pieceCellsEliminated++; // Moohahahaaa! } } } } return(pieceCellsEliminated); }
public STGameState( ) { // Core Game State // Board and Piece mSTBoardCurrent = new STBoard(); mSTPieceCurrent = new STPiece(); // Core Game State Variables mGameOver = false; mIterationCountdownSeconds = 0.0; mCurrentPiecePointValue = 0; // starts at 24+(3*(level-1)) mCompletedRows = 0; // Piece Sequence Generator mSTPieceSequence = new STPieceSequence(); // User Options mPaused = false; mShowNextPiece = false; mAI = false; mSpawnFromVideoCapture = false; mOutputToRS232 = false; mAutoRestart = false; mAutoWriteFile = false; // Game Speed Adjustment // -2, -3, -4,... : Slow Mode (delay proportional to index) // -1 : Normal, Clipped at 0.20 sec/row // 0 : Normal // +1 : Fast Mode (still render bound) // +2 : Very Fast Mode (still render bound) // +3, +4, +5,... : Multiple moves per rendered frame mGameSpeedAdjustment = 0; mShadowMode = false; mHintMode = false; mMonochromeColorMode = false; // Statistics for User Consideration Only // Updated at piece spawning or row completion mPieceHistogram = new long[8]; // Count of each piece type mHeightHistogram = new long[202]; // Height after each landing mTotalElapsedTimeSeconds = 0.0; mScore = 0; // Only updated when game ends mHistoricHighScore = 0; mHistoricHighRows = 0; mHistoricHighPieces = 0; mHistoricCumulativeRows = 0; // Used to get average: rows / games mHistoricTotalGames = 0; mHistoricRows = new long[20]; // Past games [0]==most recent // Cached Derived or Copied Values // Next Piece (Not always used or available; Only 'kind' aspect is relevant) mSTPieceNext = new STPiece(); // Best Move (determined by relevant AI upon piece spawning) mSTPieceBestMove = new STPiece(); // state of animation of a an AI-executed move mAnimateAIMovesEnable = true; mAnimateAIMovesStartingY = 0; mAnimateAIMovesFinalSafeY = 0; mAnimateAITotalInitialCommands = 0; mAnimateAICommandsExecuted = 0; mAnimateAICommandsPerRow = 0; mAnimateAIMovesPendingRotation = 0; mAnimateAIMovesPendingTranslation = 0; // RUN-TIME STATE INFORMATION (DO NOT STORE IN A FILE) // video capture related mPreviousClassification = (-1); mSelectionState = 0; mSelectionX1 = 0; mSelectionY1 = 0; mSelectionX2 = 0; mSelectionY2 = 0; mCalibrationModeFlag = false; // false == OFF mCalibrationModeShapeCode = 0; // 1..7 shape // file list mFirstItem = 0; mRelativeItem = 0; mShowFileList = false; mLoadFlag = false; // miscellaneous mRenderFrameNumber = 0; mShowInstructionPage = 0; mShowConsole = false; mReportedFrameRate = 0.0f; }